Overview
- In a vector database, both your stored items and incoming queries are represented as vectors (numeric arrays called embeddings).
- The system performs nearest-neighbor searches in a semantic vector space and returns items whose vectors are closest to the query vector.
- This enables searching by meaning rather than by exact keyword matches.
How queries work in a vector database
When you submit a search phrase, it is converted into an embedding (a vector) using an embedding model. All documents or items in the database are stored as vectors produced by the same or a compatible model. The database compares the query vector to stored vectors and returns the most similar items. Example: Query text:Example results and similarity scores
- Laptop — similarity: 0.91 (very close): matches the query well.
- Tablet — similarity: 0.89 (also relevant).
- Chair — similarity: 0.29 (irrelevant).
| Metric | Description | Typical range / notes |
|---|---|---|
| Cosine similarity | Measures the cosine of the angle between vectors; commonly used for text | −1..1 (often normalized to 0..1 for ranking) |
| Euclidean distance | Geometric distance in embedding space | Lower is better (0 = identical) |
| Dot product / inner product | Sum of element-wise products; sometimes used with specific models or hardware optimizations | Larger values indicate more similarity for normalized vectors |
Choosing the right embedding model and similarity metric is crucial. Models trained on your domain (or fine-tuned) will place domain-specific concepts closer together and improve retrieval quality.
Similarity scores are model-dependent. Unexpected high or low scores may indicate an embedding/model mismatch or data-quality issue — inspect both embeddings and the model choice before tuning thresholds.
Semantic search vs. exact-match SQL
Here’s a side-by-side contrast to clarify the difference. Traditional database (exact-match SQL)- Operates on structured fields and exact values.
- Best for transactional workloads, aggregates, joins, and ACID guarantees.
- Converts text into embeddings and searches a semantic vector space for nearest neighbors.
- Returns items ranked by semantic similarity rather than exact keyword matches.
When to use each system
| Resource Type | Use Case | Which to use and why |
|---|---|---|
| Structured records (orders, transactions) | Exact queries, joins, aggregates, ACID needs | Traditional relational DB |
| Search across documents, notes, or media | Meaning-based relevance, fuzzy queries, multi-modal retrieval | Vector database + embeddings |
| Hybrid use (filters + relevance) | Combine structured filters (e.g., date, user) with semantic ranking | Use both: SQL/NoSQL for filters + vector DB for ranking |
Practical considerations
- Indexing & performance: For large datasets, approximate nearest neighbor (ANN) indexes (HNSW, IVF, PQ, etc.) drastically improve query speed with modest accuracy trade-offs.
- Scaling: Vector indexes and storage require different resource considerations compared to relational indexes (CPU/GPU for embedding generation, memory/SSD for ANN indexes).
- Model choice: Off-the-shelf models often work well, but fine-tuning or using domain-specific embeddings improves relevance.
- Evaluation: Validate retrieval using domain-specific relevance labels and metrics (e.g., recall@k, MRR).
Real-world example
Tools like Notion AI convert user queries into vectors and retrieve the most relevant notes by semantic similarity. This allows the system to return relevant content even when the user uses different words than the original notes — making search feel more like understanding than keyword matching.Next steps / Further reading
Topics to explore next:- Embedding generation: comparing popular models and their trade-offs.
- ANN indexes: HNSW, IVF, PQ and how they impact speed vs. accuracy.
- Hybrid search: combining structured filtering with semantic ranking.
- Evaluation: building labeled datasets and metrics for tuning retrieval.
- Kubernetes Documentation — (general ops reference)
- Notion AI product page
- Search terms to explore:
vector database,semantic search,embeddings,approximate nearest neighbor (ANN),cosine similarity,HNSW