Skip to main content
Prerequisites
TopK is built for high-performance dense vector search workloads. It is designed to:
  • Maintain >95% recall, reducing the likelihood of missing relevant results in applications such as recommendation systems, image search, and semantic search.
  • Deliver consistent low latency (p99 < 50 ms). See the benchmarks for details.
  • Support large-scale single-collection deployments as well as multi-tenant architectures.

Define a collection schema with a vector field

Define a schema with a vector field and add a vector_index():
Supported vector field types: See the schema reference for full API details. 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 vector field and a query vector, based on the distance metric configured in the vector index (e.g., cosine or Euclidean). You can use the computed value to sort and return the closest matches.
Let’s break down the example above:
  1. Compute the cosine similarity between the query embedding and the title_embedding field using the vector_distance() function.
  2. Store the computed cosine similarity in the title_similarity field.
  3. 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 combined with metadata filtering by adding a filter() stage to the query: