Prerequisites
- TopK account (Sign up here)
- TopK API key (Get an API key here)
semantic_index() to a field in your collection schema and querying with fn.semantic_similarity():
- Search text by meaning
- Search images by meaning
semantic_index() is powered by the production model of topk-embed-v1, TopK’s own family of multi-vector embedding models, combined with Sparse Multi-Vector Encoding (SMVE) for scalable retrieval and quantized MaxSim reranking.
Learn more about the smaller models in the family, topk-embed-v1-xsmall and topk-embed-v1-small.
Why multi-vector? Single-vector (dense) embeddings compress an entire document into one point in high-dimensional space.Multi-vector models like topk-embed-v1 keep one embedding per token, enabling token-level matching via MaxSim scoring. This consistently outperforms dense models on out-of-domain content, long documents, specific clauses, tables, and structured data.Read Introducing topk-embed-v1 for model benchmarks and High-Quality Search, Out of the Box for a deep-dive into the architecture.
How to perform a semantic search
In the following example, we’ll:1
Define a collection schema
Create a collection configured for semantic search.
2
Add documents
Insert documents into the collection.
3
Run a semantic query
Search the
title text field by meaning with a free-form query.Define a collection schema
Semantic search is enabled by adding asemantic_index() to a text() field in the collection schema:
Add documents to the collection
Let’s add some documents to the collection:Run a semantic query
To search for documents based on semantic similarity, use thefn.semantic_similarity() function:
1
Encode and score
The
semantic_similarity() function encodes the query "classic American novel" into multi-vector token embeddings using the topk-embed-v1 production model and scores each document via quantized MaxSim — comparing every query token against every document token to find the best alignment.2
Retrieve candidates
Candidate retrieval is accelerated by SMVE, which uses fast sparse approximations to identify a small set of candidates before the full MaxSim pass.
3
Rank results
The results are ranked by their MaxSim score and the top 10 most relevant documents are returned.
Searching images
semantic_index() also works on image() fields, so you can search images with a free-form text query. TopK embeds the images for you with the same model it uses for text: topk-embed-v1 is multimodal.
Define an image field
Add asemantic_index() to an image() field:
Add images
Images are stored as JPEG or PNG, up to 512KB each (see limits).Query images with text
Pass the image field tofn.semantic_similarity() together with a text query:
Stored raw images can’t be selected in queries. To fetch the raw document, use the Get API with the
_ids returned by the query:Inference
Model version
Adding asemantic_index() does not specify a model or a model version. For embedding, the latest generation of topk-embed models (topk-embed-v1) is used.
Text and image fields are embedded by the same model.
Combining semantic and keyword search
For certain use cases, you might want to use a combination of keyword search and semantic search:ensuring your search results capture both exact matches and contextual meaning with a custom scoring function that’s best suited for your use case.