collection: like a table in sql, each has its own dimension, indexes,
point: row/record to store vector + payload
payload: metadata attached to a vector
filtering: sql styled conditions on payload
indexing: organizing vectors for fast search
vectors
- dense vectors: regular embeddings
- sparse vectors: not fixed lenght, exact term matching
- multivectors: matrix of vectors
// A sparse vector with 4 non-zero elements
{
"indexes": [1, 3, 5, 7],
"values": [0.1, 0.2, 0.3, 0.4]
}the sparse vectors contains many zeroes, they are stored separately in qdrant special storage.
payload types
- integer
- float
- bool
- string
- geolocations
- datetime
- UUID
Approximate COrdinate-based Nearest Neighbor (ACORN) search algorithm: has a similar recall but has a very low memory usage and update cost as compared to HNSW
we can also group the documents by document_id via groups API
without grouping
1. chunk 5 of doc A
2. chunk 8 of doc A
3. chunk 3 of doc A
4. chunk 12 of doc A
5. chunk 1 of doc ALLM gets nearly identical contexts
with grouping by doc_id
1. best chunk from doc A
2. best chunk from doc B
3. best chunk from doc C
4. best chunk from doc D
5. best chunk from doc ELLM gets diverse knowledge
ingesting same document metadata for millions of chunks can waste storage, you can create duplicated metadata inside a collection and reference it in your queries to space space its called lookup in groups
dont index if your points are less than 5k
create indexes (lookup tables) for metadata to get faster results for each query type
cardinality = how many points will match my filter
if cardinality is 10 → brute force
if 1000 → brute force
if 100,000 → ANN
if 10,000,000 → ACORN + heavy indexing
Recommendations API
we can also get recommendations via multiple algorithms defined in qdrant. (average_vector, best_score, sum_scores)
postiive vectors = things the user has liked
negative vectors = things the user dislikes
1. Average vector:
search_vector = 2 * avg_of_all_positive_vectors - avg_of_all_negative_vectorsthen run regular ANN search using search vector
2. Best score strategy
candidate = item inside your db
for candidate in candidates:
if max(sim to positives) > max(sim to negatives):
candidate["score"] = +strength
else:
candidate["score"] = -strengththen rank the candidates based on their scores
3. Sum score strategy
for each C in candidates
final_score = sum(sim(C, positives)) - sum(sim(C, negatives))
then rank the candidates based on their scores
Discovery API
concept of context: set of positive and negative pairs, each pair divides the space into positive and negative zones
discovery search: inputs context pairs and a target vector
target vector = what you ultimately want to find like
context pairs = positive negative pairs
context search: you dont provide target, just context pairs, returns points that are in best positive zones
Hybrid search: uses dense and sparse retrieval to get the most relevant documents
- Reciprocal Rank Fusion (RRF)
issa formulae that inputs rank of sparse and dense retrieval and outputs the revised scores
rank means, most similar document → rank=1
second most similar document → rank=2 - DBSF (distribution based score fusion)
this first normalizes the densed and sparsed retrieved documents
then computes the final score leading to better matches
problem before this was, sparse query barely matters cuz its scores are very low compared to dense scores, and your final ranking was biased towards dense query
Maximal Marginal Relevance (MMR): without MMR top k results might be super identical to each other, if you want a little diversity, you can add MMR
tweak the diversity parameter [0, 1] to tweak the tradeoff between diversity | relevancy
after we have fetched the vectors, we can boost thier scores on the basis of metadata filters by score boosting API
BM25 (Best Matching 25) is a ranking function for text search, it uses sparse vectors that represent documents, each dimension corresponds to a word, Qdrant can generate these sparse embeddings from input text directly on the server
optimizer: some data structures are hard to change individually e.g. indexes. if you change things too often, the database operations can slow down. optimizer is qdrants way of batching changes and cleaning up segments to maintain performance.
- Vacum optimizer: when you delete points, it stays in segment until too many accumulate, vacum optimizer cleans up these deleted points.
- merge optimizer: overtime many small segments (gaps in the memory space) can form, qdrant has to scan/merge them during queries. merge optimizer merges smaller segments into large ones
- indexing optimizer: small segments mean brute force may be faster than building an index, large segments mean indexing could improve query speed. indexing optimizer enables/disables indexes on these segments dynamically
Indexing: process of building a data structure over vectors to quickly find nearest neighbors without scanning every vector
- payload index: create index for metadata, exact matches for keywords/range for integers/true false filters/xyz
- on disk payload index: by default payload indexes are in memory for fast access. if indexes are too large or rarely used, they can be stored on disk. it saves ram
- full text index: we usually tokenize the full text metadata which are then indexed in the inverted index
Tokenizer: a tokenizer is an algorithm that splits text into smaller pieces called tokens so Qdrant can index and search efficiently
- word tokenizer
- whitespace tokenizer
- prefix tokenizer: splits the words but also indexes prefixes allows for autocomplete or prefix search
- multilingual: uses charabia and vaporetto packages to tokenize large variety of languages
factors affecting tokenization:
- lowercasing
- ascii folding: converts accented chars.
café→cafe - stemmer: reducing words to their root words. running → run
- stopwords: ignores common words
Embedding generation pipeline
- Tokenization
Step: Convert text into tokens (subword units)
Output: List of token IDs
"I love AI"
→ [101, 1045, 2293, 9932, 102]b. Token Embedding Lookup
Step: Each token ID is mapped to a vector from embedding table
Output: Sequence of vectors
(5 tokens) → (5, D)
e.g. → (5, 384) or (5, 3072)c. Positional Encoding Addition
Step: Add position information so order matters
Output: Position-aware token embeddings
(5, 384) → (5, 384) with order info injectedd. Transformer Layers (Contextualization)
Step: Self-attention mixes information across tokens
Output: Context-aware token embeddings
(5, 384) → (5, 384) but now each token “understands” otherse. Pooling (Sentence Compression)
Step: Combine token embeddings into one vector
Output: Single sentence embedding
(5, 384) → (384,)f. (Optional) Normalization
Step: Normalize vector length (L2 norm usually)
Output: Final embedding used for similarity search
(384,) → normalized (384,)Core Evaluation Metrics
1. Precision@K
Of top K results → how many are relevant?
Focus: correctness of top results
2. Recall@K
Of all relevant documents → how many did we retrieve in top K?
Focus: coverage
3. MRR (Mean Reciprocal Rank)
Looks at position of first relevant result
Formula idea:
Rank 1 → best score
Rank 10 → low score
Focus: “How fast do we find a correct answer?”
4. DCG (Discounted Cumulative Gain)
Measures relevance of entire ranking
Gives higher weight to top positions
5. NDCG (Normalized DCG)
DCG normalized by ideal ranking (IDCG)
Range: 0 → 1
Most important metric for ranking systems