Semantic search

On this page 7

Semantic search is a retrieval method that finds content by meaning rather than by exact word overlap. It converts both the query and the documents into dense vector embeddings and returns the items whose vectors lie closest to the query vector, so a search for “how to cancel my plan” can match a passage titled “Ending your subscription”.

In retrieval and knowledge systems within artificial intelligence, semantic search is the first-stage retriever behind most question answering, enterprise search and RAG pipelines. It complements rather than replaces lexical search, and the strongest production systems usually combine both approaches before a reranking step.

How semantic search works

A semantic search system runs in two phases: indexing and querying. During indexing, documents are split into passages by chunking, each passage is passed through an embedding model, and the resulting vectors are stored in a vector index together with the original text and metadata.

At query time the same embedding model encodes the user query, and the index returns the top-k nearest neighbors by a similarity measure, most often cosine similarity or dot product. Because exact comparison against millions of vectors is slow, production systems use approximate nearest neighbor (ANN) indexes that trade a small amount of recall for large speed gains.

The table below lists the stages of a typical pipeline and what each contributes.

StageWhat happensTypical choice
ChunkingDocuments split into passages200 to 800 tokens with overlap
EmbeddingText mapped to dense vectorsBi-encoder, 384 to 3,072 dimensions
IndexingVectors stored for fast lookupHNSW or IVF index
RetrievalNearest vectors to the queryTop 20 to 100 candidates
RerankingCandidates rescored preciselyCross-encoder model
FilteringMetadata constraints appliedDate, language, access rights
Stages of a semantic search pipeline

Embeddings, similarity measures and index types

The quality of semantic search depends first on the embedding model. A bi-encoder encodes query and document separately, which allows document vectors to be precomputed. Models are trained with contrastive objectives so that semantically related texts end up close together, and many use asymmetric prefixes that distinguish queries from passages.

The choice of index determines latency, memory use and recall. Vector similarity is usually computed on normalized vectors, in which case cosine similarity and dot product give the same ranking.

Index typeHow it searchesStrengthWeakness
Flat (exact)Compares every vectorPerfect recallSlow beyond about a million vectors
HNSWNavigable small-world graphHigh recall, low latencyHigh memory use
IVFClusters, probes nearest listsScales to large corporaRecall depends on probes
Product quantizationCompressed vector codesSmall memory footprintLower precision
Common vector index types for semantic search

Key tuning parameters include the HNSW ef_search value, often 50 to 500, and the number of IVF probes. Raising them improves recall at the cost of latency, so they should be tuned against a labeled evaluation set rather than guessed.

Semantic search and keyword search fail in opposite and complementary ways. Lexical methods such as BM25 excel at exact identifiers, rare names and error codes, while dense retrieval excels at paraphrases, synonyms and natural-language questions.

AspectKeyword search (BM25)Semantic searchHybrid search
Matching basisShared termsShared meaningBoth signals
Synonyms and paraphrasesMissedHandled wellHandled well
Exact codes and namesHandled wellOften missedHandled well
Out-of-domain vocabularyRobustCan degradeRobust
ExplainabilityHighLowMedium
InfrastructureInverted indexVector indexBoth plus fusion
Keyword, semantic and hybrid retrieval compared

Hybrid systems typically merge the two result lists with reciprocal rank fusion or a weighted score, then pass the best 20 to 100 candidates to a cross-encoder reranker. This layered design usually outperforms either retriever alone, especially on mixed queries such as “refund policy for order 4471”.

Designing and evaluating a semantic search system

Good semantic search is an engineering decision chain rather than a single model choice. The decision table below covers the questions that most often determine success.

SituationRecommended choiceReason
Specialized jargon, legal or medical textDomain-tuned embedding modelGeneral models blur technical terms
Many product codes or IDsHybrid with BM25Dense vectors miss exact tokens
Multilingual contentMultilingual embedding modelCross-language matches in one space
Long documentsSmaller chunks with titles attachedFocused vectors, preserved context
Strict latency budgetHNSW with tuned ef_searchPredictable millisecond lookups
Practical design decisions for semantic search

Evaluation should use a labeled query set drawn from real user traffic. Standard metrics are recall at k, which shows whether the right passage appears in the candidate list, and nDCG or MRR, which reward placing it near the top. A few hundred well-labeled queries already reveal most regressions.

Limitations and common mistakes

Semantic search returns the nearest vectors, not verified answers. There is always a nearest neighbor, even when nothing relevant exists, so systems need relevance thresholds or a reranker that can reject weak candidates.

  • Mixing embedding models: query and document vectors must come from the same model and version, or similarities become meaningless.
  • Ignoring negation and numbers: embeddings often place “with sugar” and “without sugar” close together.
  • Poor chunking: passages that cut a table or definition in half produce vectors that match nothing well.
  • Skipping access control: filtering must apply before results reach the user, not after generation.
  • Stale indexes: changed documents need re-embedding, and model upgrades require a full re-index.

The short version

Ordinary search looks for the same words you typed. Semantic search tries to understand what you mean and finds text that says the same thing in different words.

It works a little like a librarian who knows that a question about “fixing a flat tire” belongs next to a guide on “repairing a punctured bicycle wheel”, even though the two share almost no words. The system places similar ideas near each other on a map and then looks for the closest neighbors to your question.

Where it makes a difference

An internal support team at a software company maintains about 12,000 help articles. Agents complain that keyword search fails when customers describe problems in their own words, such as “the app forgets me every morning” for a session timeout issue.

The team chunks the articles into passages of roughly 400 tokens, embeds them with a multilingual model, and builds a hybrid search combining BM25 and vectors with a cross-encoder reranker on the top 50 results. They evaluate the setup on 300 real tickets with known correct articles.

Recall at 10 rises clearly compared with keyword search alone, while queries containing exact error codes keep working through the lexical side. Agents find the right article faster, and the same index later becomes the retrieval layer of an internal assistant.