Table of Contents

Semantic Search

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)

How Semantic Search Works

  1. Encoding: Text (queries and documents) is transformed into numerical vectors (embeddings) using transformer models like BERT, MPNet, or dedicated embedding models. These vectors capture semantic meaning and contextual relationships between words. 3)
  2. Indexing: Document embeddings are stored in a vector database or search index optimized for similarity queries.
  3. Querying: The user's query is encoded into an embedding using the same model.
  4. Retrieval: The query embedding is compared to stored document embeddings using similarity metrics, and top-k most similar documents are returned.

Types of Embeddings

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.

Vector Similarity Metrics

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”

6) 7)

Vector Databases

Vector databases store and query embeddings efficiently at scale: 8)

Approximate Nearest Neighbor Algorithms

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)

Applications

Limitations

Best Practices

See Also

References

1)
https://www.elastic.co/what-is/semantic-search|Elastic: What Is Semantic Search
2) , 6) , 10) , 13)