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: v3.0.x/site/en/userGuide/indexes/sparse/sparse-inverted-index.md
+89-24Lines changed: 89 additions & 24 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,46 +6,83 @@ summary: "The SPARSE_INVERTED_INDEX index is an index type used by Milvus to eff
6
6
7
7
# SPARSE_INVERTED_INDEX
8
8
9
-
The `SPARSE_INVERTED_INDEX` index is an index type used by Milvus to efficiently store and search sparse vectors. This index type leverages the principles of inverted indexing to create a highly efficient search structure for sparse data. For more information, refer to [INVERTED](inverted.md).
9
+
The `SPARSE_INVERTED_INDEX` index is an index type used by Milvus to efficiently store and search sparse vectors. It builds an inverted structure from the non-zero dimensions in sparse vectors. You can use this index for BM25 full text search and for sparse embedding search based on inner product.
10
+
11
+
For more information about sparse vector fields, metric types, and full text search, refer to [Sparse Vector](sparse_vector.md), [Metric Types](metric.md), and [Full Text Search](full-text-search.md).
10
12
11
13
## Build index
12
14
13
-
To build a `SPARSE_INVERTED_INDEX` index on a sparse vector field in Milvus, use the `add_index()` method, specifying the `index_type`, `metric_type`, and additional parameters for the index.
15
+
To build a `SPARSE_INVERTED_INDEX` index on a sparse vector field in Milvus, use the `add_index()` method and specify `index_type`, `metric_type`, and index parameters.
16
+
17
+
For BM25 full text search, build the index on the sparse vector field generated by a BM25 function. Set `metric_type` to `BM25`.
field_name="sparse", # Name of the sparse vector field to index
28
+
index_type="SPARSE_INVERTED_INDEX", # Type of the index to create
29
+
index_name="sparse_bm25_index", # Name of the index to create
30
+
metric_type="BM25", # Metric type used for full text search
31
+
params={"inverted_index_algo": "DAAT_MAXSCORE"},
32
+
)
20
33
34
+
client.create_index(
35
+
collection_name="your_collection_name",
36
+
index_params=index_params,
37
+
)
38
+
```
39
+
40
+
For sparse embedding search, build the index on a sparse vector field that stores externally generated sparse vectors. Set `metric_type` to `IP`.
41
+
42
+
```python
43
+
# Prepare index building params
44
+
index_params = client.prepare_index_params()
21
45
index_params.add_index(
22
-
field_name="your_sparse_vector_field_name", # Name of the vector field to be indexed
46
+
field_name="sparse_vector", # Name of the sparse vector field to index
23
47
index_type="SPARSE_INVERTED_INDEX", # Type of the index to create
24
-
index_name="sparse_inverted_index", # Name of the index to create
48
+
index_name="sparse_ip_index", # Name of the index to create
25
49
metric_type="IP", # Metric type used to measure similarity
26
-
params={"inverted_index_algo": "DAAT_MAXSCORE"}, # Algorithm used for building and querying the index
50
+
params={"inverted_index_algo": "SINDI"},
51
+
)
52
+
53
+
client.create_index(
54
+
collection_name="your_collection_name",
55
+
index_params=index_params,
27
56
)
28
57
```
29
58
30
-
In this configuration:
59
+
In the preceding configurations:
31
60
32
-
-`index_type`: The type of index to be built. In this example, set the value to `SPARSE_INVERTED_INDEX`.
61
+
-`index_type`: The type of index to build. Set this value to `SPARSE_INVERTED_INDEX`.
33
62
34
63
-`metric_type`: The metric used to calculate similarity between sparse vectors. Valid Values:
35
64
36
-
-`IP` (Inner Product): Measures similarity using dot product.
65
+
-`BM25`: Uses BM25 relevance scoring for full text search.
37
66
38
-
-`BM25`: Typically used for full-text search, focusing on textual similarity.
67
+
-`IP` (Inner Product): Measures sparse vector similarity using dot product.
39
68
40
-
For further details, refer to [Metric Types](metric.md) and [Full Text Search](full-text-search.md).
69
+
For details, refer to [Metric Types](metric.md) and [Full Text Search](full-text-search.md).
41
70
42
71
-`params.inverted_index_algo`: The algorithm used for building and querying the index. Valid values:
43
72
44
-
-`"DAAT_MAXSCORE"` (default): Optimized Document-at-a-Time (DAAT) query processing using the MaxScore algorithm. MaxScore provides better performance for high *k* values or queries with many terms by skipping terms and documents likely to have minimal impact. It achieves this by partitioning terms into essential and non-essential groups based on their maximum impact scores, focusing on terms that can contribute to the top-k results.
73
+
-`"DAAT_MAXSCORE"`: Document-at-a-Time MaxScore query processing. This is the default for `BM25`. For background, refer to [Query Evaluation: Strategies and Optimizations](https://dl.acm.org/doi/10.1016/0306-4573%2895%2900020-H).
74
+
75
+
-`"DAAT_WAND"`: Document-at-a-Time WAND query processing. This algorithm is suitable for smaller topK values or shorter queries. For background, refer to [Efficient Query Evaluation using a Two-Level Retrieval Process](https://dl.acm.org/doi/10.1145/956863.956944).
45
76
46
-
-`"DAAT_WAND"`: Optimized DAAT query processing using the WAND algorithm. WAND evaluates fewer hit documents by leveraging maximum impact scores to skip non-competitive documents, but it has a higher per-hit overhead. This makes WAND more efficient for queries with small *k* values or short queries, where skipping is more feasible.
77
+
-`"TAAT_NAIVE"`: Basic Term-at-a-Time query processing. Use this option as a baseline or when you need scoring to adapt dynamically to global collection statistics such as average document length.
47
78
48
-
-`"TAAT_NAIVE"`: Basic Term-at-a-Time (TAAT) query processing. While it is slower compared to `DAAT_MAXSCORE` and `DAAT_WAND`, `TAAT_NAIVE` offers a unique advantage. Unlike DAAT algorithms, which use cached maximum impact scores that remain static regardless of changes to the global collection parameter (avgdl), `TAAT_NAIVE` dynamically adapts to such changes.
79
+
-`"BLOCK_MAX_MAXSCORE"`: MaxScore query processing with block-level max-score metadata. For background, refer to [Faster Top-k Document Retrieval Using Block-Max Indexes](https://dl.acm.org/doi/10.1145/2009916.2010048).
80
+
81
+
-`"BLOCK_MAX_WAND"`: WAND query processing with block-level max-score metadata. For background, refer to [Faster Top-k Document Retrieval Using Block-Max Indexes](https://dl.acm.org/doi/10.1145/2009916.2010048).
82
+
83
+
-`"SINDI"`: A sparse inverted index based on fixed document-id windows, with SIMD acceleration for search. This is the default for `IP`. For details, refer to the [SINDI paper](https://arxiv.org/abs/2509.08395).
84
+
85
+
If you do not specify `inverted_index_algo`, Milvus selects the default algorithm based on `metric_type`: `DAAT_MAXSCORE` for `BM25`, and `SINDI` for `IP`.
49
86
50
87
To learn more building parameters available for the `SPARSE_INVERTED_INDEX` index, refer to [Index building params](sparse-inverted-index.md#Index-building-params).
51
88
@@ -55,19 +92,36 @@ Once the index parameters are configured, you can create the index by using the
55
92
56
93
Once the index is built and entities are inserted, you can perform similarity searches on the index.
57
94
95
+
For BM25 full text search, use raw text as the query. Milvus converts the query text into a sparse vector through the BM25 function.
96
+
97
+
```python
98
+
res = client.search(
99
+
collection_name="your_collection_name",
100
+
data=["what is information retrieval?"],
101
+
anns_field="sparse",
102
+
output_fields=["text"],
103
+
limit=3,
104
+
)
105
+
```
106
+
107
+
For sparse embedding search, use a sparse-vector dictionary as the query vector.
108
+
58
109
```python
59
110
# Prepare the query vector
60
111
query_vector = [{1: 0.2, 50: 0.4, 1000: 0.7}]
61
112
62
-
res = MilvusClient.search(
63
-
collection_name="your_collection_name", # Collection name
64
-
anns_field="vector_field", # Vector field name
65
-
data=query_vector, # Query vector
66
-
limit=3, # TopK results to return
113
+
res = client.search(
114
+
collection_name="your_collection_name",
115
+
anns_field="sparse_vector",
116
+
data=query_vector,
117
+
limit=3,
118
+
search_params={"metric_type": "IP"},
67
119
)
68
120
```
69
121
70
-
To learn more search parameters available for the `SPARSE_INVERTED_INDEX` index, refer to [Index-specific search params](ivf-flat.md#share-KDWodFEx6oCm2yxgEUAcXaUDnwg).
122
+
By default, Milvus uses the search algorithm configured for the index.
123
+
124
+
To learn more search parameters available for the `SPARSE_INVERTED_INDEX` index, refer to [Index-specific search params](sparse-inverted-index.md#Index-specific-search-params).
71
125
72
126
## Index params
73
127
@@ -87,8 +141,20 @@ The following table lists the parameters that can be configured in `params` when
87
141
<tr>
88
142
<td><p><code>inverted_index_algo</code></p></td>
89
143
<td><p>The algorithm used for building and querying the index. It determines how the index processes queries.</p></td>
<td><p>Use <code>"DAAT_MAXSCORE"</code> for scenarios with high k values or queries with many terms, which can benefit from skipping non-competitive documents. </p><p>Choose <code>"DAAT_WAND"</code> for queries with small k values or short queries to leverage more efficient skipping.</p><p>Use <code>"TAAT_NAIVE"</code> if dynamic adjustment to collection changes (e.g., avgdl) is required.</p></td>
144
+
<td><p><code>"DAAT_MAXSCORE"</code>, <code>"DAAT_WAND"</code>, <code>"TAAT_NAIVE"</code>, <code>"BLOCK_MAX_MAXSCORE"</code>, <code>"BLOCK_MAX_WAND"</code>, <code>"SINDI"</code></p><p>Default value: <code>"DAAT_MAXSCORE"</code> for <code>BM25</code>; <code>"SINDI"</code> for <code>IP</code>.</p></td>
145
+
<td><p>Use <code>"DAAT_MAXSCORE"</code> for BM25 full text search workloads with high k values or queries with many terms.</p><p>Use <code>"DAAT_WAND"</code> for BM25 workloads with small k values or short queries.</p><p>Use <code>"TAAT_NAIVE"</code> as a baseline, or when you need scoring to adapt dynamically to global collection statistics such as average document length.</p><p>Use <code>"BLOCK_MAX_MAXSCORE"</code> or <code>"BLOCK_MAX_WAND"</code> to use block-level max-score metadata for query pruning.</p><p>Use <code>"SINDI"</code> for sparse embedding search with <code>IP</code>.</p></td>
146
+
</tr>
147
+
<tr>
148
+
<td><p><code>bm25_k1</code></p></td>
149
+
<td><p>Controls term frequency saturation for BM25 scoring. This parameter applies only when <code>metric_type</code> is <code>BM25</code>.</p></td>
<td><p>Increase this value to give term frequency more weight in document ranking.</p></td>
152
+
</tr>
153
+
<tr>
154
+
<td><p><code>bm25_b</code></p></td>
155
+
<td><p>Controls the strength of document length normalization for BM25 scoring. This parameter applies only when <code>metric_type</code> is <code>BM25</code>.</p></td>
<td><p>Use a higher value to apply stronger length normalization. Use a lower value to reduce the effect of document length on ranking.</p></td>
92
158
</tr>
93
159
</table>
94
160
@@ -106,8 +172,7 @@ The following table lists the parameters that can be configured in `search_param
106
172
<tr>
107
173
<td><p><code>drop_ratio_search</code></p></td>
108
174
<td><p>The proportion of the smallest values to ignore during search, helping to reduce noise.</p></td>
109
-
<td><p>Fraction between 0.0 and 1.0 (e.g., 0.2 ignores the smallest 20% of values)</p></td>
175
+
<td><p>Range: [0.0, 1.0) (for example, 0.2 ignores the smallest 20% of values)</p></td>
110
176
<td><p>Tune this parameter based on the sparsity and noise level of your query vectors.</p><p>This parameter controls the proportion of low-magnitude values dropped during search. Increasing this value (for example, to <code>0.2</code>) can reduce noise and focus the search on more significant components, which may improve precision and efficiency. However, dropping more values can also reduce recall by excluding potentially relevant signals. Choose a value that balances recall and accuracy for your workload.</p></td>
Copy file name to clipboardExpand all lines: v3.0.x/site/en/userGuide/search-query-get/full-text-search.md
+5-5Lines changed: 5 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -430,7 +430,7 @@ export indexParams='[
430
430
</tr>
431
431
<tr>
432
432
<td><p><code>index_type</code></p></td>
433
-
<td><p>The type of the index to create. <code>AUTOINDEX</code> allows Milvus to automatically optimize index settings. If you need more control over your index settings, you can choose from various index types available for sparse vectors in Milvus. For more information, refer to <a href="index.md#Indexes-supported-in-Milvus">Indexes supported in Milvus</a>.</p></td>
433
+
<td><p>The type of the index to create. For BM25 full text search in Milvus, set this value to <code>SPARSE_INVERTED_INDEX</code>. For more information, refer to <a href="sparse-inverted-index.md">SPARSE_INVERTED_INDEX</a>.</p></td>
<td><p>The algorithm used for building and querying the index. Valid values:</p><ul><li><p><code>"DAAT_MAXSCORE"</code> (default): Optimized Document-at-a-Time (DAAT) query processing using the MaxScore algorithm. MaxScore provides better performance for high <em>k</em> values or queries with many terms by skipping terms and documents likely to have minimal impact. It achieves this by partitioning terms into essential and non-essential groups based on their maximum impact scores, focusing on terms that can contribute to the top-k results.</p></li><li><p><code>"DAAT_WAND"</code>: Optimized DAAT query processing using the WAND algorithm. WAND evaluates fewer hit documents by leveraging maximum impact scores to skip non-competitive documents, but it has a higher per-hit overhead. This makes WAND more efficient for queries with small <em>k</em> values or short queries, where skipping is more feasible.</p></li><li><p><code>"TAAT_NAIVE"</code>: Basic Term-at-a-Time (TAAT) query processing. While it is slower compared to <code>DAAT_MAXSCORE</code> and <code>DAAT_WAND</code>, <code>TAAT_NAIVE</code> offers a unique advantage. Unlike DAAT algorithms, which use cached maximum impact scores that remain static regardless of changes to the global collection parameter (avgdl), <code>TAAT_NAIVE</code> dynamically adapts to such changes.</p></li></ul></td>
445
+
<td><p>The algorithm used for building and querying the BM25 sparse inverted index. Valid values:</p><ul><li><p><code>"DAAT_MAXSCORE"</code> (default): Document-at-a-Time MaxScore query processing. This option is suitable for full text search workloads with high <em>k</em> values or queries with many terms. For background, refer to <a href="https://dl.acm.org/doi/10.1016/0306-4573%2895%2900020-H">Query Evaluation: Strategies and Optimizations</a>.</p></li><li><p><code>"DAAT_WAND"</code>: Document-at-a-Time WAND query processing. This option is suitable for full text search workloads with small <em>k</em> values or short queries. For background, refer to <a href="https://dl.acm.org/doi/10.1145/956863.956944">Efficient Query Evaluation using a Two-Level Retrieval Process</a>.</p></li><li><p><code>"TAAT_NAIVE"</code>: Basic Term-at-a-Time query processing. Use this option as a baseline, or when you need scoring to adapt dynamically to global collection statistics such as average document length.</p></li><li><p><code>"BLOCK_MAX_MAXSCORE"</code>: MaxScore query processing with block-level max-score metadata. For background, refer to <a href="https://dl.acm.org/doi/10.1145/2009916.2010048">Faster Top-k Document Retrieval Using Block-Max Indexes</a>.</p></li><li><p><code>"BLOCK_MAX_WAND"</code>: WAND query processing with block-level max-score metadata. For background, refer to <a href="https://dl.acm.org/doi/10.1145/2009916.2010048">Faster Top-k Document Retrieval Using Block-Max Indexes</a>.</p></li></ul></td>
446
446
</tr>
447
447
<tr>
448
448
<td><p><code>params.bm25_k1</code></p></td>
449
-
<td><p>Controls the term frequency saturation. Higher values increase the importance of term frequencies in document ranking. Value range: [1.2, 2.0].</p></td>
449
+
<td><p>Controls the term frequency saturation. Higher values increase the importance of term frequencies in document ranking. Recommended range: [1.2, 2.0]. Default value: 1.2.</p></td>
450
450
</tr>
451
451
<tr>
452
452
<td><p><code>params.bm25_b</code></p></td>
453
-
<td><p>Controls the extent to which document length is normalized. Values between 0 and 1 are typically used, with a common default around 0.75. A value of 1 means no length normalization, while a value of 0 means full normalization.</p></td>
453
+
<td><p>Controls the extent to which document length is normalized. Values between 0 and 1 are typically used, with a default value of 0.75. A value of 0 means no length normalization, while a value of 1 means full length normalization.</p></td>
<td><p>Proportion of low-importance terms to ignore during search. For details, refer to <a href="sparse_vector.md">Sparse Vector</a>.</p></td>
704
+
<td><p>Proportion of low-importance terms to ignore during search. The value must be in the range [0.0, 1.0). For details, refer to <a href="sparse_vector.md">Sparse Vector</a>.</p></td>
0 commit comments