Embedding Models
Keyword search misses paraphrases ('refund policy' vs 'money back guarantee'). Embeddings capture meaning, not just tokens. The embedding model is the lens through which your entire knowledge base becomes searchable — a weak model means weak retrieval regardless of infrastructure.
Embeddings are like GPS coordinates for meaning. Two restaurants described differently ('Italian bistro downtown' vs 'pasta place near Main St') get nearby coordinates if they mean the same thing.
Visual Workflows
Start here — study each diagram, then use + / − to zoom if needed.
Scroll inside the frame · use + / − to zoom
Key Takeaways
- 1.Embedding models convert text into dense numerical vectors where semantically similar content maps to nearby points in vector space — enabling similarity search as the core retrieval mechanism in RAG.
- 2.Embedding models are transformer encoders trained with contrastive loss (similar pairs close, dissimilar pairs far).
- 3.Key decisions: model choice (OpenAI text-embedding-3-small/large, Cohere embed-v3, BGE, E5), dimensionality (trade storage/latency vs quality), same model for indexing and querying (mandatory), batch size for throughput, and normalization (cosine similarity assumes unit vectors).
- 4.Production: embed at ingestion time (batch, async), cache query embeddings, monitor embedding drift when swapping models (requires full re-index), and consider domain-specific fine-tuned embedders for specialized corpora (medical, legal).
Real Example
Scenario
A support bot uses text-embedding-3-small (1536 dims). 'How do I cancel my subscription?' retrieves chunks about cancellation even when docs say 'terminate your plan' — semantic match that BM25 alone would miss.
What you would do
In RAG Engineering, apply Embedding Models to this scenario: A support bot uses text-embedding-3-small (1536 dims). Identify the inputs, run the technique, validate the output, and note one thing you would monitor in production.
Practice Task
Open the Code Walkthrough below and run it locally. Change one parameter related to Embedding Models (e.g. model, temperature, top_k, or tool name), observe the difference in output, and write 2–3 sentences explaining what changed.
Code Walkthrough
Highlighted lines show where Embedding Models happens in the code.
1from openai import OpenAI # import dependencies2import numpy as np # import dependencies3
4client = OpenAI() # create API client5
6def embed_texts(texts: list[str], model: str = "text-embedding-3-small") -> list[list[float]]: # define a reusable function7 response = client.embeddings.create(input=texts, model=model) # core API call for Embedding Models8 return [item.embedding for item in response.data] # return the result9
10def cosine_similarity(a: list[float], b: list[float]) -> float: # define a reusable function11 a, b = np.array(a), np.array(b)12 return float(np.dot(a, b) / (np.linalg.norm(a) * np.linalg.norm(b))) # return the result13
14query_vec = embed_texts(["refund policy"])[0]15doc_vecs = embed_texts(["money back guarantee", "shipping times"])16scores = [cosine_similarity(query_vec, d) for d in doc_vecs]Cheat Sheet
Quick recap
quick ref- •Index + query = same model
- •text-embedding-3-small = cost-effective default
- •Cosine similarity on normalized vectors
- •Batch embed at ingestion
- •Re-index on model change
- •Matryoshka: lower dims = less storage
Common Mistakes
- ✕Mixing embedding models between index and query
- ✕Not batching embedding requests — kills throughput and inflates cost
- ✕Skipping re-index when upgrading embedding model
- ✕Using oversized models when small ones pass eval thresholds
- ✕Ignoring embedding API rate limits in ingestion pipelines