Skip to content

Commit 521ff04

Browse files
authored
Merge pull request #1193 from vespa-engine/boeker/add-ann-tuning-to-front-page
Add short page with infos on ANN parameter tuning to front page
2 parents 7ceda9e + 39b0b84 commit 521ff04

2 files changed

Lines changed: 53 additions & 0 deletions

File tree

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# ANN Parameter Tuning
2+
3+
Approximate Nearest Neighbor (ANN) search is a powerful way to make vector search scalable and efficient. In Vespa, this is implemented by building HNSW graphs for embedding fields.
4+
5+
For a search that uses _only_ vector similarity for retrieval, this works very well as you can just query the HNSW index and get (enough) relevant results back very fast.
6+
However, most Vespa applications are more complex and often combine vector similarity with filtering on metadata fields.
7+
8+
There are multiple strategies in Vespa for handling queries that combine ANN with filtering,
9+
and there are parameters that control the strategy selection and the strategies themselves.
10+
While Vespa has chosen default values for these parameters that work well in most use cases, one often can benefit from further tuning these parameters for the application/use case/data set at hand.
11+
12+
## ANN Parameter Optimizer
13+
14+
The `vespa.evaluation` module provides a `VespaNNParameterOptimizer` class that, given a sufficient sample of queries
15+
using ANN with filtering,
16+
performs measurements to analyze the effect of various tuning parameters and, based on this,
17+
provides suggestions for these parameters.
18+
Running the optimizer can be as simple as this:
19+
20+
```python
21+
from vespa.evaluation import VespaNNParameterOptimizer
22+
23+
optimizer = VespaNNParameterOptimizer(
24+
app=my_vespa_app,
25+
queries=my_list_of_queries,
26+
hits=number_of_target_hits_used_in_my_queries,
27+
)
28+
report = optimizer.run()
29+
30+
suggested_parameters = {
31+
"ranking.matching.approximateThreshold": report["approximateThreshold"][
32+
"suggestion"
33+
],
34+
"ranking.matching.filterFirstThreshold": report["filterFirstThreshold"][
35+
"suggestion"
36+
],
37+
"ranking.matching.filterFirstExploration": report["filterFirstExploration"][
38+
"suggestion"
39+
],
40+
"ranking.matching.postFilterThreshold": report["postFilterThreshold"][
41+
"suggestion"
42+
],
43+
}
44+
```
45+
46+
See the
47+
[example](https://vespa-engine.github.io/pyvespa/examples/ann-parameter-tuning-vespa-cloud.html)
48+
for a full guide on how to use this class and how to interpret the report it produces.
49+
See the
50+
[documentation](https://vespa-engine.github.io/pyvespa/api/vespa/evaluation.html#vespa.evaluation.VespaNNParameterOptimizer)
51+
for further details.
52+

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ nav:
5353
- Read and write operations: reads-writes.ipynb
5454
- Evaluating a Vespa Application: evaluating-vespa-application-cloud.ipynb
5555
- Troubleshooting: troubleshooting.md
56+
- ANN Parameter Tuning: ann-parameters.md
5657
- Examples: /examples/*
5758
- API Reference:
5859
- Summary: api/summary.md

0 commit comments

Comments
 (0)