Semantic Search Explained: Embeddings, Indexes and Ranking
Semantic search explained: how embeddings turn text into vectors, how HNSW indexes find neighbours fast, and how hybrid ranking orders the results.
By Galactic News Editorial · Published 2026-11-17T07:29:49+00:00 · Updated 2026-11-17T07:29:49+00:00
Semantic Search Explained: Embeddings, Indexes and Ranking
Semantic search finds results by meaning instead of by exact words. A query about a cheap laptop for students can return a page that never uses the word cheap. The page says affordable instead. Keyword search would miss it. Semantic search does not. This guide explains how it works: embeddings turn text into numbers, indexes make lookup fast, and ranking decides what the user sees first.
Semantic search explained in one paragraph
Semantic search ranks documents by conceptual similarity to a query rather than by literal token overlap. An embedding model maps each piece of text into a vector, a list of numbers, where distance approximates meaning. Search becomes a nearest-neighbour lookup in that vector space. The score for a query and a document is the cosine similarity between their embeddings. Higher scores mean more closely related content. Unlike keyword search, there is no requirement for shared words. That is the whole idea. Everything else is engineering around it.
Embeddings: turning text into numbers
An embedding is a fixed-length numeric vector that represents a chunk of text. Texts with similar meanings produce vectors that sit close together. Models such as BERT and Sentence-BERT create these embeddings. OpenAI's current models are text-embedding-3-small and text-embedding-3-large. The small model produces 1,536-dimension vectors. The large model produces 3,072-dimension vectors. On the MTEB retrieval benchmark, the small model scores 62.3 percent and the large model scores 64.6 percent. The large model costs more per token and stores twice the bytes per vector. On most corpora the recall gain is small. The default choice for a new project is the small model. The query and the documents must be embedded by the same model. Vectors from two different models live in incompatible spaces, and their distances are meaningless.
Chunking: the step everyone underestimates
Before embedding, documents are split into chunks. Chunk sizes between 300 and 800 tokens are common starting points. Structure-aware chunkers split on headings in wikis and on functions in code. Chunks that are too long blur distinct ideas together. Chunks that are too short lose context. Each chunk is embedded separately and stored with its text and metadata. Metadata enables filtering, such as limiting results to one product line or one date range. Good chunking matters more than the choice of embedding model for most small systems.
Indexes: finding neighbours fast
At scale, you never compare a query against every document. You store precomputed embeddings in a vector database and use approximate nearest neighbour indexes for fast lookup. Two common index types are HNSW and IVF. HNSW builds a graph that search traverses in roughly logarithmic time. IVF groups vectors into clusters and checks only the nearest clusters. Both trade a little accuracy for large speed gains. The vector stores most teams use are Pinecone, Qdrant, Weaviate, and Milvus. If you already run Postgres, pgvector adds vectors as a column type and similarity search as a SQL operator. The HNSW index is the default in pgvector 0.7 and later. A vector store is not the same as semantic search itself. Vector search is the mechanism. Semantic search is the goal of matching meaning. Vector search over text embeddings is the usual way to reach it.
Ranking: from similarity to results
First-stage vector search optimises recall across millions of chunks. It returns the top-k nearest candidates, often 50 or 100. Then a reranker reorders that small set for precision. A reranker is a cross-encoder. It reads the query and each candidate together and scores their true relevance. That is far more accurate than comparing two independent embeddings. After reranking, the top results go to the user or to a language model in a RAG pipeline. Retrieval quality caps RAG quality. Generation cannot exceed retrieval quality. Semantic search is the retrieval layer in most RAG systems.
| Approach | How it ranks | Wins on | Misses |
|---|---|---|---|
| Keyword search (BM25) | Exact term matches, rare terms weighted | IDs, SKUs, error codes, rare terms | Synonyms, paraphrases |
| Semantic search | Vector similarity between embeddings | Intent, synonyms, paraphrase | Exact identifiers |
| Hybrid search | Both scores merged, then reranked | Most production queries | Needs more tuning |
Hybrid search runs a keyword query and a vector query side by side and merges the two result lists. BM25 is the default ranking function in Elasticsearch and OpenSearch. Production systems combine both paths because each covers the other's weakness. Keyword search handles exact identifiers. Semantic search handles meaning. A reranker then orders the merged list.
How to build a basic semantic search pipeline
- Split your documents into chunks of 300 to 800 tokens.
- Embed each chunk with one model and store the vectors with text and metadata.
- Build an approximate nearest neighbour index, such as HNSW, over the vectors.
- At query time, embed the query with the same model.
- Retrieve the top candidates by cosine similarity.
- Rerank the candidates with a cross-encoder and return the top results.
Track four metrics once the system runs. Recall at k on a labelled question set. Mean reciprocal rank. Zero-result rate. And downstream answer quality when search feeds RAG generation. If recall is low, fix chunking and the embedding model first. If precision is low, add or improve the reranker.
Bottom line
Semantic search is three parts: embeddings that turn meaning into geometry, an index that finds neighbours fast, and ranking that orders results by relevance. Add keyword search and a reranker, and you have the hybrid pipeline that most production systems run. Start with one embedding model, one vector store, and a small labelled test set. Measure recall before you optimise anything else. And remember the limit. Semantic search retrieves statistically similar text, not guaranteed truth. Validate retrieved content before passing it to a language model.