Vector search optimization на собеседовании Data Scientist
Карьерник — Duolingo для аналитиков: 10 минут в день тренируй SQL, Python, A/B, статистику, метрики и ещё 3 темы собеса. 1500+ вопросов в Telegram-боте. Бесплатно.
Содержание:
Зачем разбирать на собесе
Vector search в production требует tuning. На собесе DS: «как scale до миллиардов», «recall budget».
Recall vs latency trade-off
ANN (Approximate Nearest Neighbors) — trade-off: lower recall, faster search.
Recall. Доля true nearest, найденных в approximate top-K. Если true k=10, ANN возвращает 9 of them — recall = 0.9.
Tuning. Каждый ANN method имеет params для recall ↔ latency.
HNSW efSearch: higher → recall+, latency+
IVF nprobe: higher → recall+, latency+Production target: recall ≥ 0.95-0.99 на target latency.
HNSW параметры
Build time:
- M. Max connections per layer. 16-64 typical. Higher → better recall, more memory.
- efConstruction. Search width при build. 200-500.
Query time:
- efSearch. Search width при query. Tune to target recall.
hnsw.efSearch = 100 # быстрее, recall ниже
hnsw.efSearch = 500 # медленнее, recall вышеIVF + PQ
IVF. Divide vectors на nlist clusters (Voronoi). Search — пробег только nprobe ближайших clusters.
nlist = 4 × √N (heuristic)
nprobe ≈ 10-100 (tunable)PQ (Product Quantization). Compress vectors. d=128-dim → split into 8 sub-vectors of 16-dim → kmeans-like compression each.
Original: 128 floats × 4 bytes = 512 bytes per vector
PQ: 8 × 1 byte = 8 bytes per vector (64× less)Recall падает на 2-5%, memory на 60×.
IVF-PQ. Combine — clustering + compression. На billion-scale — single GPU memory.
Reranking
После ANN retrieve top-K (e.g., 100), rerank с exact similarity на actual vectors.
1. ANN: query → 100 candidates (approximate).
2. Exact dot product / cosine на 100 candidates.
3. Sort, return top-10.100 exact computations cheap. Final accuracy — exact.
Cross-encoder rerank. Для search. После dense retrieval — heavier model оценивает (query, doc) pairs.
Hybrid search
Dense + Sparse (BM25). Combine semantic + keyword.
final = α · dense_score + (1-α) · bm25_scoreBetter recall на keyword-heavy queries.
Reciprocal rank fusion (RRF). Combines ranking без weight tuning.
score(d) = Σ_methods 1 / (k + rank_method(d))Связанные темы
- Vector databases на собесе DS
- Two-tower DSSM для DS
- Cosine vs Euclidean для DS
- Embeddings на собесе DS
- Подготовка к собесу Data Scientist
FAQ
Это официальная информация?
Нет. Статья основана на документации FAISS / Pinecone / pgvector.
Тренируйте Data Science — откройте тренажёр с 1500+ вопросами для собесов.