Skip to content

Integrate ANN into _search endpoint #88694

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

Merged
merged 7 commits into from
Jul 22, 2022
Merged

Integrate ANN into _search endpoint #88694

merged 7 commits into from
Jul 22, 2022

Conversation

jtibshirani
Copy link
Contributor

This PR adds a new knn option to the _search API to support ANN search.
It's powered by the same Lucene ANN capabilities as the old _knn_search
endpoint. The knn option can be combined with other search features like
queries and aggregations.

Addresses #87625

This PR adds a new `knn` section to the search request.

As explained in #87625, the search returns a global top k documents across all
shards:
* In the DFS phase, collect the top k vector matches per shard, combine them
and keep the global top k. 
* Then move to the query phase. Convert the top k vector matches into a new
`KnnScoreDocQueryBuilder` that matches only those top documents. For the final
query, take a boolean disjunction between this `KnnScoreDocQueryBuilder` query and
the search request `query`.

Commits:
* Rename KnnSearchRequestBuilder -> KnnSearchRequestParser to avoid confusion with new KnnSearchBuilder
* Add `KnnScoreDocQueryBuilder`
* Implement kNN search using DFS phase

Addresses #87625.
This PR introduces a 'filter' subsection where filters can be provided to the
kNN search.

Like all other queries, the filters are rewritten on the coordinating nodes as
well as data nodes.
When kNN search is enabled, it automatically uses the `dfs_query_then_fetch`
search type. The user can no longer control the search type that's used. This
commit throws an error if `search_type` is explicitly set when `knn` search is
used.
This change adds docs for the new search `knn` option:
* Add `knn` option to `_search` API docs.
* Update the kNN search guide to use the `_search` endpoint instead of
`_knn_search` endpoint. Move relevant information from the `_knn_search` API
docs to this guide, like the filtering example.
* Add an example to the kNN search guide of configuring `index_options` (just
seemed nice to have, not core to this change).

The PR doesn't deprecate the `_knn_search` endpoint yet.
@jtibshirani
Copy link
Contributor Author

Each commit was reviewed earlier:

There are some follow-ups tracked in #87625 that we'll tackle after this initial merge.

@elasticsearchmachine
Copy link
Collaborator

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

@elasticsearchmachine elasticsearchmachine added the Team:Search Meta label for search team label Jul 21, 2022
@elasticsearchmachine
Copy link
Collaborator

Hi @jtibshirani, I've created a changelog YAML for you. Note that since this PR is labelled release highlight, you need to update the changelog YAML to fill out the extended information sections.

Copy link
Contributor

@mayya-sharipova mayya-sharipova left a comment

Choose a reason for hiding this comment

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

@jtibshirani Thanks Julie, considering that everything was reviewed before, I only quickly browsed this PR and everything LGTM.

@jtibshirani jtibshirani merged commit e3ede67 into master Jul 22, 2022
@jtibshirani jtibshirani deleted the knn-search branch July 22, 2022 15:02
@jtibshirani jtibshirani added the Team:Clients Meta label for clients team label Jul 22, 2022
mayya-sharipova added a commit to mayya-sharipova/elasticsearch that referenced this pull request May 18, 2023
Add a note that approximate knn search doesn't support the
parameter ccs_minimize_roundtrips in CCS search.

Relates to elastic#88694
mayya-sharipova added a commit that referenced this pull request May 23, 2023
Add a note that approximate knn search doesn't support the
parameter ccs_minimize_roundtrips in CCS search.

Relates to #88694
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>feature release highlight :Search Relevance/Vectors Vector search Team:Clients Meta label for clients team Team:Search Meta label for search team v8.4.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants