What are embeddings, and how are they used in search?
RAG · Intermediate 2
Short answer
An embedding is a vector of numbers that represents the meaning of a piece of text, so texts with similar meaning get vectors that are close together. In search you embed documents ahead of time and the query at search time, then return the documents whose vectors are nearest, often by cosine similarity.
Deeper answer
Embedding models are trained so that related text lands close together, which lets search match "forgot login" to "reset your password" without shared words. The vectors are stored in a vector index that can find nearest neighbours quickly, even among millions of items, using approximate search.
Limits matter in interviews: embeddings can miss exact strings such as product codes or names, and quality depends on the embedding model and the domain. That is why many systems combine vector search with keyword search, and why you must use the same embedding model for queries and documents.
What a strong answer covers
- A vector of numbers representing meaning
- Similar meanings are close together
- Embed documents ahead and the query at search time
- Nearest by cosine similarity
Answer it out loud in the mock interview about 1 min
Follow-ups to expect
- Why must queries and documents use the same embedding model?
- When would keyword search beat vector search?
Common mistakes
- Saying embeddings store the original text
- Assuming any two embedding models' vectors can be compared
Learn it
- How do you choose a chunk size for RAG?
- Your RAG app gives wrong answers. How do you find the cause?
- Design a RAG system that lets a law firm search and ask questions about 50,000 contracts.
- How would you detect hallucinations in a production RAG application?
- How do you make a RAG system cite sources and stay grounded?
- What are hybrid search and reranking, and when do they help?
- How do you keep a RAG index up to date as documents change?
- How do metadata filters improve retrieval?
- How would you build RAG over documents full of charts and images?
- Your RAG system must handle scanned PDFs, tables and slides. How do you ingest them?
- How do you make sure users only get answers from documents they are allowed to see?
- What are query rewriting and HyDE, and when do they help?
- Your HR assistant keeps quoting last year's leave policy. How do you fix it?
- Tell me about a RAG system you built and how you measured whether it worked.
- Can you do retrieval for long documents without a vector database?
- What is RAG, and why would you use it?
- When would you use graph RAG instead of standard vector RAG?