Sparse vector search
TopK Sparse Vector Search Guide
Similar to dense vector search, sparse vector search is an essential feature of TopK. With that in mind, it is designed to:
- Provide 100% recall.
- Support learned sparse vector representations, for example SPLADE.
- Provide consistent low latency (<20ms p99). Check out our benchmarks.
- Support large-scale single-collection as well as multi-tenant use cases.
How to run a sparse vector search
Prerequisites
Define a schema with a sparse vector field, either f32_sparse_vector()
or u8_sparse_vector()
, and add a vector_index()
to it:
Sparse vectors do not have a fixed dimension, so you don’t need to specify the vector dimension when defining the field.
TopK only supports dot_product
metric for sparse vectors which is compatible with both fixed and learned sparse
vector representations.
Find the most relevant documents
To find the top-k most relevant results for the query, use the vector_distance()
function.
This function computes a score between the provided sparse query and indexed sparse vectors which can then be used to sort the results.
Let’s break down the example above:
- Compute the sparse dot product between the query embedding and the
title_embedding
field using thevector_distance()
function. - Store the computed dot product score in the
title_score
field. - Return the top 10 results sorted by the
title_score
field in a descending order.
Combine sparse vector search with metadata filtering
Sparse vector search can be easily combined with metadata filtering by adding a filter()
stage to the query: