RAG, measured

Embeddings

An embedding turns a text into a list of numbers, so a computer can measure how close two meanings are.

A toy you can read

Imagine an embedding with only three numbers, each with a name.

Textmoneyanimalslength
Revenue grew 12%0.90.00.2
Sales went up0.80.00.1
My dog sleeps a lot0.00.90.2
money →animals →Revenue grew 12%Sales went upMy dog sleeps a lot

“Revenue grew 12%” and “Sales went up” share no word, yet they sit close together. That is how a search by meaning finds “sales” when you typed “revenue”.

The real thing

Real embedders do the same with hundreds or thousands of numbers. No single number has a name like “money”: the meaning is spread over all of them, and only the distances between texts count.

Passageadded onceQuestionasked each timeEmbeddergemini-embedding-2Numbers[0.12, −0.40, …]Numbers[0.12, −0.40, …]Indexevery passageDistanceclosest firstClosesttop 10 passagesPassageadded onceQuestionasked each timeEmbeddergemini-embedding-2Numbers[0.12, −0.40, …]Numbers[0.12, −0.40, …]Indexevery passageDistanceclosest firstClosesttop 10 passages
Every passage gets its numbers once, when the document is added. Each question gets its own numbers when it is asked, and the search looks for the passages closest to it.

Try it

Type any sentence. Gemini turns it into 3,072 numbers; the short version keeps the first 768. Both still work for search, but one takes four times the storage.

3M's 2018 balance sheet, page 58, with total current assets marked
The example sentence asks about one line of a real report: total current assets on 3M's 2018 balance sheet, page 58.
Use my own Gemini key

Sent with this one request only. Never stored or logged.

Free tier: Google may use what you send to improve its products. Don't paste anything private.

Saved example. Press the button to run your own sentence live.

768 numbers

3 KB per passage

  1. -0.022
  2. -0.006
  3. 0.008
  4. -0.042
  5. 0.016
  6. -0.033
  7. -0.028
  8. -0.021

3,072 numbers

12 KB per passage

  1. -0.013
  2. -0.004
  3. 0.005
  4. -0.024
  5. 0.009
  6. -0.019
  7. -0.016
  8. -0.012

What a bigger embedder bought

+7 → +2

A bigger embedder found the right page for 7 more questions in 100. Once the search knew which report to open, it added only 2.

FinanceBench: 150 questions over 84 annual reports, right page in the first 10 results. bge-small (384 numbers) against bge-base (768). One run each.

One question to ask your team

Which cheap fixes did we try before paying for a bigger model?
For engineers

What the demo does, in numbers.

  • The model is gemini-embedding-2. It returns 3,072 numbers; the 768 shown are the first 768, rescaled to length 1. The model is trained so that a prefix still works (Matryoshka representation learning); Google recommends 768, 1,536 or 3,072.
  • Stored as 32-bit floats, a vector costs 4 bytes per number: 3 KB at 768, 12 KB at 3,072. For a million passages, that is about 3 GB against 12 GB, before any index.
  • The finding: page hit@10 went from 0.473 to 0.547 with plain search, and from 0.753 to 0.773 with the query planner of lesson 5.

The request the demo sends:

POST /api/embed
{ "text": "Total current assets of 3M in 2018" }

→ { "model": "gemini-embedding-2",
    "sizes": [ { "dims": 768,  "bytes": 3072,  "head": [...] },
               { "dims": 3072, "bytes": 12288, "head": [...] } ] }