MiddleAI

What is an embedding, and how does embedding search differ from keyword search?

The interviewer wants to know that you understand embeddings as a concrete tool with strengths and weaknesses, not as an impressive buzzword. They also want to see whether you know how to check that it is really better.

An embedding turns a piece of text into a vector, a list of numbers, using a model trained so that two passages with similar meaning end up with vectors that are close together. To search, you embed your documents ahead of time and store the vectors. When a question comes in, you embed it with the same model and take the passages whose vectors are closest, usually measured with cosine similarity.

The main differences from keyword search:

  1. Keywords compare words, embeddings compare meaning. A customer writes "compensate", the document says "refund": counting words sees different words that matter, while an embedding still ranks that passage high.
  2. Embedding scores only mean something relatively. Many models return scores packed into a narrow range, so you compare ranks rather than reading the score as a percentage.
  3. Keywords are stronger for codes, proper names and exact strings. If you search for a product code or a function name, an exact match is more trustworthy than a match on meaning.

An important point to make: don't assume embeddings are always better. The right approach is to prepare a set of sample questions, each with the passage that answers it, run both methods, and count how many questions each one finds enough information for. That set of questions also exposes wrong assumptions. For example, embedding the section title along with the text sounds helpful but can measure worse.

Bonus points: mention that embedding models have an input length limit (many cut off around 512 tokens), so documents need to be split into small enough passages, and that using the prefixes the model expects (like query: and passage: in the e5 family) also affects quality.