Computers are brilliant with numbers and clueless about meaning. To a plain computer, "car" and "automobile" are just two different strings of letters with nothing in common. Yet when you search "cheap phone under 15000" on a shopping app, the results somehow include listings titled "budget smartphone". Something understood that those mean nearly the same thing.
That something is usually an embedding. An embedding turns a piece of content into a list of numbers chosen so that similar meanings end up close together. Once meaning becomes numbers, a computer can measure it, compare it and search it.
When I teach embeddings, students often expect heavy maths. The core idea is closer to geography than to calculus. If you can read a map of India and see that Pune is close to Mumbai and far from Guwahati, you already understand how embeddings work. By the end of this page you will know what embeddings are, how similarity is measured, where embeddings are used, and how to create your own with an embedding model.
What are embeddings in AI? (meaning in simple words)
Embeddings are numerical representations of data, usually long lists of numbers called vectors, that capture meaning so that related items have similar numbers.
Break the idea into three parts:
- Input: almost anything. A word, a sentence, a whole paragraph, a product description, an image or even a song.
- Output: a fixed-length list of numbers, for example a list of several hundred or a few thousand decimals. The exact length depends on the model you use.
- The rule: inputs with similar meaning produce lists that are close to each other, and unrelated inputs produce lists that are far apart.
You will also hear the term vector embeddings. It means the same thing. "Vector" is simply the maths word for an ordered list of numbers, and "embedding" describes the act of placing data into that number space.
The individual numbers are not meant to be read by humans. No single number means "sportiness" or "price". The meaning lives in the pattern across all of them, and especially in how one embedding relates to another.
Embeddings as a map of meaning: the India map analogy
The easiest way to understand embeddings is to picture a map where every idea has coordinates, and nearby ideas mean similar things.
Start with a real map of India. Every city has two numbers: latitude and longitude. Mumbai and Pune have similar coordinates, so they appear close together. Delhi and Gurugram are neighbours too. Chennai and Srinagar are far apart. With just two numbers per city, you can answer questions like "which cities are closest to Bengaluru?" without knowing anything else about them.
Now imagine a map of meaning instead of geography:
- "cricket", "IPL", "bat" and "wicket" sit in one neighbourhood.
- "biryani", "pulao" and "khichdi" sit in another.
- "doctor", "hospital" and "nurse" form a third cluster.
- "cricket" and "biryani" are far apart, although they might be closer to each other than to "quantum physics", because both show up often in conversations about weekends.
A real embedding model does the same thing, but with hundreds or thousands of coordinates instead of two. Humans cannot picture that many dimensions, and that is fine. The maths of distance works exactly the same way, and the extra dimensions let the model capture many shades of meaning at once: topic, tone, formality, language and more.
I like the map analogy because it sets the right expectation. A map tells you what is near what. It does not tell you why. Embeddings work the same way.
What is embedding in AI with example?
A simple example of embedding is turning three sentences into vectors and noticing that the two sentences with similar meaning get similar numbers.
Take these three sentences:
- "How do I reset my UPI PIN?"
- "I forgot my UPI PIN, how can I change it?"
- "Best places to visit in Goa in December"
An embedding model turns each one into a vector. Real vectors are long, so here is a toy version with only four numbers each, made up purely to show the idea:
Sentence 1: [0.82, 0.11, 0.64, 0.05] Sentence 2: [0.79, 0.15, 0.60, 0.08] Sentence 3: [0.03, 0.91, 0.07, 0.72]
Sentences 1 and 2 share almost no exact words beyond "UPI PIN", yet their numbers are nearly the same because their meaning is nearly the same. Sentence 3 lands far away. A bank's help chatbot can use this to match a user's messy question to the right help article, even when the wording differs.
The classic "king minus man plus woman" example
The most famous illustration comes from word2vec, a word embedding method published by Tomas Mikolov and colleagues at Google in 2013. Researchers showed that simple arithmetic on word vectors could capture relationships. Take the vector for "king", subtract "man", add "woman", and the closest word vector is often "queen".
Treat this as a classic teaching example, not a rule. It works for some well-known word pairs and fails for many others. What it shows is that directions in the embedding space can carry meaning, such as a rough "male to female" direction.
Word embeddings vs sentence embeddings: what is the difference?
Word embeddings give one vector per word, while sentence or document embeddings give one vector for a whole piece of text, taking context into account.
Early methods like word2vec (2013) and GloVe (from Stanford, 2014) created word embeddings. Each word got one fixed vector, learned from which words tend to appear near it in huge amounts of text. That idea, "you know a word by the company it keeps", is the foundation of everything that came later.
But fixed word vectors have a weakness. The word "bank" gets one vector, whether you mean a river bank or SBI. Modern embedding models are built on the transformer architecture, which reads the whole sentence and produces representations that depend on context. "I deposited cash at the bank" and "we sat on the river bank" end up in different places.
| Word embeddings | Sentence and document embeddings | |
|---|---|---|
| Unit | One word | A sentence, paragraph or document |
| Context-aware? | No, one vector per word | Yes, meaning depends on surrounding words |
| Classic examples | word2vec, GloVe | Modern transformer-based embedding models |
| Typical use today | Teaching, older NLP systems | Semantic search, RAG, recommendations, clustering |
For almost any project you build today, you will use sentence or document embeddings from a modern embedding model. Word embeddings are still worth learning, because they make the core idea easy to see.
How do embeddings measure similarity? Distance and cosine similarity
Embeddings measure similarity by checking how close two vectors are, most often using a score called cosine similarity, which compares the direction in which two vectors point.
Go back to the map. The simplest way to compare two cities is straight-line distance: the shorter the distance, the more similar. That works for embeddings too, and it is called Euclidean distance.
Cosine similarity takes a slightly different view. Imagine every embedding as an arrow starting from the centre of the map. Instead of asking "how far apart are the tips?", cosine similarity asks "are these arrows pointing the same way?"
- Arrows pointing the same direction give a score close to 1: very similar meaning.
- Arrows at a right angle give a score near 0: unrelated.
- Arrows pointing in opposite directions give a score near minus 1.
In practice, with most text embedding models, scores for related texts sit noticeably higher than scores for unrelated ones, but the exact numbers vary from model to model. Never assume a fixed cut-off like "anything above 0.8 is a match". Test with your own data and pick a threshold that works.
You do not need to compute any of this by hand. Libraries and vector databases do it for you in milliseconds, even across millions of vectors.
How does an embedding model create vectors?
An embedding model is a neural network trained so that related inputs produce nearby vectors and unrelated inputs produce distant ones.
At a high level, creating a text embedding works like this:
- Tokenise. The text is split into tokens, small pieces of words, and each token becomes an ID number.
- Process. A neural network, usually a transformer, reads all the tokens together and builds an internal representation of each one in context.
- Pool. The model combines those internal representations into one fixed-length vector for the whole input.
- Output. You get back a list of numbers, the same length every time, no matter how long or short the input was (within the model's input limit).
How does the model learn where to put things? During training, it sees huge numbers of examples, often pairs of texts that should be close (a question and its answer, a title and its article) and pairs that should be far apart. Training nudges the network until related pairs land near each other. Nobody hand-codes "cricket goes near IPL". The model learns it from data.
Embedding models are related to chat models like ChatGPT, but they are not the same thing. A chat LLM produces text. An embedding model produces vectors. Many AI products use both: the embedding model finds relevant information, and the LLM writes the answer.
Where are embeddings used? Search, recommendations, RAG and more
Embeddings are used anywhere a system needs to find, group or compare things by meaning rather than by exact words.
The most common uses:
- Semantic search. Searching "phone that lasts all day" finds products described as "5000 mAh battery" even though the words do not match.
- Recommendations. Shows, songs or courses get embeddings, and you are shown items close to the ones you liked. If you watched three videos on Python basics, nearby items might be beginner data science videos.
- RAG (Retrieval-Augmented Generation). Documents are embedded so an AI can find the right passages before answering. More on this in the next section.
- Duplicate detection. A support team can spot that "app crashes on login" and "cannot sign in, app closes" are the same complaint. Q&A forums use similar ideas to flag repeat questions.
- Clustering. Group thousands of customer reviews into themes like delivery, pricing and quality without reading each one.
- Classification. Use embeddings as input features to sort emails, tickets or messages into categories.
- Multilingual matching. Many multilingual embedding models place a Hindi sentence and its English translation near each other, which helps apps serve users across languages.
- Images and audio. Some models embed images and text into the same space, which is how you can search a photo gallery by typing "dog on a beach". Image generation tools also rely on text embeddings to connect your prompt to the picture they produce.
In my view, embeddings are the most underrated idea in modern AI. Chatbots get the headlines, but embeddings quietly run the search, matching and recommendation systems behind many apps you open every day.
Embeddings in RAG: how they power retrieval
In RAG, embeddings are what let the system find the passages that match a question by meaning, so the AI can answer from your documents.
Here is where they fit in a RAG pipeline:
- Your documents are split into chunks, such as a few paragraphs each.
- Every chunk is turned into an embedding and stored, usually in a vector database.
- When a user asks a question, the question is embedded with the same model.
- The system finds the chunks whose embeddings are closest to the question's embedding.
- Those chunks are added to the prompt, and the LLM writes an answer from them.
Say an HR policy bot holds the company handbook. An employee asks, "Can I take leave for my sister's wedding?" The handbook never uses the word "wedding". It has a section called "Casual and personal leave". Keyword search might miss it, but a good embedding places the question and that section close together, so the right chunk comes back.
The quality of your embeddings sets a ceiling on the quality of your RAG system. If retrieval brings back the wrong chunks, even the best LLM will answer from the wrong information.
How to create embeddings with an embedding model
You create embeddings by sending your text to an embedding model, either through a hosted API or an open-source model running on your own machine, and storing the vectors it returns.
Option 1: Hosted embedding APIs
Major AI providers, including OpenAI and Google, offer embedding models through their APIs. You send text, you get back a vector, and you pay a small amount per token processed. Model names, vector sizes and prices change over time, so check each provider's current documentation before you choose.
Option 2: Open-source models
Libraries such as sentence-transformers in Python let you download an open embedding model and run it locally, often free and even on a laptop for small datasets. Open models are a great choice for students and for data that should not leave your machine.
A beginner workflow, in rough pseudo-code:
model = load_embedding_model("some-embedding-model")
texts = ["How do I reset my UPI PIN?", "Best places to visit in Goa"]
vectors = model.embed(texts)
score = cosine_similarity(vectors[0], vectors[1])
print(score)Three rules that save hours of confusion:
- Use the same model for your documents and your queries. Vectors from two different models live on different maps and cannot be compared.
- Re-embed everything if you switch models.
- Test on your own data. A model that tops a public leaderboard may not be the best for Hinglish customer chats.
Common embedding mistakes beginners make
The most common embedding mistakes come from expecting embeddings to understand more than they do.
Here is my contrarian take: embeddings do not "understand" meaning the way people do. They capture patterns of how words and ideas are used together. Usually that is close enough to meaning to be useful, but not always. A sentence and its negation, such as "this medicine is safe for children" and "this medicine is not safe for children", can sit surprisingly close together, because they discuss the same topic in almost the same words.
Other mistakes to avoid:
- Mixing models. Comparing a vector from one model with a vector from another gives meaningless scores.
- Embedding huge chunks. A whole 40-page PDF squeezed into one vector blurs all its topics together. Smaller, focused chunks search better.
- Ignoring exact matches. Embeddings can be weak at exact codes, roll numbers or product IDs. Combining keyword search with embedding search (hybrid search) often works better.
- Fixed thresholds. Copying a similarity cut-off from a tutorial instead of testing on your own data.
- Forgetting updates. When documents change, their embeddings must be regenerated too.
If you can explain these trade-offs clearly, you are already ahead of most beginners, and this exact topic shows up often in AI engineering interviews. Our AI interview prep section has questions on embeddings and RAG to practise with.
Key takeaways
- Embeddings are lists of numbers (vectors) that capture meaning, so similar items get similar numbers.
- Think of them as coordinates on a map of meaning, just with hundreds or thousands of dimensions instead of two.
- Similarity is usually measured with cosine similarity, which checks whether two vectors point the same way.
- Modern embedding models are context-aware, unlike early word embeddings such as word2vec and GloVe.
- Embeddings power semantic search, recommendations, RAG, duplicate detection and clustering.
- Always use the same embedding model for documents and queries, and test on your own data.