Skip to content

Commit 15768f6

Browse files
authored
Adds BBQ documentation to the Reference content (#133066)
1 parent 9447929 commit 15768f6

File tree

2 files changed

+163
-0
lines changed

2 files changed

+163
-0
lines changed
Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
---
2+
navigation_title: Better Binary Quantization (BBQ)
3+
applies_to:
4+
stack: all
5+
serverless: all
6+
---
7+
8+
# Better Binary Quantization (BBQ) [bbq]
9+
10+
Better Binary Quantization (BBQ) is an advanced vector quantization method, designed for large-scale similarity search. BBQ is a form of lossy compression for [`dense_vector` fields](https://www.elastic.co/docs/reference/elasticsearch/mapping-reference/dense-vector) that enables efficient storage and retrieval of large numbers of vectors, while keeping results close to those from the original uncompressed vectors.
11+
12+
BBQ offers significant improvements over scalar quantization by relying on optimized `bit` level computations to reduce memory usage and computational costs while maintaining high search relevance using pre-computed corrective factors. BBQ is designed to work in combination with [oversampling](#bbq-oversampling) and reranking, and is compatible with various [vector search algorithms](#bbq-vector-search-algorithms), such as [HNSW](#bbq-hnsw) and [brute force (flat)](#bbq-flat).
13+
14+
## How BBQ works [bbq-how-it-works]
15+
16+
BBQ retains the original vector’s dimensionality but transforms the datatype of the dimensions from the original `float32` to `bit` effectively compressing each vector by 32x plus an additional 14 bytes of corrective data per vector. BBQ uses these pre-computed corrective factors as partial distance calculations to help realize impressively robust approximations of the original vector.
17+
18+
Measuring vector similarity with BBQ vectors requires much less computing effort, allowing more candidates to be considered when using the HNSW algorithm. This often results in better ranking quality and improved relevance compared to the original `float32` vectors.
19+
20+
## Supported vector search algorithms [bbq-vector-search-algorithms]
21+
22+
BBQ currently supports two vector search algorithms, each suited to different scenarios. You can configure them by setting the dense vector field’s `index_type`.
23+
24+
### `bbq_hnsw` [bbq-hnsw]
25+
26+
When you set a dense vector field’s `index_options` parameter to `type: bbq_hnsw`, {{es}} uses the HNSW algorithm for fast [kNN search](https://www.elastic.co/docs//solutions/search/vector/knn) on compressed vectors. With the default [oversampling](#bbq-oversampling) applied, it delivers better cost efficiency, lower latency, and improved relevance ranking, making it the best choice for large-scale similarity search.
27+
28+
:::{note}
29+
Starting in version 9.1, `bbq_hnsw` is the default indexing method for new `dense_vector` fields with greater than 384 dimensions, so you typically don’t need to specify it explicitly when creating an index.
30+
31+
Datasets with less than 384 dimensions may see less accuracy and incur a higher overhead cost related to the corrective factors, but we have observed some production datasets perform well even at fairly low dimensions including [tests on e5-small](https://www.elastic.co/search-labs/blog/better-binary-quantization-lucene-elasticsearch).
32+
:::
33+
34+
The following example creates an index with a `dense_vector` field configured to use the `bbq_hnsw` algorithm.
35+
36+
```console
37+
PUT bbq_hnsw-index
38+
{
39+
"mappings": {
40+
"properties": {
41+
"my_vector": {
42+
"type": "dense_vector",
43+
"dims": 64,
44+
"index": true,
45+
"index_options": {
46+
"type": "bbq_hnsw"
47+
}
48+
}
49+
}
50+
}
51+
}
52+
```
53+
54+
To change an existing index to use `bbq_hnsw`, update the field mapping:
55+
56+
```console
57+
PUT bbq_hnsw-index/_mapping
58+
{
59+
"properties": {
60+
"my_vector": {
61+
"type": "dense_vector",
62+
"dims": 64,
63+
"index": true,
64+
"index_options": {
65+
"type": "bbq_hnsw"
66+
}
67+
}
68+
}
69+
}
70+
```
71+
72+
After this change, all newly created segments will use the `bbq_hnsw` algorithm. As you add or update documents, the index will gradually convert to `bbq_hnsw`.
73+
74+
To apply `bbq_hnsw` to all vectors at once, reindex them into a new index where the `index_options` parameter's `type` is set to `bbq_hnsw`:
75+
76+
:::::{stepper}
77+
::::{step} Create a destination index
78+
```console
79+
PUT my-index-bbq
80+
{
81+
"mappings": {
82+
"properties": {
83+
"my_vector": {
84+
"type": "dense_vector",
85+
"dims": 64,
86+
"index": true,
87+
"index_options": {
88+
"type": "bbq_hnsw"
89+
}
90+
}
91+
}
92+
}
93+
}
94+
```
95+
::::
96+
97+
::::{step} Reindex the data
98+
```console
99+
POST _reindex
100+
{
101+
"source": { "index": "my-index" }, <1>
102+
"dest": { "index": "my-index-bbq" }
103+
}
104+
```
105+
1. The existing index to be reindexed into the newly created index with the `bbq_hnsw` algorithm.
106+
::::
107+
108+
:::::
109+
110+
### `bbq_flat` [bbq-flat]
111+
112+
When you set a dense vector field’s `index_options` parameter to `type: bbq_flat`, {{es}} uses the BBQ algorithm without HNSW. This option generally requires fewer computing resources and works best when the number of vectors being searched is relatively low.
113+
114+
The following example creates an index with a `dense_vector` field configured to use the `bbq_flat` algorithm.
115+
116+
```console
117+
PUT bbq_flat-index
118+
{
119+
"mappings": {
120+
"properties": {
121+
"my_vector": {
122+
"type": "dense_vector",
123+
"dims": 64,
124+
"index": true,
125+
"index_options": {
126+
"type": "bbq_flat"
127+
}
128+
}
129+
}
130+
}
131+
}
132+
```
133+
134+
## Oversampling [bbq-oversampling]
135+
136+
Oversampling is a technique used with BBQ searches to reduce the accuracy loss from compression. Compression lowers the memory footprint by over 95% and improves query latency, at the cost of decreased result accuracy. This decrease can be mitigated by oversampling during query time and reranking the top results using the full vector.
137+
138+
When you run a kNN search on a BBQ-indexed field, {{es}} automatically retrieves more candidate vectors than the number of results you request. This oversampling improves accuracy by giving the system more vectors to re-rank using their full-precision values before returning the top results.
139+
140+
```console
141+
GET bbq-index/_search
142+
{
143+
"knn": {
144+
"field": "my_vector",
145+
"query_vector": [0.12, -0.45, ...],
146+
"k": 10,
147+
"num_candidates": 100
148+
}
149+
}
150+
```
151+
152+
By default, oversampling is set to 3×, meaning if you request k:10, {{es}} retrieves 30 candidates for re-ranking. You don’t need to configure this behavior; it’s applied automatically for BBQ searches.
153+
154+
:::{note}
155+
You can change oversampling from the default 3× to another value. Refer to [Oversampling and rescoring for quantized vectors](https://www.elastic.co/docs/solutions/search/vector/knn#dense-vector-knn-search-rescoring) for details.
156+
:::
157+
158+
## Learn more [bbq-learn-more]
159+
160+
- [Better Binary Quantization (BBQ) in Lucene and {{es}}](https://www.elastic.co/search-labs/blog/better-binary-quantization-lucene-elasticsearch) - Learn how BBQ works, its benefits, and how it reduces memory usage while preserving search accuracy.
161+
- [Dense vector field type](https://www.elastic.co/docs/reference/elasticsearch/mapping-reference/dense-vector) - Find code examples for using `bbq_hnsw` `index_type`.
162+
- [kNN search](https://www.elastic.co/docs/solutions/search/vector/knn) - Learn about the search algorithm that BBQ works with.

docs/reference/elasticsearch/toc.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ toc:
3737
- file: index-settings/index.md
3838
children:
3939
- file: index-settings/serverless.md
40+
- file: index-settings/bbq.md
4041
- file: index-settings/index-modules.md
4142
- file: index-settings/shard-allocation.md
4243
children:

0 commit comments

Comments
 (0)