Core Concepts
Reasoning
Memory & Retrieval
Agent Types
Design Patterns
Training & Alignment
Frameworks
Tools
Safety & Security
Evaluation
Meta
Core Concepts
Reasoning
Memory & Retrieval
Agent Types
Design Patterns
Training & Alignment
Frameworks
Tools
Safety & Security
Evaluation
Meta
Semantic search is a search technique that understands the intent and contextual meaning behind queries using natural language processing and machine learning, rather than relying on exact keyword matches. It works by converting queries and documents into vector embeddings and measuring their similarity in high-dimensional space. 1) 2)
Dense embeddings: High-dimensional vectors (typically 768 to 3,072 dimensions) from transformer models, capturing rich semantic information across all dimensions. Most common for semantic search. 4)
Sparse embeddings: High-dimensional but mostly zero vectors emphasizing key terms (e.g., SPLADE, learned sparse representations). Computationally lighter and interpretable, bridging the gap between keyword and semantic search.
| Metric | Description | Typical Use |
|---|---|---|
| Cosine similarity | Measures the angle between vectors (range -1 to 1), ignoring magnitude | Most common for text; insensitive to document length differences |
| Dot product | Scalar product of vectors; faster than cosine but sensitive to magnitude unless normalized | Optimized vector databases with normalized embeddings |
| Euclidean distance | Straight-line distance in vector space; penalizes magnitude differences | Less common for text; used in some ANN configurations |
Cosine similarity is the default choice for semantic search because it handles normalization differences between documents of varying lengths. 5)
| Aspect | Semantic Search | Keyword Search |
|---|---|---|
| Matching | Intent, synonyms, context via vector similarity | Exact words and phrases |
| Strengths | Handles varied phrasing, captures meaning | Fast, simple, precise for exact terms |
| Weaknesses | Compute-intensive, embedding quality dependent | Misses synonyms, no understanding of meaning |
| Example | “affordable smartphones with good cameras” finds relevant products | Requires exact terms like “cheap phone camera” |
Vector databases store and query embeddings efficiently at scale: 8)
Exact k-nearest neighbor search is too slow for large datasets (millions to billions of vectors). ANN algorithms trade small accuracy losses for dramatically faster queries: 9)