What is semantic search?

Build agents
HoneyHive Engineering

Semantic search finds results by meaning instead of shared words. How embedding retrieval works, where it misses, and how to check it.

Semantic search retrieves results by meaning instead of by shared words. In an example from the Sentence Transformers docs, the query “How to learn Python online?” should find the entry “How to learn Python on the web?”, which shares few of its words. It is the retrieval step behind most RAG pipelines.

Sentence Transformers puts it this way: semantic search seeks to improve search accuracy by understanding the meaning of the query, and it can handle synonyms, abbreviations and misspellings. The catch is that meaning is approximated by a model, and that model can be wrong in ways keyword matching never is.

How it works

index time:  document -> embed -> vector index
query time:  query -> embed -> nearest vectors -> results

An embedding is, in OpenAI’s words, a vector of floating point numbers, and the distance between two vectors measures how related they are. OpenAI recommends cosine similarity. The Sentence Transformers docs describe the loop: embed every entry in the corpus once, embed the query into the same vector space at search time, and return the closest embeddings.

Two practical points follow from that.

  • Long documents are split first, because one vector per large page blurs its topics. See chunking strategies.
  • The model has to fit the task. The same docs call choosing the right model critical and separate symmetric tasks, where query and entries look alike, from asymmetric ones, where a short question retrieves a longer passage. Most question answering is asymmetric.

Semantic search is also cheap to run at query time because the documents are embedded ahead of time. Reimers and Gurevych estimated that finding the most similar pair among 10,000 sentences takes about 65 hours when a BERT model must compare every pair, and about 5 seconds with sentence embeddings. For comparing the vectors themselves, see semantic similarity.

Keyword (BM25) Semantic (dense embeddings)
Matches on Shared terms Closeness in vector space
Handles synonyms and rephrasing Poorly Well
Exact names, codes, rare terms Well Can miss
Needs an embedding model No Yes
Indexing cost Tokenize each document One embedding model call per document

Anthropic wrote in September 2024 that embedding models “excel at capturing semantic relationships” but “can miss crucial exact matches”, so product names, error codes and identifiers are the usual failure cases.

What the evidence says

The BEIR authors tested retrieval models on 18 datasets. They reported that BM25 is a robust baseline, that re-ranking and late-interaction models achieved the best zero-shot results on average at high computational cost, and that dense and sparse retrieval models are more efficient but often underperform other approaches. That was 2021, and models have improved, so it supports one habit more than any ranking: keep a keyword baseline and measure against it.

Combining methods is the common fix. Anthropic’s post describes running embeddings and BM25 together and merging the results with rank fusion. On its test set, the top-20 retrieval failure rate fell 49 percent with contextual embeddings plus contextual BM25 and 67 percent after adding a reranker, against a 5.7 percent baseline failure rate. Those figures come from Anthropic’s own data and a technique that adds context to each chunk, so they show direction, not what you will get.

The Sentence Transformers docs advise a two-stage retrieve and re-rank pipeline for complex cases. Their retrieve and re-rank guide describes a first stage that pulls a large candidate list, for example 100 hits, with lexical search or a bi-encoder, then a cross-encoder that scores each candidate’s relevance to the query.

Where it fails

  • Exact terms, as above.
  • Chunks that lost their context. Anthropic’s example is a chunk that says “The company’s revenue grew by 3% over the previous quarter” without naming the company or the period.
  • A model mismatch, such as one trained for symmetric similarity used for question-to-passage retrieval.
  • Wrong results that look plausible, since nearest-neighbor search always returns something.

The last one matters for agents. A retriever that returns the nearest vectors with no relevance check passes bad context to the model, which then answers from it.

How to check it

Evaluate retrieval on its own before judging the final answer: build queries with known relevant documents, and compare keyword, semantic and hybrid retrieval on the same set. Context precision and recall and RAG evaluation cover the metrics. If a semantic cache sits in front of the model, it uses the same embedding idea; see semantic caching.

To see what the retriever returned for a production query, trace the retrieval step so each query, its results and their scores are recorded. HoneyHive’s experiments reference covers running and comparing evaluation runs when you change the embedding model, chunking or retrieval settings.

FAQ

What is semantic search?

Search that matches the meaning of a query instead of its exact words. Sentence Transformers describes it as embedding the whole corpus, embedding the query into the same vector space at search time, and returning the closest entries.

How is semantic search different from keyword search?

Keyword search scores documents on the terms they share with the query, as BM25 does. Semantic search compares embedding vectors, so it can match synonyms and rephrasings, but Anthropic notes embedding models can miss crucial exact matches.

Is semantic search better than BM25?

Not by default. The BEIR benchmark authors found in 2021 that BM25 was a robust baseline on zero-shot tests, with dense retrieval models often underperforming other approaches. Models have improved since, so test both on your own queries.

Do I need a vector database for semantic search?

You need some way to find the nearest vectors. The Sentence Transformers docs show the basic version as embedding the corpus and comparing the query embedding with it. A dedicated index matters once the corpus is large.

How do I evaluate semantic search?

Score retrieval on its own, before the model answers, using labeled queries. See RAG evaluation and context precision and recall.

Share