elastic / elasticsearch

Free and Open Source, Distributed, RESTful Search Engine
https://www.elastic.co/products/elasticsearch
Other
1.22k stars 24.85k forks source link

ANN search performance with multiple segments #90700

Open jtibshirani opened 2 years ago

jtibshirani commented 2 years ago

To support ANN search, Elasticsearch indexes the vector values of each segment as an HNSW graph. Usually an index has multiple segments, which means ANN must check several HNSW graphs as it searches one segment after another. With fewer segments, the ANN search is more efficient, since we check a smaller number of graphs. Another way to describe it: searching an HNSW graph is sub-linear in the number of vectors, so it's better to search larger graphs vs. several smaller ones.

It's certainly possible to force merge the index to one segment, but force merge can take substantial time and has some downsides (explained here).

This meta issue explores ideas to improve performance that don't require force merge. These are early ideas and may change.

elasticsearchmachine commented 2 years ago

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

elasticsearchmachine commented 2 years ago

Pinging @elastic/es-distributed (Team:Distributed)

AkisAya commented 1 year ago

ANN must check several HNSW graphs as it searches one segment after another

why is that we can not search multiple hnsw graph in parallel an then merge the result ?

benwtrent commented 1 year ago

@AkisAya nothing in Elasticsearch currently searches segments in parallel. Any change there needs to be considered carefully as resource contention is a real concern. We would prefer when concurrency support is added, we add it for everything (all queries, all aggregations).

Julie mentions this as an option in the issue description.

Also, in benchmarking, there is not a huge difference in search speed for KNN over multiple segments vs just a single one, as long as the segments are not tiny.

javanna commented 9 months ago

The concurrency bits are now addressed: segments can now be searched in parallel. Enabled in Elasticsearch 8.11 for knn (which runs in the dfs phase) and Elasticsearch 8.12 for the query phase.

elasticsearchmachine commented 4 months ago

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