Quick revision
The short answer
Ingestion splits the documentation into chunks with metadata such as source, section and product version, embeds them and stores them in a vector store such as pgvector. Retrieval embeds the question, searches the top-k chunks with metadata filters such as version and language, and can rerank them. The prompt gives the chunks with ids and tells the model to answer only from them, cite the ids and say it does not know otherwise. Evaluation uses questions with expected answers and sources to measure retrieval recall and answer faithfulness on every change, and embeddings are refreshed when documents change and when the embedding model changes.
What to remember
In this answer, we designed a documentation chatbot with RAG. Ingestion splits documents into chunks with source, section and version metadata, embeds them and stores them in pgvector. Retrieval searches the top-k with metadata filters and optional reranking. The prompt gives numbered chunks and requires answers only from them with citations, and a refusal otherwise. An evaluation set measures retrieval recall and faithfulness on every change, and the index is refreshed when documents or the embedding model change.
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.
Ingestion splits the documentation into chunks with metadata such as source, section and product version, embeds them and stores them in a vector store such as pgvector. Retrieval embeds the question, searches the top-k chunks with metadata filters such as version and language, and can rerank them. The prompt gives the chunks with ids and tells the model to answer only from them, cite the ids and say it does not know otherwise. Evaluation uses questions with expected answers and sources to measure retrieval recall and answer faithfulness on every change, and embeddings are refreshed when documents change and when the embedding model changes.
Why this question is asked
A documentation chatbot is the most common first retrieval-augmented generation, or RAG, project: instead of hoping the model knows our product, we look up the relevant parts of our documentation and give them to the model with the question. It looks simple, yet most quality problems come from details in chunking, filtering, prompting and refreshing. Interviewers ask this design question because it touches every part of a RAG system. In this answer, we will recap RAG, then design ingestion, retrieval, prompting with citations, evaluation and keeping the index fresh.
1A Quick Recap of Retrieval-Augmented Generation
An embedding model turns text into a vector, a list of numbers such that texts with similar meaning get vectors that are close together. A vector store keeps these vectors and finds the ones nearest to a query vector. RAG uses this in two phases. Offline, we embed pieces of our documents and store them. At question time, we embed the question, find the closest pieces and put them into the prompt, so the model answers from our documentation rather than from memory.
- Split documents into chunkswith source, section, version
- Embed chunks and store thempgvector table
- Embed the questionsame embedding model
- Search top-k with metadata filtersversion 4.x, language en
- Rerank and keep the best fewoptional
- Prompt with numbered chunksanswer only from them, cite ids
- Return answer and source links
7 steps in order. Play them, or step through them one at a time.
2Ingestion: Chunks With Metadata
We read the documentation pages, from Markdown, HTML or PDF, and split them into chunks, pieces small enough to be precise but large enough to make sense on their own, often a few hundred tokens, split at headings and paragraphs rather than in the middle of a sentence. A small overlap between neighbouring chunks keeps a sentence that spans a boundary from being lost.
Each chunk carries metadata: the source URL, the section heading, the product version, the language and the last update date. Metadata is what makes filtering and citations possible later. We then embed each chunk and store it, here in PostgreSQL with the pgvector extension, which keeps the vectors next to ordinary columns and lets us use the same database we already operate.
In Spring AI, VectorStore.add embeds documents with the configured embedding model before storing them. In a real pipeline the metadata comes from each page, not from constants; check your version for splitter options.
3Retrieval: Top-k Search With Filters
At question time we embed the question with the same embedding model and search for the top-k most similar chunks, for example k = 8. Filters matter as much as similarity. A customer using version 3.9 must not get instructions for 4.2, and a French user wants French documentation, so we filter on version and language metadata.
Similarity search is fast but imprecise. A reranker, a model that reads the question and each candidate chunk together and scores how well the chunk answers it, can reorder the 8 hits and keep the best 4. Hybrid search, combining vector similarity with keyword search, helps with exact terms such as error codes and configuration property names, which embeddings sometimes miss.
4Prompting: Answer Only From Sources, and Cite Them
We give the model the retrieved chunks with short ids and clear rules. It must answer only from the given chunks, cite the id of each chunk it used, and say it does not know when the chunks do not contain the answer. That last rule is what stops the bot from filling gaps with plausible inventions.
After the call, code checks that every cited id is one we actually provided and turns ids into links using the source metadata, so the user can open the page. Spring AI also offers a retrieval advisor that does the search and prompt assembly automatically; writing it explicitly, as here, makes the citation step clearer.
5Evaluation on Every Change
We build an evaluation set of, say, 150 real questions, each with the expected answer and the document sections that contain it, plus some questions the documentation cannot answer. Two numbers matter most. Retrieval recall asks whether the right section was among the retrieved chunks; if it was not, no prompt can save the answer. Faithfulness asks whether the answer is supported by the retrieved chunks, which we judge with a model grader and spot-check by hand. We also check that unanswerable questions get 'I do not know'.
We run this set on every change: chunk size, k, filters, reranker, prompt, chat model or embedding model. A change that raises faithfulness but drops recall is visible immediately instead of being discovered by customers.
6Keeping the Index Fresh
Documentation changes, and an index built months ago gives outdated answers. The ingestion pipeline runs whenever the docs are published: it re-chunks changed pages, deletes chunks of removed pages, and stores a content hash per page so unchanged pages are skipped. When the embedding model itself changes, all chunks must be re-embedded, because vectors from different models are not comparable; we build a new index alongside the old one, evaluate it, and switch over in one step.
7Follow-up questions
How do you choose the chunk size?
Experiment with the evaluation set. Small chunks are precise but may lose context; large ones keep context but dilute similarity and use more prompt tokens. Splitting by headings with a few hundred tokens per chunk is a reasonable start, then measure recall.
Why not put the whole documentation in the prompt, since context windows are large?
Even if it fits, it costs much more per question, adds latency, and models are less reliable at finding one detail in a very long context. Retrieval keeps prompts small and focused and makes citations natural.
What do you do when users ask about a version you do not know?
Ask them, or detect it from their account, and default to the latest version only when it is unknown, saying so in the answer.
8Conclusion
In this answer, we designed a documentation chatbot with RAG. Ingestion splits documents into chunks with source, section and version metadata, embeds them and stores them in pgvector. Retrieval searches the top-k with metadata filters and optional reranking. The prompt gives numbered chunks and requires answers only from them with citations, and a refusal otherwise. An evaluation set measures retrieval recall and faithfulness on every change, and the index is refreshed when documents or the embedding model change.
Open with
I would split it into four parts. Ingestion: read the documentation, split it into chunks of a few hundred tokens at headings and paragraphs with a small overlap, and attach metadata, source URL, section, product version, language and update date.
Then, if they want more
Then embed the chunks and store them in pgvector, which keeps vectors next to normal columns in Postgres.
Retrieval: embed the question with the same model, search the top-k, maybe eight, with metadata filters on version and language so a 3.9 user does not get 4.2 instructions, add keyword search for error codes and property names, and optionally rerank to keep the best four.
Prompting: give the chunks with numbered ids and instruct the model to answer only from them, cite the ids, and say it does not know if they do not contain the answer; then code checks the cited ids exist and turns them into links.
Evaluation: a set of real questions with expected answers and source sections, plus unanswerable ones, measuring retrieval recall and faithfulness on every change to chunking, prompts or models.
Finally freshness: re-ingest on every docs publish using content hashes, delete removed pages, and re-embed everything into a new index when we change the embedding model, because vectors from different models are not comparable.
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 Java chatbot that answers questions about your product documentation with...": https://scrivio-interview-library.netlify.app/spring-boot/ai-agents-and-mcp/f7ad90807f/