Quick answer: An embedding is a list of numbers that represents the meaning of a piece of text (or an image). Texts with similar meaning get similar numbers, so a computer can find “related” content by measuring how close two lists are. Embeddings power semantic search, RAG chatbots, recommendations and duplicate detection.
Embeddings in plain English
Computers cannot understand words directly. They understand numbers. An embedding model reads a sentence and turns it into a long list of numbers, called a vector. Each number captures some aspect of meaning. Nobody hand-picks these aspects; the model learns them from huge amounts of text.
Think of a big Indian wedding hall. Guests naturally sit near people they know: college friends at one table, cousins at another, office colleagues somewhere else. If you know where someone is sitting, you can guess who they are related to. Embeddings place every sentence in a giant “hall” with hundreds of dimensions, and sentences with similar meaning end up sitting close together.
So “How do I reset my UPI PIN?” and “I forgot my UPI PIN, what to do?” land very close to each other, even though they share few exact words. “Best biryani in Hyderabad” lands far away.
Why keyword search is not enough
| Search type | Matches on | Finds “car loan” when you type “vehicle finance”? |
|---|---|---|
| Keyword search | Exact words | Usually no |
| Embedding (semantic) search | Meaning | Usually yes |
Keyword search is fast and precise for exact terms like product codes. Semantic search is better when people describe the same idea in different words. Most good production systems combine both, which is called hybrid search.
How similarity is measured
Once two texts are vectors, we compare them with a distance score. The most common is cosine similarity: it looks at the angle between two vectors. A score close to 1 means “very similar meaning”, close to 0 means “unrelated”.
# pip install sentence-transformers
from sentence_transformers import SentenceTransformer, util
model = SentenceTransformer("all-MiniLM-L6-v2") # small, free, runs on a laptop
sentences = [
"How do I reset my UPI PIN?",
"I forgot my UPI PIN, what should I do?",
"Best biryani in Hyderabad",
]
emb = model.encode(sentences)
print(util.cos_sim(emb[0], emb[1])) # high score: same meaning
print(util.cos_sim(emb[0], emb[2])) # low score: different topic
Run this and you will see the first pair score much higher than the second. That single idea is the engine behind semantic search.
Where embeddings are used
- RAG chatbots: your documents are embedded and stored; when a user asks a question, the closest chunks are fetched and given to the LLM. Read our beginner guide to RAG.
- Semantic search on websites, help centres and internal wikis.
- Recommendations: “people who read this also liked…”.
- Duplicate detection: finding repeated support tickets or near-identical questions.
- Clustering: grouping thousands of customer reviews into themes.
Step by step: build a tiny semantic search
- Collect your texts (FAQs, notes, product descriptions).
- Split long documents into chunks of a few paragraphs each.
- Embed every chunk with the same embedding model.
- Store the vectors, either in memory for small projects or in a vector database for larger ones.
- When a query arrives, embed it with the same model.
- Return the chunks with the highest similarity scores.
import numpy as np
docs = ["Refunds are processed in 5-7 working days.",
"You can change your delivery address before dispatch.",
"We accept UPI, cards and net banking."]
doc_emb = model.encode(docs, normalize_embeddings=True)
def search(q, k=2):
q_emb = model.encode([q], normalize_embeddings=True)[0]
scores = doc_emb @ q_emb # cosine similarity (vectors are normalised)
top = np.argsort(-scores)[:k]
return [(docs[i], round(float(scores[i]), 3)) for i in top]
print(search("when will I get my money back?"))
Notice the query never says “refund”, yet the refund sentence comes first. That is meaning-based retrieval.
Choosing an embedding model
- Language: if your users write in Hindi, Tamil or Hinglish, choose a multilingual model and test it on real examples.
- Size vs speed: bigger models are often more accurate but slower and costlier. Small open models are fine for learning and many real apps.
- Hosted vs local: API models need no setup; local models keep data on your machine.
- Consistency: always use the same model for documents and queries. Vectors from different models cannot be compared.
Public leaderboards such as the MTEB benchmark on Hugging Face compare embedding models across tasks. Treat them as a starting point and always test on your own data.
Troubleshooting
- Results feel random: check that queries and documents use the same model, and that chunks are not too long.
- Exact codes or names are missed: add keyword search alongside embeddings (hybrid search).
- Good matches, wrong answers in RAG: the retrieval is fine but the prompt or the LLM needs work; inspect what was retrieved.
- Slow search on large data: move from a Python list to a vector database with approximate nearest-neighbour indexes.
Limits to keep in mind
- Embeddings capture similarity, not truth. A close match can still be outdated or wrong.
- They can carry biases from their training data.
- Changing the embedding model means re-embedding everything.
- Sensitive documents sent to a hosted API leave your system, so check your company policy first.
FAQ
Is an embedding the same as an LLM?
No. An LLM generates text. An embedding model only turns text into vectors. Many RAG apps use both: one to find information, the other to write the answer.
How many numbers are in an embedding?
It depends on the model, commonly a few hundred to a few thousand dimensions. More dimensions are not automatically better.
Do I need a vector database to start?
No. For a few thousand chunks, a NumPy array in memory is enough. Move to a vector database when data or traffic grows.
Can embeddings work for images?
Yes. Multimodal models place images and text in the same space, so you can search photos with a sentence.
Your next step
Run the two code snippets above on your laptop, then read What is RAG? to see how embeddings feed a chatbot, and What is a Large Language Model for the other half of the picture. Preparing for interviews? Try our GenAI interview questions.

