BuildSpark AI

Map · Retrieval & Grounding · 03 · Embeddings for retrieval

Concept card · Retrieval & Grounding

Embeddings for retrieval

Embeddings for retrieval turn a query and stored chunks into lists of numbers, then return the chunks closest to the query.

Using embeddings to find stored chunks that are close to a query.

Last checked 2026-10-17 Free card 4 min

Ask about Embeddings for retrieval

What changed

Oct 17: First card. The picture ranks three fixed chunks against a query. It is not an embedding model. Foundations Embeddings stays without a card, and this card links to that entry. Sources are the OpenAI embeddings guide, the Gemini embeddings guide, and the OpenAI retrieval guide.

1 What it is

This card is the retrieval use. You embed the stored chunks, embed the query, and return the chunks that land closest. OpenAI's embeddings guide says an embedding is a list of floating point numbers, that the distance between two lists measures relatedness, and that search ranks results by relevance to a query. The Foundations entry Embeddings is that general idea, and it does not have a card yet. This page does not repeat it.

Illustration. Pick a query. The bars are fixed picture scores for three made-up chunks. They are not distances from an embedding model.

2 Why it matters

Cost

OpenAI's embeddings guide says requests are billed by the number of tokens in the input. You embed chunks when you store them, and you embed the query when you search. Gemini's File Search guide bills that tool differently: indexing embeddings are charged, and query-time embeddings for File Search are free. This card does not copy a rate.

Quality

OpenAI's embeddings guide says to retrieve documents with cosine similarity and return the highest scored ones. A close chunk can still be the wrong fact. Gemini's embeddings guide says to use RETRIEVAL_QUERY for a query and RETRIEVAL_DOCUMENT for documents on gemini-embedding-001, and a search prompt prefix rather than a sentence-similarity prefix on gemini-embedding-2. The same task format has to be used on the query and the documents.

Risk

OpenAI's retrieval guide says semantic search can surface a result that shares few or no keywords with the query. Nearness is not a check that the chunk is true, current, or permitted. Gemini's embeddings guide says the sentence-similarity task is not for search or retrieval.

3 How to apply · try today

Take one query and three chunks you already have. If the provider has a retrieval task type or a retrieval prompt prefix, use it on the query and the matching document form on the chunks. See whether the nearest chunk is the one you would have picked by reading.

Common mistake

Comparing a query embedding from one model with chunk embeddings from another, or ranking by shared words and calling that an embedding search.

Self-check

The query is "When does the warehouse close?" What does this search use to pick a chunk?

Questions

What are embeddings for retrieval?
Embeddings for retrieval turn a query and stored chunks into lists of numbers, then return the chunks closest to the query.
Is this the same as the Foundations Embeddings entry?
No. Foundations Embeddings is the general idea, and it does not have a card yet. This card is the retrieval use: finding stored chunks close to a query.
Does the nearest chunk have to share words with the query?
No. OpenAI's retrieval guide says semantic search can surface a result with few or no shared keywords. OpenAI's embeddings guide says distance measures relatedness.