Skip to content

Conversation

@matthewmcneely
Copy link
Contributor

Description

DO NOT MERGE

This PR adds support for the new effort and distance threshold in generated GraphQL queries for types that have embedding vectors.

Note. There's a breaking change in the resulting computed distance in that for cosine and dotproduct indexes, the computed distance is no longer divided by 2. The results now correctly represent the distances stored in the index.

Checklist

  • The PR title follows the
    Conventional Commits syntax, leading
    with fix:, feat:, chore:, ci:, etc.
  • Code compiles correctly and linting (via trunk) passes locally
  • Tests added for new functionality, or regression tests for bug fixes added as applicable
  • For public APIs, new features, etc., a PR on the
    docs repo staged and linked here. This process can
    be simplified by going to the public docs site and clicking the
    "Edit this page" button at the bottom of page(s) relevant to your changes. Ensure that you
    indicate in the PR that this is an unreleased feature so that it does not get merged into
    the main docs prematurely.

@matthewmcneely matthewmcneely requested a review from a team as a code owner January 9, 2026 22:30
@github-actions github-actions bot added area/testing Testing related issues area/graphql Issues related to GraphQL support on Dgraph. area/core internal mechanisms go Pull requests that update Go code labels Jan 9, 2026

if metric == schema.SimilarSearchMetricDotProduct {
distanceFormula = "math(( 1.0 - (($search_vector) dot v2)) /2.0)"
distanceFormula = "math(1.0 - (($search_vector) dot v2))"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@raphael-istari For some reason, the calculated distances for cosine and dp were being divided by 2. Not sure why, maybe to normalize them to [0,1] instead of their natural [0,2] (which is how they're actually stored in the index). The distance_threshold param exposes this oddness. So this (a breaking change to GraphQL queries) computes them as they're stored--and the distance_threshold parameter actually works as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/core internal mechanisms area/graphql Issues related to GraphQL support on Dgraph. area/testing Testing related issues go Pull requests that update Go code

Development

Successfully merging this pull request may close these issues.

2 participants