Evaluate kNN search settings
- POST also GET /{index}/_knn_eval
Estimate the recall and cost of approximate kNN search configurations on a dense_vector field against a more thorough baseline.
The field must use the bbq_disk index type, and must not be inside a nested object.
Each knn_settings entry reports the mean recall of the baseline's top k, not of relevance judgments, plus included and excluded query counts and cost totals.
A query is excluded from the mean recall when the candidate finds a document scoring above the baseline's lowest top k score.
A baseline returning fewer than k hits fails that query, because recall at k is undefined.
All configurations run against one point in time.
The default baseline uses a visit_percentage of 20 and a rescore_vector.oversample of 100.
An exact full-precision baseline must be requested explicitly with allow_exact_baseline, and is limited to 100 million vector-by-query comparisons.
The request is refused when the search.knn_eval.enabled cluster setting or the index.knn_eval.enabled index setting is false.
Required authorization
- Index privileges read view_index_metadata
Query parameters
-
ignore_unavailableboolean · default: false -
If
false, the request returns an error if it targets a missing or closed index. -
allow_no_indicesboolean · default: true -
If
false, the request returns an error if any wildcard expression, index alias, or_allvalue targets only missing or closed indices. This behavior applies even if the request targets other open indices. -
expand_wildcardsunion oneOf · default: open -
The type of index that wildcard patterns can match. It supports comma-separated values, such as
open,hidden.Supported values include:
all: Match any data stream or index, including hidden ones.open: Match open, non-hidden indices. Also matches any non-hidden data stream.closed: Match closed, non-hidden indices. Also matches any non-hidden data stream. Data streams cannot be closed.hidden: Match hidden data streams and hidden indices. Must be combined withopen,closed, orboth.none: Wildcard expressions are not accepted.
-
Values:
allopenclosedhiddennone -
wait_for_completionboolean · default: true -
If
true, the request waits for the evaluation to complete. A large evaluation can run for minutes, and closing the connection, for example because of a client or proxy timeout, cancels it. Iffalse, the request returns a task identifier, and stores the completed response for retrieval through the task management API.
Request body
-
query_sourceunion oneOfrequired -
The source of the query vectors.
-
One of:
(determined by
from) -
baselineobject -
The settings of the search that the
knn_settingsentries are compared with. If not specified, it uses avisit_percentageof 20 and arescore_vector.oversampleof 100. -
knn_settingsobject[]required -
The kNN search settings to evaluate, from 1 to 32 unique entries.
from: docs
Samples the query vectors from the stored documents.
from: vectors
Uses the query vectors in the request.
Response
-
query_sourceobject -
The source of the query vectors. Not returned when
wait_for_completionisfalse. -
baselineobject -
The settings of the baseline search. Not returned when
wait_for_completionisfalse. -
visit_percentagenumber -
The percentage of postings to visit, from 0 to 100.
0selects the automatic visit calculation. -
num_candidatesnumber -
The number of nearest neighbor candidates to consider per shard. It can't be less than
k, or more than 10000 (9999 with sampling). -
exactboolean · default: false -
If
true, compares every vector at full precision. Only applies to thebaseline, requiresallow_exact_baseline, and can't be combined with other settings. -
baseline_took_msnumber -
The time the baseline searches took, in milliseconds. Not returned when
wait_for_completionisfalse. -
baseline_vector_opsnumber -
The number of vector operations of the baseline searches. Not returned when
wait_for_completionisfalse. -
baseline_vector_ops_kindenum -
What
baseline_vector_opscounts. Not returned whenwait_for_completionisfalse.Supported values include:
full_precision_scan: Full-precision comparisons across all the matching vectors.quantized_visit_plus_rescore: Quantized visits plus full-precision rescoring.
-
Values:
full_precision_scanquantized_visit_plus_rescore -
resultsobject[] -
The results of each
knn_settingsentry, in the order of the request. Not returned whenwait_for_completionisfalse. -
knn_settingsobjectrequired -
The evaluated settings.
-
visit_percentagenumber -
The percentage of postings to visit, from 0 to 100.
0selects the automatic visit calculation. -
num_candidatesnumber -
The number of nearest neighbor candidates to consider per shard. It can't be less than
k, or more than 10000 (9999 with sampling). -
exactboolean · default: false -
If
true, compares every vector at full precision. Only applies to thebaseline, requiresallow_exact_baseline, and can't be combined with other settings. -
recallunion number | stringrequired nullable -
The mean recall of the included queries, or
nullif no query is included.