An embedding is a dense float vector, commonly a few hundred to a few thousand dimensions (1024 and 3072 are common), that encodes the meaning of text, an image or code. Nearby vectors mean similar content, measured by cosine similarity.

Embeddings & vector representationsDiagram with these labels, in reading order: Input Data; (text, image, code); Embedding Model; (maps to vector); Vector DB; (stores vectors); Query Vector; (semantic search); Approx. Nearest-Neighbor; (retrieval).Input Data(text, image, code)Embedding Model(maps to vector)Vector DB(stores vectors)Query Vector(semantic search)Approx. Nearest-Neighbor(retrieval)
Embedding process and retrieval flow

From input to nearest neighbors

  1. An embedding model converts the input into a vector.
  2. You store the vectors in a database such as pgvector, Pinecone or Qdrant.
  3. A query is embedded the same way.
  4. An approximate nearest-neighbor search, using an algorithm such as HNSW or IVF, returns the closest stored vectors.

Without embeddings you would rely on keyword matching, which cannot see the meaning behind the words. Storing vectors in a database built for fast retrieval is what makes the search practical.

The model places related inputs near each other, so "dog" and "puppy" get close vectors. A query for "canine" then retrieves "dog", "puppy" and "wolf", all of which sit nearby in the space.

Meaning versus exact terms

A hash table matches exact keys and a full-text index matches words. An embedding matches meaning, so "car" can retrieve "automobile" though the two share no characters. Synonyms and paraphrases that defeat an index are within reach. Because the vectors carry context and intent, retrieval often returns more relevant results for natural-language queries than keyword matching alone.

BM25 and similar keyword methods are strong at finding documents with the exact terms. They miss paraphrases that share no terms with the query.

Hybrid search for IDs, names and rare tokens

Embeddings blur exact matches. For specific IDs, names or rare tokens, keyword search is more precise. Many systems therefore run both: keywords for exact matches and embeddings for intent. Weighting the two by use case works well in practice. The trade-off is that embeddings give richer contextual understanding but can add noise, since they focus on meaning, while keyword search is precise but misses related concepts.

Embeddings are the base of Retrieval-Augmented Generation (RAG) systems and of any feature that needs to find similar items.

Precision and recall Embeddings can blur precision for rare tokens, so hybrid approaches often work better.
TaskBetter fit
Semantic search, RAG retrievalEmbeddings
Deduplication, clustering, recommendationsEmbeddings
Exact IDs, names, rare tokensKeyword search

Example scenario: retrieval success falls to 65%

Suppose retrieval success drops to 65%. One cause is drift in the embedding space: the data distribution changed, or the embedding model was updated while the stored vectors were not.

Embeddings & vector representationsDiagram with these labels, in reading order: Embedding Retrieval; Success Rate; Inadequate Vector Quality; Insufficient Training Data; Cosine Similarity; Threshold; Add Data Augmentation; Improve Model Architecture.Embedding RetrievalSuccess RateInadequate Vector QualityInsufficient Training DataCosine SimilarityThresholdAdd Data AugmentationImprove Model Architecture
Debugging embedding failure
  1. Measure cosine similarity between recent queries and their expected results.
  2. Log the distribution of embeddings over time and look for shifts that line up with the drop.
  3. A/B test the current embedding model against a previous version.

If the embedding model changed, the remedy is to re-embed the stored vectors with the current model. If the data shifted, fine-tune the model on current data. Either costs compute. Monitor retrieval accuracy and drift afterwards.

Back to the knowledge baseRequest an assessment