What is an embedding? An embedding is a list of numbers, called a vector, that represents the meaning of an item such as a word, sentence, document, image, product or user in a way that machines can compare. Items with similar meaning end up close together in this numeric space, so a search for refund policy can find a page about returns even when the words differ. Embeddings power semantic search, recommendation, clustering, retrieval augmented generation and many other AI features. This guide explains how embeddings work, how similarity is measured, how they are stored and searched, practical use cases and the design choices that decide quality and cost.
Short answer: An embedding turns content into a vector so that similar meanings are near each other. You compare vectors with measures such as cosine similarity to find related items, which makes semantic search and recommendations possible.
What is an embedding?
The word embedding article on Wikipedia describes the technique of mapping words to vectors of real numbers. Modern embedding models are neural networks trained with deep learning and often come from a large language model family. Vectors are stored in a vector database and are the backbone of RAG.
How embeddings work

- Input: text, image, audio, code or structured data is prepared and, for long text, split into chunks.
- Encode: an embedding model converts each piece into a fixed length vector, often hundreds or thousands of numbers.
- Store: vectors are saved with their source text and metadata in a vector index.
- Query: the user query is embedded with the same model.
- Search: the system finds the nearest vectors using a similarity measure.
- Return: matching items are ranked and shown, or passed to a language model as context.
Measuring similarity
| Measure | What it compares | Notes |
|---|---|---|
| Cosine similarity | Angle between vectors | Most common for text |
| Dot product | Angle and magnitude | Used when vectors are normalised or magnitude matters |
| Euclidean distance | Straight line distance | Common in clustering |
| Approximate nearest neighbour (HNSW, IVF) | Fast search over millions of vectors | Trades tiny accuracy loss for speed |
Types of embeddings
| Type | Represents | Typical use |
|---|---|---|
| Word embeddings | Single words | Early NLP, analogy tasks |
| Sentence and document embeddings | Whole passages | Semantic search, RAG |
| Image embeddings | Pictures | Visual search, deduplication |
| Multimodal embeddings | Text and images in one space | Search images with text |
| Code embeddings | Source code | Code search and assistants |
| User and item embeddings | Behaviour patterns | Recommendation. See what is a recommendation engine |
Common use cases
- Semantic search that matches meaning rather than keywords.
- RAG, where relevant passages are retrieved to ground model answers.
- Recommendations based on similar items or users.
- Clustering and topic discovery in tickets, reviews or documents.
- Duplicate and near duplicate detection.
- Anomaly detection and classification with simple models on top of vectors.
Design choices that decide quality
- Choose the model. Match language, domain, context length, dimension size and cost to your content.
- Chunk content well. Split by meaning, keep overlap and include titles so chunks stand alone.
- Keep metadata. Store source, date, permissions and type for filtering.
- Combine with keyword search. Hybrid retrieval handles names, codes and exact terms better than vectors alone.
- Evaluate retrieval. Use test questions and measure whether the right passages are returned.
- Plan updates. Re-embed when content or the model changes, and version your index.
Pitfalls to avoid
- Mixing vectors from different models in one index.
- Chunks that are too large or too small.
- Ignoring access control, so users retrieve documents they cannot see.
- Assuming nearest means correct: similar text is not always relevant.
- Embedding sensitive data without considering where vectors are stored.
- No evaluation, so quality problems go unseen.
Our AI and machine learning service designs retrieval and embedding pipelines, and our data analytics service prepares the content behind them.
A worked example: semantic search for a knowledge base
A support team has twelve thousand help pages, and keyword search fails when customers use different words, such as cancel my plan instead of terminate subscription. The team splits each page into sections of a few hundred words, adds the page title to each chunk and embeds them. Vectors and metadata, including product and language, are stored in a vector index.
At query time the question is embedded, filtered by product and permissions and matched against the index, then combined with keyword scores for exact terms. A test set of five hundred real questions shows the right page in the top three results for 91 percent of queries, compared with 68 percent for keyword search. The same index later feeds a chatbot with cited sources.
Cost, scale and maintenance
Embedding costs come from generating vectors, storing them and searching them. Higher dimension vectors improve nuance but increase storage and latency, and many models allow truncated dimensions with small quality loss. Approximate nearest neighbour indexes keep searches fast at millions of items. Budget for re-embedding when you change models, and automate updates so new and edited content appears in search within minutes rather than weeks.
Security and privacy of embeddings
Vectors can leak information about the content they represent, so treat them as sensitive as the source. Enforce document level permissions at query time, encrypt stores, control who can run searches and keep audit logs. Consider where embedding is performed, because sending text to an external service moves data outside your boundary. For regulated data, use approved models and regions and apply retention rules to vectors as well as to source documents.
Embeddings versus keyword search versus fine-tuning
| Need | Best fit | Why |
|---|---|---|
| Exact codes, names, SKUs | Keyword search | Exact match matters |
| Meaning based discovery | Embeddings | Finds related wording |
| Best of both | Hybrid search | Combines recall and precision |
| New facts for an AI answer | Embeddings with RAG | Retrieval grounds responses. See what is fine-tuning |
| Specialised style or behaviour | Fine-tuning | Learned behaviour, not retrieval |
These approaches work together. Many production systems use embeddings for recall, keyword filters for precision, a re-ranking model to order the final list and a language model to compose the answer from the top results with citations.
Evaluating retrieval quality
Build a test set of real questions with known correct passages and measure how often the right passage appears in the top results. Review failures by hand: they usually point to poor chunking, missing metadata or content gaps, not to the embedding model itself. Repeat the evaluation whenever you change models, chunk sizes or ranking logic, and keep a baseline so improvements are measurable.
Choosing chunk size and overlap
Chunk size is one of the most influential settings. Very small chunks lose context and return fragments, while very large chunks blur several topics into one vector and waste space in a language model prompt. A practical starting point is a few hundred words per chunk with modest overlap, split along headings and paragraphs. Include the document title and section heading in each chunk so it makes sense alone. Test two or three sizes against your question set and keep the one that retrieves the right passages most often.
Key takeaways
- An embedding is a vector that captures meaning so similar items are close together.
- Cosine similarity and approximate nearest neighbour search find related content quickly.
- Embeddings power semantic search, RAG, recommendations and clustering.
- Quality depends on model choice, chunking, metadata, hybrid search and evaluation.
- Protect vectors and enforce permissions like any sensitive data.
Quick glossary
| Term | Meaning |
|---|---|
| Embedding | A numeric vector representing meaning |
| Cosine similarity | A measure of the angle between two vectors |
| Chunking | Splitting content into passages for embedding |
| Hybrid search | Combining keyword and vector retrieval |
| ANN | Approximate nearest neighbour search |
Read next: What Is Fine-Tuning? Methods, Data and Costs · What Is Feature Engineering? Techniques and Workflow · What Is Explainable AI? Methods, SHAP and LIME
Frequently asked questions
What is an embedding in simple terms?
It is a list of numbers that represents the meaning of text, an image or another item, so that similar items sit close together and can be compared.
How are embeddings used in search?
The query and documents are both embedded, and the system returns the documents whose vectors are closest to the query vector.
What is cosine similarity?
It measures the angle between two vectors. A value near one means very similar direction and therefore similar meaning.
What is the difference between embeddings and keywords?
Keywords match exact words. Embeddings match meaning, so they find relevant content even when different words are used.
Do I need a vector database?
For small collections a simple index works, but a vector database or vector enabled database helps with scale, filtering and updates.
How do embeddings relate to RAG?
RAG uses embeddings to retrieve relevant passages, which are then supplied to a language model to ground its answer.
Can I mix embedding models?
Not in one index. Vectors from different models are not comparable, so re-embed everything when you change models.
Are embeddings secure?
They can reveal information about the source content, so apply the same access control, encryption and retention rules as for the original data.
