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/indexing/vector-index.mdx
+47-8Lines changed: 47 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
---
2
2
title: "Vector Indexes"
3
3
sidebarTitle: "Vector Index"
4
-
description: "Build and optimize vector indexes in LanceDB using IVF-PQ, HNSW, and binary indexes."
4
+
description: "Build and optimize LanceDB vector indexes, including IVF_HNSW_SQ, IVF_RQ, IVF_PQ, and binary indexes."
5
5
icon: "arrow-up-right-dots"
6
6
---
7
7
import {
@@ -42,6 +42,38 @@ You can create a new index with different parameters using `create_index` - this
42
42
Although the `create_index` API returns immediately, the building of the vector index is asynchronous. To wait until all data is fully indexed, you can specify the `wait_timeout` parameter.
43
43
</Note>
44
44
45
+
## Choose the Right Index
46
+
47
+
Use this table as a quick starting point:
48
+
49
+
| If your top priority is... | Use this index | Why | Typical compressed size vs. raw vectors |
50
+
| :--- | :--- | :--- | :--- |
51
+
| Best recall/latency trade-off |`IVF_HNSW_SQ`| Combines IVF partitioning with HNSW graph search for strong quality at low latency. | Typically a little larger than `1/4` of raw size |
52
+
| Maximum compression |`IVF_RQ`| RaBitQ-style quantization with very strong compression. | Around `1/32` of raw size |
53
+
| Higher accuracy at small dimensions (`dimension <= 256`) |`IVF_PQ`| On small-dimensional vectors, `IVF_PQ` often provides higher accuracy with similar performance compared to `IVF_RQ`. | Usually `1/64` to `1/16` of raw size (depends on `num_sub_vectors`) |
54
+
55
+
<Warning>
56
+
If your vector search frequently includes metadata filters (`where(...)`), prefer `IVF_RQ` or `IVF_PQ`. In filtered workloads, `IVF_HNSW_SQ` latency can fluctuate significantly.
57
+
</Warning>
58
+
59
+
Compression ratios are practical rules of thumb and can vary with vector distribution, metric, and configuration.
60
+
For small dimensions, choose `IVF_PQ` for accuracy, not for guaranteed higher compression than `IVF_RQ`.
61
+
62
+
### Indexing Tuning by Index Type
63
+
64
+
Start with these values, then tune for your workload:
65
+
66
+
-`IVF_HNSW_SQ`
67
+
-`num_partitions`: start at `num_rows // 1,048,576` (rounded to an integer)
68
+
- Lower `num_partitions` can reduce search latency, but index build may become slower because partitions are larger.
69
+
-`ef_construction`: start at `150`; increase for better recall, decrease for faster indexing.
70
+
-`IVF_RQ`
71
+
-`num_partitions`: start at `num_rows // 4096` (rounded to an integer). This is a strong default for most datasets.
72
+
-`IVF_PQ`
73
+
-`num_partitions`: start at `num_rows // 4096` (rounded to an integer).
74
+
-`num_sub_vectors`: start at `dimension // 8`. Increase for better recall, decrease for faster search and smaller indexes.
75
+
- For small dimensions (`dimension <= 256`), `IVF_PQ` is often preferred over `IVF_RQ` for better accuracy at similar query performance.
76
+
45
77
## Example: Construct an IVF Index
46
78
47
79
In this example, we will create an index for a table containing 1536-dimensional vectors. The index will use IVF_PQ with L2 distance, which is well-suited for high-dimensional vector search.
@@ -53,12 +85,15 @@ Make sure you have enough data in your table (at least a few thousand rows) for
53
85
Sometimes you need to configure the index beyond default parameters:
54
86
55
87
- Index Types:
56
-
-`IVF_PQ`: Default index type, optimized for high-dimensional vectors
57
-
-`IVF_HNSW_SQ`: Combines IVF clustering with HNSW graph for improved search quality
88
+
-`IVF_HNSW_SQ`: best recall/latency trade-off
89
+
-`IVF_RQ`: best compression for large, high-dimensional datasets
90
+
-`IVF_PQ`: often higher accuracy than `IVF_RQ` for small dimensions (`<= 256`) at similar query performance
58
91
-`metrics`: default is `l2`, other available are `cosine` or `dot`
59
92
- When using `cosine` similarity, distances range from 0 (identical vectors) to 2 (maximally dissimilar)
60
-
-`num_partitions`: The number of partitions in the IVF portion of the index. This number is usually chosen to target a particular number of vectors per partition. A common heuristic is `num_rows / 8192`. Larger values generally make index building take longer but use less memory, and they often improve accuracy at the cost of slower search because queries typically need a higher `nprobes`. LanceDB automatically selects a sensible default `num_partitions` based on the heuristic mentioned above.
61
-
-`num_sub_vectors`: The number of sub-vectors that will be created during Product Quantization (PQ). This number is typically chosen based on the desired recall and the dimensionality of the vector. Larger `num_sub_vectors` increases accuracy but can significantly slow queries; a good starting point is `dimension / 8`.
93
+
-`num_partitions`: use index-specific starting points from the section above:
94
+
-`IVF_HNSW_SQ`: `num_rows // 1,048,576`
95
+
-`IVF_RQ` and `IVF_PQ`: `num_rows // 4096`
96
+
-`num_sub_vectors`: applies to `IVF_PQ`; start with `dimension // 8`. Larger values often improve recall but can slow search.
62
97
63
98
Let's take a look at a sample request for an IVF index:
64
99
@@ -81,7 +116,7 @@ Connect to LanceDB and open the table you want to index.
81
116
82
117
### 2. Construct an IVF Index
83
118
84
-
Create an `IVF_PQ` index with `cosine` similarity. Specify `vector_column_name` if you use multiple vector columns or non-default names. By default LanceDB uses Product Quantization; switch to `IVF_SQ` for scalar quantization.
119
+
Create an `IVF_PQ` index with `cosine` similarity. Specify `vector_column_name` if you use multiple vector columns or non-default names. You can switch `index_type` to `IVF_RQ` or `IVF_HNSW_SQ` depending on your recall/latency/compression target.
0 commit comments