esc
  • WorkflowsPages
  • Case studiesPages
  • Machine Learning FoundationsLearn
  • AI EngineeringLearn
  • AI Guardrails & Red TeamingLearn
  • UI/UXLearn
  • Design SystemsLearn
  • Production System DesignLearn
  • AI papersPages
  • Interview KitPages
  • Book a callContact
  • Download ResumeContact
Let’s talk

I’ll build the agent for it.

Designing RAG for 10 Million Documents

How to design retrieval over 10 million documents: chunking, approximate search, reranking, permissions and a fresh index, explained for your AI interview.

In short

Split every document into chunks, store them in an index built for fast search, and search with keywords and meaning together. Rerank the best candidates, and filter by who may read each chunk inside the search, not after it.

12 min readAdvancedCommon · estimateFacts checked 26 November 2026

Say it out loud

Read it once, then say it without looking. Start with the short one; use the long one when they ask you to go deeper.

At ten million documents, I would build RAG as two pipelines. One splits, labels and embeds every file once, then keeps the index in sync with changes. The other takes a question, runs keyword and meaning search with the same permission filter, reranks the best candidates, and sends a few chunks to the model. The permission filter goes inside the search, never after it.

What is RAG at 10 million documents, in plain words?

RAG means the AI looks up the right passages first, then writes its answer from them. With 10 million documents, the model can't read everything for each question, so the system keeps a catalogue and fetches only the few passages a question needs.

Picture a county records office with 10 million files. Nobody photocopies the whole room for each enquiry. Clerks index every file once, keep that index current, and pull the handful of folders that match a request. The model is the reader at the desk, and the index is the catalogue.

At this size, the hard parts are the index, the speed of each search, keeping it fresh, and making sure each person sees only what they may read.

Key words

Chunk
A piece of a document, usually a few hundred tokens (small pieces of text, often part of a word), so a search can return one passage.
Embedding
A vector, which is a list of numbers that stands for the meaning of a text. Similar texts get similar lists.
Index
The stored structure that finds the closest chunks fast, without reading every one.
Reranker
A slower model that re-sorts the best candidates by how well each one answers the question.
Permission filter
A rule that drops any chunk the person asking has no right to read.

How do 10 million documents get in, and stay current?

Indexing runs as a pipeline. Each file is read once, cut into chunks, labelled, turned into numbers and stored. Microsoft's guidance for this kind of system lists the same stages, from chunking through to storing the chunks in the search index.

The sums matter. If each file gives about eight chunks, 10 million files make about 80 million chunks, and each chunk is embedded once. The first load is a large batch job that you run in parts, with a queue and retries, not a single request on a web page.

From files to a searchable index

10 million files

contracts, letters, call notes

Pipeline, run per file

Split into chunks

a few hundred tokens each

Turn into numbers

one vector per chunk

Store with labels

owner, date, who may read

Ready to search

updated by a sync job

  1. 1Each of the 10 million files is read once.
  2. 2Each file is cut into chunks, and each chunk becomes a list of numbers.
  3. 3Every chunk is saved with its labels, so the search can filter on them later.
  4. 4The index is ready, and a sync job keeps it current.
Each file goes through four stages once. A sync job repeats them only for files that changed, and a question never goes back to the source files.

After the first load, a sync job compares each file with the last run. It embeds new and edited files and removes the chunks of deleted ones. Deletion is the step people forget, and a removed contract that stays in the index can still be found and quoted.

Updates cost money too. Google's managed vector search prices the building and the updating of indexes. So update cost is a design input you plan for from the start.

How big does the index get?

Do the arithmetic before you pick hardware. The code below uses made-up numbers: 10 million documents, eight chunks each, and 1,024 numbers per vector. It prints the rough size of the raw vectors, the size if each number is shrunk to one byte, and how many chunks change each day.

Python
# Rough sizing for a made-up bank document store. Every number is an assumption.
DOCS = 10_000_000
CHUNKS_PER_DOC = 8
DIMS = 1024
DAILY_CHANGE = 0.02

chunks = DOCS * CHUNKS_PER_DOC
raw_gb = chunks * DIMS * 4 / 1e9
small_gb = chunks * DIMS * 1 / 1e9
changed = int(chunks * DAILY_CHANGE)

print(f"Chunks to index: {chunks:,}")
print(f"Raw vectors, 4 bytes each: {raw_gb:,.0f} GB")
print(f"Shrunk to 1 byte each: {small_gb:,.0f} GB")
print(f"Chunks to re-embed per day: {changed:,}")

Output

Chunks to index: 80,000,000
Raw vectors, 4 bytes each: 328 GB
Shrunk to 1 byte each: 82 GB
Chunks to re-embed per day: 1,600,000

About 328 GB of raw vectors is more than a typical laptop or small server holds in memory, so the index is split into parts that are searched together. Shrinking each number to one byte brings it to about 82 GB, but that can cost some accuracy, so test it on your own questions. The vector size is an example, not a figure for any product, and the sums are simple arithmetic on the assumptions.

Tip

Say the sums out loud in the interview. Interviewers want to hear you size the problem before you name a tool.

Who may see which chunk?

A search that returns a chunk a person may not read is a leak, even if the answer looks right. The safe rule: take the user's identity from the server's login, never from the question, turn it into a filter, and apply that filter inside the search itself.

  • “In multi-tenant deployments, similarity search frequently runs across the full index before access control is applied at the application layer.”

    OWASP, 2026

The order is the risk. OWASP says an attacker can probe a shared index and infer what other tenants hold from result counts and timing, without ever seeing the documents. The attack works even when every document is correctly tagged, because the access check runs after the search. So the filter goes before the ranking, not after it.

Microsoft's security filter pattern follows the same idea. It trims results with a filter on a security principal, inside the query, but the application must authenticate users, obtain trusted principal values, and apply the filter to every query.

Each chunk carries its permission label from the day it was indexed. When a permission changes, the chunks need new labels, so the sync job must handle permission changes as well as file edits.

How would you design it for a bank's files?

A bank's branch staff ask a question, and the answer must come from policies, loan files and complaint letters. Some files are only for one branch. Here is the design in five steps.

  1. 1

    Chunk each type differently

    A loan file keeps its section headings, and a call note stays whole. One rule for every file type loses the structure that makes answers accurate.

  2. 2

    Label every chunk

    Store the owner, product, branch, date and who may read it. Labels are cheap at ingest and slow to add later.

  3. 3

    Index two ways

    Build a meaning index and a keyword index over the same chunks, and merge their results at query time.

  4. 4

    Filter inside both searches

    The identity from the login becomes the filter. With no identity, return nothing.

  5. 5

    Measure on real questions

    Keep about 300 real questions with the right chunks marked. Run them on every change, and block a release that lowers recall.

What does the interviewer want to hear?

A strong answer covers

  • Two pipelines: indexing once, and answering each question.
  • Chunks, labels and an index sized with simple arithmetic.
  • Approximate search, measured with recall, not exact search for everything.
  • Hybrid search, then a reranker over a wider candidate set.
  • Permission filter inside the search, identity from the server.
  • A sync job for changes and deletes, and a test set that catches drops.

Common traps

  • Trap"Put everything in one big vector database."

    BetterTen million files also need splitting, labels, a sync job and a filter, not only a database.

  • Trap"A bigger model will fix the misses."

    BetterCheck what was retrieved before you change the model. A better model can't answer from a passage the search never found.

  • Trap"Filter the answer after the model writes it."

    BetterBy then the model has already read the chunk. Filter the search itself.

Can you spot the safe design?

Spot the safe query

Which search call is safe for a branch-only loan file?

Quick check

Your search finds meaning well but misses exact product codes. What is the cleanest fix?

Can you answer these from memory?

Flash cards · tap a card to flip it

1 / 6

What will they ask next?

  1. Q146How do you pick top-k?11 min
  2. Q147When must you re-embed everything?Coming soon
  3. Q148What are vector and embedding security weaknesses?13 min
  4. Q149How do you clean and deduplicate documents first?11 min
  5. Q151"The answer was in the docs, but the bot missed it." How do you debug?12 min
  6. Q142What is parent-child (small-to-big) retrieval?Coming soon

Learn it in depth

Last updated on 26 November 2026

Building search over a large document store?

Venkat designs and builds AI products and agents, including the search, the permissions and the tests that show the answers are right. Book a short call and tell him how many documents you have and who may read them.