You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/reference/mapping/types/dense-vector.asciidoc
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -127,7 +127,7 @@ When using a quantized format, you may want to oversample and rescore the result
127
127
To use a quantized index, you can set your index type to `int8_hnsw`, `int4_hnsw`, or `bbq_hnsw`. When indexing `float` vectors, the current default
128
128
index type is `int8_hnsw`.
129
129
130
-
Quantized vectors can use <<knn-quantized-vector-rescoring,rescoring>> to improve accuracy on approximate kNN search results.
130
+
Quantized vectors can use <<dense-vector-knn-search-reranking,oversampling and rescoring>> to improve accuracy on approximate kNN search results.
131
131
132
132
NOTE: Quantization will continue to keep the raw float vector values on disk for reranking, reindexing, and quantization improvements over the lifetime of the data.
133
133
This means disk usage will increase by ~25% for `int8`, ~12.5% for `int4`, and ~3.1% for `bbq` due to the overhead of storing the quantized and raw vectors.
When using <<dense-vector-quantization,quantized vectors>> for kNN search, you can optionally rescore results to balance performance and accuracy.
1020
-
Rescoring works by retrieving more results per shard using approximate kNN, and then use the original vector values for rescoring these results.
1021
-
As the non-quantized, original vectors are used to calculate the final score on the top results, rescoring combines:
1022
-
- The performance and memory gains of approximate retrieval using quantized vectors on the top candidates.
1023
-
- The accuracy of using the original vectors for rescoring the top candidates.
1024
-
1025
-
Rescoring won't be as accurate as an <<exact-knn,exact kNN search>>, as some of the top results may not be retrieved using approximate kNN search.
1026
-
But the results retrieved by rescoring from the top candidates will have the same score and relative ordering as would be retrieved using exact kNN search.
1027
-
1028
-
You can use the `rescore` option to specify an `oversample` parameter.
1029
-
When `oversample` is specified, the approximate kNN search will retrieve the top `k * oversample` candidates per shard.
1030
-
It will then use the original vectors to rescore them, and return the top `k` results.
1031
-
1032
-
`num_candidates` will not be affected by oversample, besides ensuring that there are at least `k * oversample` candidates per shard.
1033
-
1034
-
Here is an example of using the `rescore` option with the `oversample` parameter:
- Search using approximate kNN with `num_candidates` set to 100.
1058
-
- Rescore the top 20 (`k * oversample`) candidates per shard using the original vectors.
1059
-
- Return the top 10 (`k`) results from the rescored candidates.
1060
-
1061
-
NOTE: Rescoring only makes sense for quantized vectors; when <<dense-vector-quantization,quantization>> is not used, the original vectors are used for scoring.
1062
-
Rescore option will be ignored for non-quantized `dense_vector` fields.
the global top `k` matches across shards. You cannot set the
1118
1069
`search_type` explicitly when running kNN search.
1119
1070
1071
+
1120
1072
[discrete]
1121
-
[[exact-knn]]
1122
-
=== Exact kNN
1073
+
[[dense-vector-knn-search-reranking]]
1074
+
==== Oversampling and rescoring for quantized vectors
1123
1075
1124
-
To run an exact kNN search, use a `script_score` query with a vector function.
1076
+
When using <<dense-vector-quantization,quantized vectors>> for kNN search, you can optionally rescore results to balance performance and accuracy, by doing:
1077
+
* Oversampling: Retrieve more candidates per shard using approximate kNN
1078
+
* Rescoring: Use the original vector values for re-calculating the score on the oversampled candidates.
1125
1079
1126
-
. Explicitly map one or more `dense_vector` fields. If you don't intend to use
1127
-
the field for approximate kNN, set the `index` mapping option to `false`. This
1128
-
can significantly improve indexing speed.
1129
-
+
1130
-
[source,console]
1131
-
----
1132
-
PUT product-index
1133
-
{
1134
-
"mappings": {
1135
-
"properties": {
1136
-
"product-vector": {
1137
-
"type": "dense_vector",
1138
-
"dims": 5,
1139
-
"index": false
1140
-
},
1141
-
"price": {
1142
-
"type": "long"
1143
-
}
1144
-
}
1145
-
}
1146
-
}
1147
-
----
1080
+
As the non-quantized, original vectors are used to calculate the final score on the top results, rescoring combines:
* The performance and memory gains of approximate retrieval using quantized vectors on the top candidates.
1083
+
* The accuracy of using the original vectors for rescoring the top candidates.
1084
+
1085
+
All forms of quantization will result in some accuracy loss and as the quantization level increases the accuracy loss will also increase.
1086
+
Generally, we have found that:
1087
+
1088
+
* `int8` requires minimal if any rescoring
1089
+
* `int4` requires some rescoring for higher accuracy and larger recall scenarios. Generally, oversampling by 1.5x-2x recovers most of the accuracy loss.
1090
+
* `bbq` requires rescoring except on exceptionally large indices or models specifically designed for quantization. We have found that between 3x-5x oversampling is generally sufficient. But for fewer dimensions or vectors that do not quantize well, higher oversampling may be required.
1091
+
1092
+
There are three main ways to oversample and rescore:
==== Oversampling and rescoring for quantized vectors
1132
+
This example will:
1133
+
* Search using approximate kNN with `num_candidates` set to 100.
1134
+
* Rescore the top 20 (`k * oversample`) candidates per shard using the original vectors.
1135
+
* Return the top 10 (`k`) results from the rescored candidates.
1206
1136
1207
-
All forms of quantization will result in some accuracy loss and as the quantization level increases the accuracy loss will also increase.
1208
-
Generally, we have found that:
1209
-
- `int8` requires minimal if any rescoring
1210
-
- `int4` requires some rescoring for higher accuracy and larger recall scenarios. Generally, oversampling by 1.5x-2x recovers most of the accuracy loss.
1211
-
- `bbq` requires rescoring except on exceptionally large indices or models specifically designed for quantization. We have found that between 3x-5x oversampling is generally sufficient. But for fewer dimensions or vectors that do not quantize well, higher oversampling may be required.
1212
1137
1213
-
There are two main ways to oversample and rescore. The first is to utilize the <<rescore, rescore section>> in the `_search` request.
===== Use the `rescore` section for top-level kNN search
1141
+
1142
+
You can use the <<rescore, rescore section>> in the `_search` request to rescore the top results from a kNN search.
1214
1143
1215
1144
Here is an example using the top level `knn` search with oversampling and using `rescore` to rerank the results:
1216
1145
@@ -1259,8 +1188,13 @@ gathering 20 nearest neighbors according to quantized scoring and rescoring with
1259
1188
<5> The weight of the original query, here we simply throw away the original score
1260
1189
<6> The weight of the rescore query, here we only use the rescore query
1261
1190
1262
-
The second way is to score per shard with the <<query-dsl-knn-query, knn query>> and <<query-dsl-script-score-query, script_score query >>. Generally, this means that there will be more rescoring per shard, but this
1263
-
can increase overall recall at the cost of compute.
0 commit comments