Skip to content

Wrap ES KNN queries with PatienceKNN query #127223

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 74 commits into
base: main
Choose a base branch
from

Conversation

tteofili
Copy link
Contributor

@tteofili tteofili commented Apr 23, 2025

This exposes an option to add the patience-based early termination defined in apache/lucene#14094 to KNN queries in ES.
This leverages PatienceKnnVectorQuery which wraps ES KNN queries when mapping is one of hnsw, int8_hnsw, int4_hnsw, bbq_hnsw and early_termination is set to true (within index_options).

e.g.:

{
  "mappings": {
    "properties": {
      "my_vector" : {
        "type": "dense_vector",
        "dims" : 10,
        "index" : true,
        "index_options" : {
          "type" : "bbq_hnsw"
          "early_termination" : true
        }
      }
    }
  }
}

Currently this has the limitation that we can't profile that query because we can't extend the PatienceKnnQuery same as https://github.com/elastic/elasticsearch/blob/main/server/src/main/java/org/elasticsearch/search/vectors/ESKnnByteVectorQuery.java#L28-L38 because of visibility issues. However it's fixed in 10.3 branch via apache/lucene#14838 and we'll incorporate that as soon as 10.3 is released and included in ES main branch.

@tteofili
Copy link
Contributor Author

tteofili commented May 9, 2025

dense_vector
Screenshot 2025-05-09 at 16 16 13
Screenshot 2025-05-09 at 16 17 08

@tteofili
Copy link
Contributor Author

so_vector
Screenshot 2025-05-29 at 15 40 18
Screenshot 2025-05-29 at 15 40 35
Screenshot 2025-05-29 at 15 37 07
Screenshot 2025-05-29 at 15 37 27
Screenshot 2025-05-29 at 15 37 56

Copy link
Contributor

github-actions bot commented Jun 19, 2025

🔍 Preview links for changed docs:

🔔 The preview site may take up to 3 minutes to finish building. These links will become live once it completes.

@tteofili tteofili marked this pull request as ready for review June 27, 2025 13:28
@tteofili tteofili added :Search Relevance/Vectors Vector search auto-backport Automatically create backport pull requests when merged labels Jun 27, 2025
@elasticsearchmachine elasticsearchmachine added the Team:Search Relevance Meta label for the Search Relevance team in Elasticsearch label Jun 27, 2025
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-search-relevance (Team:Search Relevance)

@elasticsearchmachine
Copy link
Collaborator

Hi @tteofili, I've created a changelog YAML for you.

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.

Whew, way cleaner! Still some room for simplifying. But the index setting looks much nicer to me :)

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.

So clean! I like it, and the performance numbers are ⚡

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-backport Automatically create backport pull requests when merged >feature :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.

3 participants