Tune vector search accuracy and speed: DiskBBQ
The vector indexes of Agentic ES are built on the disk-native quantized index bbq_disk (DiskBBQ). At query time, it first performs a fast coarse scan over the 1-bit compressed vector clusters on disk (significantly reducing memory usage and disk reads), then reads the original floating-point vectors of the selected candidates for exact rescoring (fine ranking). By tuning visit_percentage and rescore_vector.oversample, you can strike the best balance between recall and query latency for your needs.
All API examples in this topic provide CONSOLE / CURL / GO / PYTHON / JAVASCRIPT / JAVA code tabs (CONSOLE requests can be copied directly into Kibana Dev Tools), reusing the Quick start's demo-knowledge-chunks collection and its sample data.
1. How it works and core tuning parameters
You can think of the DiskBBQ query process as finding the k most relevant books in a library:
Step 1, fast coarse scan (controlled by
visit_percentageornum_candidates): first look at the compressed catalog (the1-bitcompressed vector clusters on disk) to quickly shortlist the most likely relevant books, greatly reducing disk reads.Step 2, exact rescoring (controlled by
rescore_vector.oversample): read the original floating-point vectors of the shortlisted candidates, compute exact distances one by one, and finally return the most accurate topkresults. For example, to returnk = 10results with the defaultoversample = 10.0, the system first coarse-scans10 × 10 = 100candidates, rescores them exactly, then truncates to the top 10.
Beyond the basic k and num_candidates parameters, DiskBBQ provides two parameters that directly control the "coarse-scan scope" and the "rescoring precision":
Parameter | Stage | Default | Description |
(mapping: | Coarse scan (proportion of vector clusters scanned) |
|
|
| Fine ranking (multiplier for rescoring original vectors) |
| Rescores |
Two key effective rules:
Parameter precedence: per-query parameters take precedence over mapping defaults; when the effective
visit_percentage > 0,num_candidatesno longer determines the scan ratio (passing an explicit0in the query switches back tonum_candidatesmode).Lower bound on candidate size: when
visit_percentage = 0and rescoring is enabled, the actual candidate size ismax(num_candidates, k × oversample). Therefore, to reduce latency, loweroversampleand make surenum_candidatesis not greater thank × oversample(or do not passnum_candidatesexplicitly) — merely reducingnum_candidatesbelowk × oversamplehas no effect, and when an excessively largenum_candidatesis passed explicitly, lowering onlyoversamplereduces the number of rescored items but does not shrink the coarse-scan scope.
Tuning reference for common scenarios:
Business need | Recommended starting configuration | Expected effect |
Balanced (default starting point) | Do not pass | Balances low latency with relatively high recall; suitable as a starting point for most workloads. |
Pursue high recall (knowledge-base Q&A, legal search) | Increase | Widens the coarse-scan and rescoring scope and reduces missed recall, with a moderate latency increase ( |
Pursue ultra-low latency (high-concurrency first-pass filtering for recommendations) | Lower | Shrinks the disk reads and rescoring work of both stages and lowers P99 latency, with recall dropping accordingly. |
The top-level knn, retriever.knn, and the retriever.rrf retriever's nested knn clause all support passing visit_percentage and rescore_vector. For vector fields and basic kNN syntax, also refer to the Elasticsearch documentation: Dense vector and kNN search.
2. Explicitly specify visit_percentage and rescore_vector
CONSOLE
POST /demo-knowledge-chunks/_search?_slice=kb-a&allow_partial_search_results=false
{
"knn": {
"field": "embedding",
"query_vector": [0.80, 0.12, 0.05, 0.03],
"k": 5,
"visit_percentage": 10.0,
"rescore_vector": {
"oversample": 15.0
},
"filter": { "term": { "category": "after-sales" } }
},
"_source": ["title", "category"]
}CURL
curl -u "$ES_USER:$ES_PASSWORD" -X POST \
"$ES_ENDPOINT/demo-knowledge-chunks/_search?_slice=kb-a&allow_partial_search_results=false" \
-H 'Content-Type: application/json' \
--data-binary @- <<'JSON'
{
"knn": {
"field": "embedding",
"query_vector": [0.80, 0.12, 0.05, 0.03],
"k": 5,
"visit_percentage": 10.0,
"rescore_vector": {
"oversample": 15.0
},
"filter": { "term": { "category": "after-sales" } }
},
"_source": ["title", "category"]
}
JSONGO
res, err := client.Search().
Index("demo-knowledge-chunks").
Routing("kb-a").
AllowPartialSearchResults(false).
Knn(&types.KnnSearch{
Field: "embedding",
QueryVector: []float32{0.80, 0.12, 0.05, 0.03},
K: some.Int(5),
VisitPercentage: some.Float32(10.0),
RescoreVector: &types.RescoreVector{Oversample: 15.0},
Filter: []types.Query{{Term: map[string]types.TermQuery{"category": {Value: "after-sales"}}}},
}).
SourceIncludes_("title", "category").
Do(ctx)
if err != nil {
log.Fatal(err)
}
fmt.Println(res.Hits.Hits)PYTHON
res = client.search(
index="demo-knowledge-chunks",
routing="kb-a",
allow_partial_search_results=False,
knn={
"field": "embedding",
"query_vector": [0.80, 0.12, 0.05, 0.03],
"k": 5,
"visit_percentage": 10.0,
"rescore_vector": {"oversample": 15.0},
"filter": {"term": {"category": "after-sales"}},
},
source=["title", "category"],
)
print(res["hits"]["hits"])JAVASCRIPT
const res = await client.search({
index: 'demo-knowledge-chunks',
routing: 'kb-a',
allow_partial_search_results: false,
knn: {
field: 'embedding',
query_vector: [0.80, 0.12, 0.05, 0.03],
k: 5,
visit_percentage: 10.0,
rescore_vector: { oversample: 15.0 },
filter: { term: { category: 'after-sales' } },
},
_source: ['title', 'category'],
})
console.log(res.hits.hits)JAVA
SearchResponse<Map> res = client.search(s -> s
.index("demo-knowledge-chunks")
.routing("kb-a")
.allowPartialSearchResults(false)
.knn(k -> k
.field("embedding")
.queryVector(0.80f, 0.12f, 0.05f, 0.03f)
.k(5)
.visitPercentage(10.0f)
.rescoreVector(rv -> rv.oversample(15.0f))
.filter(f -> f.term(t -> t.field("category").value("after-sales"))))
.source(src -> src.filter(f -> f.includes("title", "category"))),
Map.class);
System.out.println(res.hits().hits());3. Set defaults in the collection mapping
If you want all queries on a vector field to use a higher scan ratio by default, or to change the default rescoring multiplier (the mapping-level oversample supports 0 or 1.0-10.0, and already defaults to the cap of 10.0; for values above 10.0, pass an override in the individual query), specify them directly in the mapping when creating the Collection:
"embedding": {
"type": "dense_vector",
"dims": 1024,
"index": true,
"similarity": "cosine",
"index_options": {
"type": "bbq_disk",
"default_visit_percentage": 5.0,
"rescore_vector": { "oversample": 10.0 }
}
}