An embedding is a list of numbers that represents the meaning of text, an image, or other data.
It allows a computer to compare information by meaning, not just by matching exact words.
Why are embeddings needed?
Suppose a company policy says:
Employees can work remotely during severe weather.
A user searches:
Can I work from home during heavy rain?
The wording is different:
- work remotely vs work from home
- severe weather vs heavy rain
A basic keyword search may miss the connection. Embeddings help the system understand that both sentences have similar meanings.
Embeddings help computers answer: "Which pieces of information mean something similar?"
What exactly is an embedding?
An embedding model converts text into a fixed-length vector, which is an array of numbers.
"How do I reset my password?"
↓
[0.018, -0.421, 0.735, 0.106, ...]
A real vector may contain hundreds or thousands of numbers.
You do not normally interpret each number separately. The complete pattern represents the meaning of the input.
The main idea: similar meaning, nearby vectors
"Reset my password"
"I forgot my login password"
These sentences have different words but similar meanings, so their embeddings should be close together.
"Reset my password"
"Which helmet should I buy?"
These meanings are unrelated, so their embeddings should be far apart.
flowchart LR
A["Text or document"] --> B["Embedding model"]
B --> C["Numeric vector"]
C --> D["Compare with other vectors"]
D --> E["Find similar meaning"]
How semantic search works
When storing documents
- Take a document.
- Split a large document into smaller chunks.
- Create an embedding for every chunk.
- Store the original text and its embedding.
When the user searches
- Create an embedding for the user's question.
- Compare it with stored embeddings.
- Return the closest matches.
Clear example
Stored documents:
A: Employees may work remotely during severe weather.
B: Passwords must contain at least eight characters.
C: Annual leave requires manager approval.
User asks:
Can I work from home during a red rain alert?
Illustrative similarity results:
| Document | Similarity |
| A: Remote work during severe weather | High |
| C: Annual leave approval | Medium or low |
| B: Password rules | Very low |
The system returns Document A even though the query does not use the exact words remote work or severe weather.
This is called semantic search.
Keyword search vs embedding search
| Keyword search | Embedding search |
| Matches exact words | Matches similar meaning |
| Good for IDs, names, and exact phrases | Good for natural-language questions |
| May miss synonyms | Can recognize related words and concepts |
Many applications combine both approaches. This is called hybrid search.
How embeddings are used in RAG
Embeddings commonly help an AI find relevant documents before answering.
User question
↓
Create question embedding
↓
Find similar document embeddings
↓
Send matching documents to the LLM
↓
Generate an answer using those documents
The embedding does not generate the answer. It only helps retrieve the right information.
The LLM reads the retrieved information and writes the final response.
Simplified backend example
// Create and store a document embedding
const vector = await embeddingModel.embed(
"Employees can work remotely during severe weather."
);
await documents.insert({
text: "Employees can work remotely during severe weather.",
embedding: vector
});
When a user searches:
const queryVector = await embeddingModel.embed(
"Can I work from home during heavy rain?"
);
const matches = await documents.findNearest(queryVector);
The actual methods depend on the AI provider and database.
Important things to remember
- Use the same embedding model for documents and search queries.
- Store the original text along with its embedding.
- Split large documents into meaningful chunks.
- Regenerate an embedding when its original content changes.
- Your backend must still enforce user permissions.
- An embedding represents similarity; it does not prove that information is correct.
- Embeddings are not encryption and should not be treated as anonymous data.
Embedding model vs LLM
| Embedding model | Generative LLM |
| Produces a numeric vector | Produces text |
| Finds similar information | Writes answers and content |
| Used for search and retrieval | Used for generation and reasoning |
Common use cases
- semantic search
- retrieving documents for RAG
- recommendations
- finding duplicate support tickets
- matching questions with FAQ entries
- grouping similar content
Final mental model
Embedding model: converts meaning into numbers. Vector search: finds nearby meanings. LLM: uses the retrieved information to generate an answer.
Interview answer
An embedding is a numerical vector that represents the semantic meaning of data such as text. Similar meanings produce nearby vectors, allowing applications to perform semantic search and retrieve relevant information for systems such as RAG. Embeddings help find information; they do not generate the final answer.