Skip to the page

Retrieval-augmented generation · core

Embeddings and similarity search

An embedding turns text into a list of numbers so that similar meaning gives nearby vectors. Search finds the nearest vectors, and the model that made the vectors must be the same for queries and documents.

The notes

What you must know

  • An embedding model turns a text (or image) into a fixed-length list of numbers. Texts with similar meaning land close together.
  • The query and the documents must be embedded with the same model. Vectors from different models, or different versions of one model, live in different spaces, so never mix them in one index.
  • Cosine similarity compares direction. For normalised vectors, cosine and dot product give the same ranking. Use the metric the model was trained for.
  • Exact search compares the query with every vector. Approximate (ANN) indexes such as HNSW and IVF are much faster but can miss true neighbours. Settings like ef_search or probes trade recall for speed.
  • Weak spots: exact identifiers (policy numbers, error codes), negation (not covered), numbers and very short queries.
  • Choose a model with your own test set: 100 to 300 real questions with the chunks that answer them. Compare recall@k and MRR or NDCG. Public leaderboards only make a shortlist.
  • Check languages (Hindi in Devanagari and Hinglish in Roman script), maximum input length, dimensions, licence, price or GPU cost, and whether the provider may retire the model.
  • Changing the embedding model means a new index and re-embedding everything, with a dual-write and a flag, and with the old index kept for rollback.

The red pen

Common traps: mistake → fix

  • Mistake: Embeddings understand exact words

    Fix: they capture meaning and blur exact strings like E-4012 and E-4021.

  • Mistake: A newer embedding model can replace the old one in place

    Fix: old vectors become meaningless against new queries; build a new index.

  • Mistake: The top of a public leaderboard is the best model for us

    Fix: test on your own documents and languages.

Easy to hard

Questions interviewers ask, easy to hard

  1. What is an embedding?
  2. How does a search for refund not received find money not credited back?
  3. Cosine similarity or dot product?
  4. How would you choose an embedding model for English and Hindi insurance documents?
  5. Search became random after we switched the embedding model. Why? How should the switch be done?

Practise

Practise with these questions

Your first interview is free

Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.

Start your free interview