Skip to main content
Prerequisites
TopK provides native support for sparse vector search, enabling exact retrieval over high-dimensional sparse representations. It is designed to:
  • Provide 100% recall (exact search).
  • Support learned sparse representations such as SPLADE.
  • Deliver consistent low latency (p99 < 20 ms). See the benchmarks for details.
  • Support large-scale single-collection deployments as well as multi-tenant architectures.

Define a collection schema with a sparse vector field

Define a schema with a sparse vector field and add a vector_index():
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.
To retrieve the top-k nearest neighbors of a query vector, use the fn.vector_distance() function. fn.vector_distance() computes the distance (or similarity) between a stored sparse vector field and a query vector, based on the distance metric configured in the vector index (e.g., dot product). You can use the computed value to sort and return the closest matches.
Let’s break down the example above:
  1. Compute the sparse dot product between the query embedding and the title_embedding field using the vector_distance() function.
  2. Store the computed dot product score in the title_score field.
  3. 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 combined with metadata filtering by adding a filter() stage to the query: