LlamaIndex Hub
Flat isometric illustration of two pink cube stacks flanking a glass case holding a glowing amber column, arrows pointing inward across a teal grid platform.
troubleshooting

LlamaIndex Retrieval Troubleshooting: Fix Bad Answers

Find out why LlamaIndex gives bad answers. Replay a query to see whether retrieval missed a passage, a filter dropped it, or synthesis went wrong.

By LlamaIndex Hub Editorial · · 7 min read

To fix a bad LlamaIndex answer, replay the same question with a known source passage in mind. Check whether retrieval found the passage, whether it survived filtering or reranking, and whether response synthesis produced an answer supported by the surviving text. Querying

Compare source nodes before and after postprocessing

Start with the exact question that produced the bad answer. In the authoritative document, copy the full passage that would answer it, including any condition or exception. Record the document version and section so you can distinguish it from an older or incomplete match. RAG failure mode checklist

For example, suppose you ask “How many days do I have to return an unopened accessory?” The current returns policy says, “Unopened accessories may be returned within 30 days of delivery.” Look for the item, the deadline, and what starts the clock in the retrieved text.

Run the two calls below in your existing app. Use its configured retriever and llm. Use the production node_postprocessors list in its original order. Both calls use no_text, which skips answer generation and exposes the evidence through source_nodes. The second call still applies the postprocessors. The output shows each node ID and its full text. Retriever query engine API · Response synthesizer guide · NodeWithScore API

from llama_index.core.query_engine import RetrieverQueryEngine

question = "How many days do I have to return an unopened accessory?"

before_postprocessors = RetrieverQueryEngine.from_args(
    retriever=retriever,
    llm=llm,
    response_mode="no_text",
)
before = before_postprocessors.query(question)
print("Before postprocessing")
for source in before.source_nodes:
    print(source.node_id, source.get_content(), sep="\n")

after_postprocessors = RetrieverQueryEngine.from_args(
    retriever=retriever,
    llm=llm,
    response_mode="no_text",
    node_postprocessors=node_postprocessors,
)
after = after_postprocessors.query(question)
print("After postprocessing")
for source in after.source_nodes:
    print(source.node_id, source.get_content(), sep="\n")

If only follow-ups fail, check the chat mode first. Inspect the rewritten question in condense_question or condense_plus_context. In context mode, retrieval uses the current message. In simple mode, the LLM answers directly. LlamaIndex query engine vs chat engine · Chat engine usage pattern

The symptom table

What you see Where to look next
The expected passage is absent from both outputs Check the extracted document text, indexed nodes, and retriever settings, including any retriever-level filters.
No nodes appear even in the first output Check that the app is querying the expected index and that the retriever’s filters allow eligible nodes.
Both outputs contain nodes, but their text is unrelated Check whether the indexed passage exists and whether retrieval ranks it within similarity_top_k.
The full passage appears only before postprocessing Inspect the postprocessors in order. Check similarity cutoffs and how many nodes the reranker keeps.
Both outputs show “30 days” but omit “of delivery” Check the chunk boundary and whether an adjacent node contains the missing condition.
The full passage survives, but the normal answer says “30 days from purchase” Confirm the production response includes the same passage. Check the synthesis prompt and response mode.
The correct passage survives among many irrelevant nodes Check how much context reaches synthesis and whether reranking can reduce the noise while retaining the passage.
The answer is visible in a scanned PDF but missing from its extracted text Apply OCR and confirm the passage is present before reindexing.
Semantic questions work, but exact IDs fail Compare keyword or hybrid retrieval on the same ID query.
The answer cites an older document version Check the version in the returned nodes and refresh the indexed document.
Retrieval quality drops across queries after a change Compare the query embedding model with the model used to build the index.
Metadata filters seem ineffective Inspect the metadata on the nodes and compare it with the retriever’s filter.
Startup or the first query is slow Check whether startup rebuilds the index. If it does, load the persisted index.
Queries stay slow after startup Compare retrieval and synthesis timings in a query trace.

The documents never loaded

Check the documents returned by your reader for the exact passage before inspecting the index. SimpleDirectoryReader selects readers by file type. If the extracted text from a scan omits the passage, use an OCR-capable parser and check its output before indexing it. SimpleDirectoryReader guide · LlamaParse OCR documentation

The chunk boundary split the answer

If the source has the full passage but a returned node ends before “of delivery,” check the adjacent text. If the condition starts in the next chunk, try a sentence-aware splitter or adjust chunk overlap, rebuild the affected index, and replay the query. A sentence-window parser paired with MetadataReplacementPostProcessor can also supply surrounding text for synthesis. LlamaIndex chunk size and overlap guide · RAG failure mode checklist · Node postprocessor modules

Exact identifiers fail to match

If searches by topic work but a query for an error code returns unrelated codes, compare hybrid search, which combines keyword and vector retrieval, against your current retriever. Look for the exact code and the passage explaining it in the returned text. RAG failure mode checklist

Metadata filters miss their target

Inspect source.metadata on the nodes from a replay and compare the relevant field and value with the configured filter. If that field is missing from the indexed nodes, attach it during ingestion and refresh the affected documents. A filter configured on the retriever applies to both replay calls. NodeWithScore API · RAG failure mode checklist

Too many nodes bury the evidence

If the passage disappears after postprocessing, rerun the second pass with successive prefixes of the production list. Start with the first processor, then add the next, and find the first pass that loses the text. Check similarity_cutoff for SimilarityPostprocessor or top_n for a reranker such as SentenceTransformerRerank. Retriever query engine API · Node postprocessor modules

If the full passage survives among many irrelevant nodes, inspect the production prompt and context size. Try reducing similarity_top_k or using a reranker, and check that the full passage still reaches synthesis after the change. RAG failure mode checklist

The answer contradicts the retrieved text

Run the same question through your normal production query engine, with answer generation enabled. Check its own source nodes for the full passage and any competing versions.

response = query_engine.query(question)
print(response)
for source in response.source_nodes:
    print(source.node_id, source.get_content(), sep="\n")

If the production nodes contain the full current rule and the answer gives a different deadline, hold the evidence fixed. Try changing the QA prompt to direct the model to answer from that context. Use a faithfulness check to compare the answer with its evidence. Querying · RAG failure mode checklist · Evaluating guide

Stale answers

Compare the document version in the returned text or metadata with the current source. If the index is stale, re-ingest the updated document or refresh it with index.refresh_ref_docs() using the same document ID. Recheck which index the app loads. RAG failure mode checklist

If startup is slow because the app rebuilds the index, persist it and reload it with the same embedding configuration. Storing guide

If queries stay slow after startup, use callback timings to compare retrieval and synthesis in a trace of the normal query. Callbacks

The embedding model changed

If retrieval degrades across questions after a configuration change, compare the embedding model used for querying with the one recorded for the index. If you changed models, rebuild the index with the model used at query time. RAG failure mode checklist

The tutorial is out of date

If older code imports ServiceContext, migrate its configuration to Settings. LlamaIndex deprecated ServiceContext in 0.10 and removed it in 0.11. Current core classes use imports such as llama_index.core.query_engine, and integrations are packaged separately. Settings migration guide · LlamaIndex 0.11 release notes · Installation and setup

Verify the fix and build an eval set

  • Before the change, save the exact question, the expected passage, and the normal answer. Record whether each replay returned the complete passage and whether the answer was supported by its own source nodes.
  • Change one setting or pipeline stage and rerun the two no_text passes and the normal query. Compare the full passages and answer with the baseline.
  • Verify both results. In the returns example, the final nodes should include the unopened-item condition and delivery as the start of the return window. The answer should say “30 days from delivery” and apply it to unopened accessories.

Keep that query and passage as an evaluation case. For a larger set, use expected node IDs with hit rate or mean reciprocal rank to evaluate retrieval. Score answer faithfulness separately by checking whether the retrieved context supports the answer. Evaluating guide

Evidence and limits. This guide is based on the current, unversioned LlamaIndex Python framework docs and the RAG failure mode checklist on main. The returns example is hypothetical. The replay steps were not run for this article.

Sources

  1. LlamaIndex: Querying
  2. LlamaIndex: RAG failure mode checklist
  3. LlamaIndex: Retriever query engine API
  4. LlamaIndex: Response synthesizer guide
  5. LlamaIndex: NodeWithScore API
  6. LlamaIndex: Chat engine usage pattern
  7. LlamaIndex: SimpleDirectoryReader guide
  8. LlamaIndex: LlamaParse OCR documentation
  9. LlamaIndex: Node postprocessor modules
  10. LlamaIndex: Storing guide
  11. LlamaIndex: Callbacks
  12. LlamaIndex: Settings migration guide
  13. LlamaIndex: 0.11 release notes
  14. LlamaIndex: Installation and setup
  15. LlamaIndex: Evaluating guide

Related