Text Embeddings
Embedding models map text to vectors so that similar meanings land close together, powering semantic search, clustering and RAG.
Beginner · about 4 hours · difficulty 2/5
Learn first: Messages APIs and Provider SDKs, Transformers and Attention, Intuitively
An embedding is a list of numbers (a vector, often hundreds to a few thousand dimensions) that represents the meaning of a piece of text. Texts about similar things produce vectors that point in similar directions, even with no shared words: "reset my password" lands near "I cannot log in".
Where embeddings are used
- Semantic search and the retrieval step of RAG.
- Clustering and deduplication of feedback, tickets or documents.
- Classification with a small classifier on top, or nearest-neighbour labelling.
- Recommendations and "similar items".
Choosing an embedding model
- Hosted options come from OpenAI, Google, Cohere, Voyage and others; open models (for example from the sentence-transformers ecosystem, BGE, E5, Nomic families) run locally.
- Compare on the MTEB leaderboard, but test on your own data and language.
- Consider dimensions (storage cost), max input length, multilingual support and price.
Rules to remember
- Queries and documents must be embedded with the same model. Switching models means re-embedding everything.
- Some models expect different prefixes or task types for queries versus documents; read the model card.
- Embeddings capture topic similarity, not truth or exact matches. Product codes and names are often better handled by keyword search.
Good enough to move on
You can embed a set of texts, find the nearest neighbours of a query, and explain why a keyword search would have missed some of the results.
Key concepts
- What an embedding vector represents
- Hosted embedding APIs
- sentence-transformers and open models
- MTEB leaderboard
- Query vs document embeddings
- Dimensions and storage cost
- Clustering and visualization
Mini project
Embed 500 short texts (for example job titles or FAQ questions), build a tiny semantic search CLI with numpy, and plot clusters with a 2D projection.
Check yourself
You upgraded your embedding model but only re-embedded new documents. What breaks and why?
Free resources
- Sentence Transformers documentation (SBERT)
- MTEB leaderboard (Hugging Face)
- OpenAI docs: embeddings (OpenAI)