LLMS & GENERATIVE AI · QUESTION 14
What are embeddings, and how are they used in AI applications?
On this page
An embedding is a list of numbers that represents an item—such as text, an image, or a product—in a space where useful similarities can be measured. An embedding model maps related items to nearby vectors, which makes semantic search and recommendations possible even when wording differs. Similarity is only a signal: quality depends on the model, the data, and how the application interprets results.
LET'S MAKE IT SIMPLE
First, the idea in plain English
Computers need a numerical representation to compare things. An embedding model turns an item into a vector, a sequence of numbers. The model is trained so that items related in a useful way tend to have similar vectors. A search application can embed both a query and its documents, then find nearby document vectors. This can match meaning rather than just exact words, but the result still needs to fit the task.
A USEFUL COMPARISON
Picture it this way
Imagine a map where nearby neighborhoods share useful characteristics. An embedding space is like that map, except its dimensions are learned numeric features and cannot usually be labeled as simple human concepts. Nearby points suggest similarity under the model’s training objective; they do not prove that two items are interchangeable.
FOLLOW THE JOURNEY
From content to a searchable vector space
See how text and a query become vectors that can be compared for semantic retrieval.
The embedding is a search representation, not the document itself. A useful system keeps the original text, metadata, and permissions alongside vectors.
Documents and a query are encoded into vectors; a similarity search ranks nearby document vectors, and the application returns selected source text.
How to read this visual
The embedding is a search representation, not the document itself. A useful system keeps the original text, metadata, and permissions alongside vectors.
UNDER THE HOOD
How it works, step by step
Prepare items
Choose meaningful text or other items and preserve their source metadata.
Why it matters: Poorly prepared or context-free items produce weak retrieval results.
Encode consistently
Use an embedding model to map each item and later queries into vectors.
Why it matters: The vectors must come from compatible models and preprocessing.
Measure similarity
Use an index and a distance or similarity function to find candidates.
Why it matters: This replaces exact string matching with a learned semantic signal.
Rerank and use results
Apply filters or a reranker, then show or pass the original content to the next step.
Why it matters: Nearest neighbors are candidates, not automatically correct answers.
OUTSIDE THE TEXTBOOK
A practical example
A help center embeds each article paragraph and stores its title, URL, and access scope. When someone asks “How do I get my money back?”, the system embeds the question and retrieves passages about refunds even if the articles use “reimbursement.” It should still rank evidence, respect permissions, and show the source rather than treating similarity as proof.
GO A LITTLE DEEPER
Technical details that matter
- Cosine similarity compares vector direction, while Euclidean distance compares geometric distance; normalization and model training affect which is appropriate.
- Chunk size, metadata filters, embedding model choice, and query formulation all influence retrieval quality.
- Approximate nearest-neighbor indexes trade exactness, memory, and query speed; measure recall on representative queries.
- Changing the embedding model usually requires re-embedding indexed content so query and document vectors remain compatible.
MAKE A GOOD CHOICE
When is this useful?
- Semantic search across documentation or support content.
- Candidate retrieval for recommendation or deduplication systems.
- Finding related examples to supply as context to a language model.
Keyword search is often better for exact names, identifiers, and rare terms. Hybrid retrieval can combine lexical matching with vector similarity when both exact wording and semantic intent matter.
WATCH OUT FOR
Common misunderstandings
- Assuming nearby embeddings guarantee the retrieved text answers the question.
- Comparing vectors from incompatible embedding models or preprocessing pipelines.
- Ignoring metadata and permissions because the index returns a high similarity score.
REAL-WORLD TRADE-OFFS
Limitations and failure cases
- The vector space reflects its training data and may encode unwanted associations.
- Embeddings can miss exact identifiers or nuanced distinctions.
- Indexing, re-embedding, and vector search add storage and operational costs.
WHAT TO REMEMBER
Key takeaways
- 1Embeddings encode items as vectors for comparison.
- 2Vector similarity can find related meaning beyond exact keyword matches.
- 3Retrieved results still need ranking, source checks, and permission filtering.
- 4Evaluate retrieval on the queries and content your application actually serves.
PRACTICE THE FOLLOW-UP
What might an interviewer ask next?
What is the difference between an embedding and a language model?
An embedding model produces a vector representation for comparison or downstream use. A language model generates or transforms sequences; some model families can support both kinds of tasks.
When is hybrid search useful?
It is useful when queries mix semantic intent with exact terms such as product IDs, names, or error codes. Lexical and vector results can be combined and reranked.
How would you evaluate embedding search?
Create representative queries with relevant source items, then measure whether relevant results appear near the top. Also review misses, permission behavior, latency, and downstream answer quality.
SAY IT OUT LOUD
How to explain this in an interview
“An embedding is a numeric representation of an item that makes similarity search possible. An embedding model maps documents and queries into the same vector space, and an index retrieves nearby candidates. This helps when people use different words for related ideas. I would treat similarity as a ranking signal, preserve source metadata and access rules, and evaluate whether the right passages are actually retrieved.”
Connect this question to the roadmap topic it supports.