Skip to content

Conversation

john-wagster
Copy link
Contributor

@john-wagster john-wagster commented Aug 28, 2025

Updating the query interface for knn to include visit_percentage

Usage example with a basic knn query (note this PR updates retrievers as well). This is setup such that visit_percentage overrides num_candidates for bbq_disk:

curl -XPUT --header 'Content-Type: application/json' "http://localhost:9200/test" -d '{
  "mappings": {
    "properties": {
       "image-vector": {
        "type": "dense_vector",
        "dims": 3,
        "similarity": "l2_norm",
        "index_options": {
          "type": "bbq_disk"
        }
      }
    }
  }
}'
seq 1 1 | xargs -I % -P1 curl -XPOST --header 'Content-Type: application/json' "http://localhost:9200/test/_doc?refresh" -d '
    { "image-vector": [0.0127, 0.1230, 0.3929] }
'
curl -XGET --header 'Content-Type: application/json' "http://localhost:9200/test/_search" -d '{
  "query" : {
    "knn": {
      "field": "image-vector",
      "query_vector": [0.0127, 0.1230, 0.3929],
      "k": 10,
      "visit_percentage": 10.0
    }
  }
}' | python -mjson.tool

Copy link
Contributor

github-actions bot commented Aug 28, 2025

`confidence_interval`
: (Optional, float) Only applicable to `int8_hnsw`, `int4_hnsw`, `int8_flat`, and `int4_flat` index types. The confidence interval to use when quantizing the vectors. Can be any value between and including `0.90` and `1.0` or exactly `0`. When the value is `0`, this indicates that dynamic quantiles should be calculated for optimized quantization. When between `0.90` and `1.0`, this value restricts the values used when calculating the quantization thresholds. For example, a value of `0.95` will only use the middle 95% of the values when calculating the quantization thresholds (e.g. the highest and lowest 2.5% of values will be ignored). Defaults to `1/(dims + 1)` for `int8` quantized vectors and `0` for `int4` for dynamic quantile calculation.

`default_visit_percentage` {applies_to}`stack: ga 9.1`
Copy link
Contributor Author

Choose a reason for hiding this comment

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

since we didn't add these in a previous PR I just added them here but could be convinced to pull docs out to a separate PR

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@benwtrent how do you feel about the docs going in with the belief we are going to yank out the feature flag immediately here. Would you be more comfortable with me pulling all of these out to a separate PR?

Copy link
Member

@benwtrent benwtrent left a comment

Choose a reason for hiding this comment

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

I read through again, looking good. Just need to test null cases.

I left some comments on ones that I found, but then I figured, eh, that is too many comments. So I stopped.

Basically, anything that is a "random input" deal, should test the null case. Additionally, the dense vector type tests should verify that when the value is passed, it actually is applied to the query.

The "refresh" popped up on the screen in the middle of the commenting. Sorry if any of them are on an old commit :(

@john-wagster
Copy link
Contributor Author

@benwtrent

Basically, anything that is a "random input" deal, should test the null case. Additionally, the dense vector type tests should verify that when the value is passed, it actually is applied to the query.

I think I got all of them? I'm double checking here and reviewing tests in general. But I believe I got fixed up what you saw. I appreciate the feedback too; that was super helpful.

Still curious if you think I should punt the docs update out of this PR or not given that stuff is still behind a feature flag or if you feel like we'll take the flag out shortly and it won't matter.

@benwtrent
Copy link
Member

Let's remove the docs changes

@john-wagster
Copy link
Contributor Author

docs changes pulled out to here: #134082

Copy link
Member

@benwtrent benwtrent left a comment

Choose a reason for hiding this comment

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

I would just make sure that the new tests you added/mutated all pass with various seeds.

I would also maybe do some release tests verification locally to make sure you handled the feature flag.

I am particularly wondering about things like the more general "RandomSearchRequestGenerator" change and if adding the value, then the generated object gets serialized to xcontent, and then parsed (which doesn't get the field if the flag isn't set) will be missing the object.

I don't know if we have tests that do that, but I know that by default release tests do not run in PRs.

@john-wagster
Copy link
Contributor Author

I've tried to run all of the tests multiple times and on several seeds and not seen any problems. Tried breaking RandomSearchRequestGenerator and not been able to do that. Tried turning the feature flag on and off and behavior seems to be ok. bwc tests seem to run ok (although to be fair configuring some of this from a release vs snapshot standpoint is confusing). I think this is good.

@john-wagster john-wagster merged commit 352b0d8 into elastic:main Sep 4, 2025
33 checks passed
elasticsearchmachine pushed a commit that referenced this pull request Sep 6, 2025
After merging two KNN PRs, the release tests started failing. This fixes
those tests.

Original PRs: * #133806 *
#133753
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

>non-issue :Search Relevance/Vectors Vector search Team:Search Relevance Meta label for the Search Relevance team in Elasticsearch v9.2.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants