Semantic search
Definition
Search that ranks results by how close their meaning is to the query rather than by shared keywords, usually by comparing embeddings.
In more detail
The query and every document are turned into embeddings by the same model, and the documents whose vectors sit closest to the query vector come back first. A search for "how do neural networks learn" can then find a passage about backpropagation that never uses the word "learn", and synonyms, abbreviations and small misspellings are handled the same way.
It is weaker at exact matches: product codes, error messages and rare names often do better with keyword search such as BM25. That is why many RAG systems use hybrid search, running both and merging the results.
Related terms
BM25
A classic keyword relevance function that scores documents by term frequency and rarity, adjusted for document length. Still a strong baseline.
Embedding
A vector representation of text or other data that places items with similar meaning close together, so they can be searched by similarity.
Hybrid search
Combining keyword search, such as BM25, with vector search and merging the results into one ranking, often with reciprocal rank fusion.
Reranking
Re-scoring an initial set of retrieved results with a slower, more accurate model before passing only the best few on to the LLM.
Vector database
A database designed to store embeddings and quickly find the nearest neighbours to a query vector, often with metadata filtering.
Read more about Semantic search
- Embeddings and vector search, hands on
Embed documents, store them in Postgres with pgvector, index them and run similarity and hybrid search.
- Embeddings and vector search
Turning text into vectors to find similar items, alone or with keywords.
- Hybrid search and reranking in Postgres
Combine Postgres full-text search and pgvector with reciprocal rank fusion in one SQL query, rerank the top results with a cross-encoder, and measure the gain.