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:

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

  1. Take a document.
  2. Split a large document into smaller chunks.
  3. Create an embedding for every chunk.
  4. Store the original text and its embedding.

When the user searches

  1. Create an embedding for the user's question.
  2. Compare it with stored embeddings.
  3. 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

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

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.