Guides
Vector search
TopK Vector Search Guide
Vector search is the essential feature of TopK. With that in mind, it is designed to:
- Stay above 95% recall — your application (e.g. recommendation, image search, semantic search) rarely misses relevant results.
- Provide consistent low latency (<100ms/p99)
- Support large-scale as well as multi-tenant configurations
How to run a vector search
Prerequisites
Define a schema with a vector field e.g. f32_vector()
and add a vector_index()
to it:
When defining a vector field, you need to specify the of the vector.
To perform a vector search on this field, index it with a vector index and specify the parameter.
Find the closest neighbors
To find the top-k closest neighbors of the query vector, use the vector_distance()
function.
It computes a numeric value(depending on the vector distance metric specified in the vector index) which you can use to sort the results:
Let’s break down the example above:
- Compute the cosine similarity between the query embedding and the
title_embedding
field using thevector_distance()
function. - Store the computed cosine similarity in the
title_similarity
field. - Return the top 10 results sorted by the
title_similarity
field in a descending order.
Combine vector search with metadata filtering
Vector search can be easily combined with metadata filtering by adding a filter()
stage to the query: