Quick revision
The short answer
I would run an ingestion pipeline triggered by document change events that re-embeds changed documents and deletes removed ones by document id, and store access metadata such as groups and tenant on every chunk so that every search applies a metadata filter built from the authenticated user. Retrieval combines keyword and vector search with a reranker, the prompt requires citations and returns not found when the context is insufficient, chunks record the embedding model version so a model change triggers re-embedding, and a labelled question set measures retrieval quality. Filtering only after retrieval fails because the top results can all be forbidden, leaving nothing, and because forbidden text can leak through caches, logs or the prompt.
What to remember
In this answer, we designed a RAG assistant over 200,000 changing documents. Change events drove idempotent re-ingestion that deleted old chunks by document id, with a nightly reconciliation. Every chunk carried tenant and group metadata, and every search applied a filter built from the authenticated user, because filtering after retrieval loses answers and leaks text. Hybrid keyword and vector search with a reranker improved retrieval, the prompt demanded citations or NOT_FOUND, the embedding model version made re-embedding a planned migration, and a labelled question set measured quality.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
I would run an ingestion pipeline triggered by document change events that re-embeds changed documents and deletes removed ones by document id, and store access metadata such as groups and tenant on every chunk so that every search applies a metadata filter built from the authenticated user. Retrieval combines keyword and vector search with a reranker, the prompt requires citations and returns not found when the context is insufficient, chunks record the embedding model version so a model change triggers re-embedding, and a labelled question set measures retrieval quality. Filtering only after retrieval fails because the top results can all be forbidden, leaving nothing, and because forbidden text can leak through caches, logs or the prompt.
Why this question is asked
A support assistant over a large, changing document set is where RAG stops being a demo. With 200,000 documents and daily changes, ingestion becomes a pipeline with failure handling. With permissions, one mistake shows a customer's contract to the wrong person, and that is worse than any wrong answer. Interviewers ask this design question to see whether we put access control in the right place and keep the index correct over time. In this answer, we will design change-driven ingestion, enforce permissions inside the search, improve retrieval with hybrid search and reranking, shape the prompt, plan for embedding model changes, and measure quality.
1Sizing the Problem
Let us put numbers on it. 200,000 documents averaging 5 pages, split into chunks of about 500 tokens, gives roughly 2 to 3 million chunks. With 1,024-dimension embeddings stored as 4-byte floats, that is about 4 KB per vector, so 10 to 12 GB of vectors plus text and indexes. PostgreSQL with pgvector and an HNSW index, an approximate nearest-neighbour index that finds close vectors without scanning them all, handles this comfortably on one well-sized primary with replicas. If 2 percent of documents change daily, that is 4,000 documents a day to re-ingest, which is small. So the hard parts are correctness and permissions, not raw scale.
2Ingestion Driven by Change Events
Re-indexing everything nightly would cost 2 million embeddings a day and still leave answers up to a day stale. Instead, the document system publishes an event whenever a document is created, updated, deleted or has its permissions changed, for example on a Kafka topic. An ingestion worker in Spring Boot consumes the events. For a create or update, it deletes the document's old chunks by document id, then reads, splits, embeds and stores the new version, all with the same document id in the metadata. For a delete, it removes the chunks. For a permission change, it updates the access metadata, which is cheaper than re-embedding.
Notice that the worker is idempotent: processing the same event twice deletes and re-adds the same chunks. A nightly reconciliation job compares document versions in the source with those in the store and repairs anything a lost or failed event left behind. The delete and add are not one transaction in most vector stores, so for a moment the document may be missing; with pgvector we can wrap both in one database transaction.
3Enforcing Permissions Inside the Search
Every chunk carries its tenant and the groups allowed to read it. When a user asks a question, the service builds a filter from the authenticated user's identity on the server, not from anything in the question, and passes it with every search. The vector store returns only chunks the user is allowed to see, and only those can ever reach the prompt.
8 messages in order. Play them, or step through them one at a time.
The filter is applied in the database, before any text reaches the prompt.
4Why Filtering After Retrieval Fails
It is tempting to search without filters and then drop the chunks the user may not read. This fails in two ways. First, quality: if the top 5 results are all from legal contracts and the user is in support, all 5 are dropped and the user gets nothing, even though permitted documents ranked 6 to 20 contained the answer. Raising top-k to compensate only moves the problem. Second, leakage: forbidden text now flows through our code, where it can end up in a cache keyed by question, in debug logs, in the reranker's inputs, or in the prompt if one code path forgets the check. Similarity scores can even reveal that a document on a topic exists. Pre-filtering in the index removes all of these, because forbidden chunks never leave the database.
5Better Retrieval: Hybrid Search and Reranking
Vector search finds text with similar meaning but is weak on exact terms such as error codes, product names and ticket numbers. Support questions are full of those: what does error E-4012 mean. Keyword search, such as PostgreSQL full-text search or BM25 in a search engine, is strong exactly there. Hybrid retrieval runs both with the same permission filter and merges the lists, for example with reciprocal rank fusion, which scores each chunk by its positions in the two lists. A reranker, a smaller model that reads the question and each candidate together and scores relevance, then picks the best 5 of the 20 candidates. It adds perhaps 100 to 200 milliseconds, so we use it where quality matters most.
6Prompt, Model Versions and Evaluation
The prompt includes each chunk with its document id and title, tells the model to answer only from the context, to cite document ids for each statement, and to reply NOT_FOUND if the context is insufficient. The service turns NOT_FOUND into a helpful message and offers to open a ticket, and it turns cited ids into links. Because we stored the embedding model version on every chunk, changing the embedding model is a planned migration: we build a new index alongside the old one, re-embed all 2 to 3 million chunks, evaluate, and switch reads over. Vectors from two models are not comparable, so the two must never be mixed in one search.
Finally, we measure. A labelled set of a few hundred real support questions, each with the documents that answer it, tells us retrieval recall at 5, whether a correct document is among the top 5, and the not-found rate. We run it on every change to chunking, filters, retrieval or models, and we add new questions from user feedback each month.
7Follow-up questions
Where would permission filtering fail if done only after retrieval?
It fails on quality when the top-k results are mostly forbidden, so the user gets too few or no chunks although permitted answers exist further down. It fails on security because forbidden text passes through application code, caches, logs, rerankers and possibly the prompt, and one missed check leaks it. Filtering inside the vector store query avoids both, since forbidden chunks never leave the database.
Could the model reveal a forbidden document through its answer?
Only if the forbidden text reached the prompt. That is why the filter belongs in retrieval. We also avoid caching answers across users, since a cached answer built from one user's permitted documents may not be permitted for another.
8Conclusion
In this answer, we designed a RAG assistant over 200,000 changing documents. Change events drove idempotent re-ingestion that deleted old chunks by document id, with a nightly reconciliation. Every chunk carried tenant and group metadata, and every search applied a filter built from the authenticated user, because filtering after retrieval loses answers and leaks text. Hybrid keyword and vector search with a reranker improved retrieval, the prompt demanded citations or NOT_FOUND, the embedding model version made re-embedding a planned migration, and a labelled question set measured quality.
Open with
I would split it into ingestion, retrieval and evaluation. For ingestion, the document system publishes change events, and a Spring Boot worker deletes a document's old chunks by its id and re-reads, splits and embeds the new version, or just deletes them if the document was removed.
Then, if they want more
It is idempotent, and a nightly job reconciles versions in case events were lost. At about two to three million chunks, pgvector with an HNSW index is enough. For permissions, every chunk stores tenant and allowed groups, and every search carries a metadata filter built from the authenticated user on the server, so forbidden chunks never leave the database.
If you filter only after retrieval, the top results can all be forbidden and the user gets nothing, and forbidden text passes through caches, logs and maybe the prompt. For quality, I combine keyword and vector search, because support questions contain error codes and product names, and rerank the top twenty to the best five.
The prompt requires citations by document id and a NOT_FOUND reply when the context is not enough. Each chunk records its embedding model version, so changing models means building a new index and re-embedding everything. And I keep a labelled set of real questions with their correct documents and measure recall at five on every change.
About this answer
- Last updated
- 12 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- Spring AI reference
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "Design a RAG-based support assistant in Spring Boot over 200,000 documents that change...": https://scrivio-interview-library.netlify.app/spring-boot/spring-ai/6de01b32b6/