Source attribution and grounding

A RAG system is only as good as its ability to prove where answers come from. Source attribution means every answer must be traceable back to a specific document. If the system can't find a source, it should say so rather than guess.

Let's test with three queries: "What are your Saturday hours?" should be answered easily. "Do you use honey?" should find our no-honey policy. And "What is your Mushroom Burger?" should pull up the detailed description.

A low score means the best match in your knowledge base is barely relevant to the question. In production, you would set a minimum score threshold (say 0.3) and if no source meets it, the system should decline to answer rather than generate a response from weak context. This is another layer of hallucination prevention.

05_rag_pipeline.ipynb
python
response = query_engine.query("Do you use honey in your food?")
print(f"Answer: {response}\n")

# Inspect the sources the answer is based on
for i, node in enumerate(response.source_nodes):
    print(f"Source {i+1} (score: {node.score:.4f}):")
    print(f"  {node.text}")
    print()

# Output:
# Source 1 (score: 0.4432):
#   We do not use any honey or bee products.
#   All sweeteners are plant-based...

Inspect source nodes and relevance scores

The honey question is answered with a score of 0.44. The system found the exact policy about bee products and used it to give a factual answer. This is grounding in action where every claim is backed by a retrievable source that users or auditors can verify.

This highlights a critical point: RAG is only as good as your data. If your knowledge base has contradictions, the LLM might pick either one or try to reconcile them incorrectly. This is why data quality and curation matter. Garbage in, garbage out applies to RAG just as much as any other system.

Quiz: Quiz

Loading practice…

Matching exercise: Match grounding concepts

Loading practice…