Executable programs and extensions
Last updated
When local RAG answer is wrong: Search, chunk, model diagnosis order
Trace a wrong RAG answer from the evidence sent to the model
Local RAG1 searches documents for content relevant to a question, passes it to a language model, and generates an answer from that evidence. If the answer is wrong, inspect the extracted PDF text, retrieved chunks, actual prompt2, and response in sequence to locate the failing stage.
To make the steps concrete, follow a case where someone asks a vacation-policy PDF, “Can I take summer leave after six months of employment?” and gets a wrong answer. Before changing the model, open the response view or logs and check which passages were retrieved and whether they were included in the actual request.
When the retrieved passages include both the eligibility period and whether leave is allowed, the answer model can use both conditions as evidence. If either is missing, inspect extraction or chunking and retrieval settings first. If both reached the request but the answer differs, check the prompt and generation stage.
Find the missing condition in the retrieved passages
Open the retrieved passages attached to the question in the response view or run logs. Check whether “six months or more after joining” and eligibility to request leave appear together in one passage. When both conditions reach the model, it can connect the service period to whether leave may be requested.
If either condition is missing from the retrieved passages, open the extracted PDF text and check whether the sentence is present there. If both conditions are in the extracted text but are split or omitted in retrieval, inspect chunk boundaries, embeddings, metadata filters, or the reranker. When both reach the actual prompt, examine how the answer uses that evidence.
- Prefill vs decode: should you look at TTFT or tok/s?
- GGUF vs MLX: which model format should you download?
- How can you search your local photos and recordings with EmbeddingGemma 2?
- Local LLM slow on its first run? Five checks before blaming the hardware
- Local AI for PDFs: check the document before buying more memory

Align the source PDF with its extracted text
For a table or two-column PDF, choose a page where the issue appears and compare the source with the extracted result side by side. Check whether the “six months or more after joining” sentence is missing or whether eligibility and exceptions from a table were mixed together. If text is missing or out of order, adjust the PDF extraction tool or OCR3 settings and extract that page again.
Before rebuilding the full index, verify the corrected page text. If retrieval still returns the old result after the condition is extracted correctly, check whether the system is still reading an older extraction or index. The source and extracted text must match in meaning before changes to chunk size or retrieval settings can be interpreted.

Change retrieval settings one at a time and compare the results
If chunks are too short, “six months after joining” and leave eligibility may land in separate passages. If chunks are too long, several leave policies can be mixed together and irrelevant sentences may also be sent. Mark the sentence that should support the answer and record whether it appears among the top results for the same question.
If evidence is missing, adjust only the chunk size first and rerun the same question. If the passage is still missing, change overlap, embeddings, document filters, and the reranker one at a time. Changing several settings together makes it hard to identify what changed retrieval. Record retrieval rank and final answer accuracy separately.
Validate a new index after editing a document, then switch over
If the old answer persists after replacing a PDF, check its hash, index creation time and version, and cache key instead of looking only at the filename. The content may have changed while the name stayed the same. Confirm that the new document appears in extracted text, then test whether a representative question retrieves the updated clause from the new index.
Deleting the active index first can leave retrieval unavailable while the replacement is being checked. Build the new index in a separate location, verify it with representative questions, and then point the service to it. Keep the previous index for rollback and record the document hash, index version, question, retrieved passages, and answer.

When the evidence is right, check the prompt and waiting time
If a retrieved passage says summer leave is available after six months but the answer says one year is required, check whether that passage reached the actual prompt unchanged. If it did, instruct the model to answer only from the supplied evidence and say when a condition is absent, then rerun the same input. If it still misreads the condition, compare models or quantizations.
Break a slow request into three intervals. Record the time from sending the question until retrieval results appear, from retrieval completion until the first token4, and from the first token until the answer finishes. A long first interval points to the index or filters; a long middle interval points to evidence length and prefill5; a long final interval points to token generation speed. If slowdown occurs only with concurrent users, compare queueing and memory use for one versus four users.
Terminology notes
Retrieval-Augmented Generation — A method that retrieves material relevant to a query, adds it to the model input, and generates an answer from that context.
Back to the textPrompt — The input text sent to a model. For generative models it describes the desired result and strongly shapes the output.
Back to the textOCR — The process of recognizing characters in images or scanned documents and turning them into text. Table layout and reading order still need the original image to verify.
Back to the textToken — A unit into which a model divides input or output for processing.
Back to the textPrefill — The stage where an LLM reads the input prompt and computes representations for its tokens. Longer prompts contain more tokens to process.
Back to the text
Frequently asked questions
- What should you check first in this article?
- Local RAG searches documents for content relevant to a question, passes it to a language model, and generates an answer from that evidence. If the answer is wrong, inspect the extracted PDF text, retrieved chunks, actual prompt, and response in sequence to locate the failing stage.
- How much memory does it need?
- Break a slow request into three intervals. Record the time from sending the question until retrieval results appear, from retrieval completion until the first token, and from the first token until the answer finishes. A long first interval points to the index or filters; a long middle interval points to evidence length and prefill; a long final interval points to token generation speed. If slowdown occurs only with concurrent users, compare queueing and memory use for one versus four users.
