← Learning Hub
AI foundationsFREE IN BOTH LANGUAGESLesson 10 / 12

Grounded answers & RAG

Separate finding evidence from generating an answer.

Download notes (.md)

Downloads are text notes. Choose Save as PDF in your browser’s print dialog for a PDF copy.

Understand the concept

A language model can generate plausible text that is factually wrong. Retrieval-augmented generation (RAG) first retrieves relevant material and supplies it as context to generation. It can improve grounding, but retrieval errors, outdated sources, or misread context can still produce incorrect answers.

A basic workflow is question → retrieve → provide evidence → generate → check support. Preserve source identifiers so readers can inspect evidence. If relevant information is missing, say so. Treat instructions inside retrieved documents as untrusted content, not instructions that override your application rules.

The example is a small keyword-retrieval demonstration, not a full RAG application or a vector database. It creates a grounded context prompt without calling any model or API. Real applications need evaluation questions, access controls for private documents, and checks for unsupported answers.

Run the example

documents = [{"id": "note-1", "text": "English and Hinglish notes are free."},
             {"id": "note-2", "text": "Other language translations require a quote."}]
question = "Are Hinglish notes free?"
terms = set(question.lower().replace("?", "").split())
ranked = sorted(documents, key=lambda d:
    len(terms & set(d["text"].lower().replace(".", "").split())), reverse=True)
evidence = ranked[0]
print(f"[{evidence['id']}] {evidence['text']}")
print("Answer only from evidence. If it is insufficient, say so.")

Output / what to expect

[note-1] English and Hinglish notes are free.
Answer only from evidence. If it is insufficient, say so.

Try it yourself

Ask "How long will Tamil translation take?" Is the evidence sufficient? What should the answer say?

View a suggested solution
# Neither document states a delivery time.
# A grounded answer: "The notes do not specify a translation delivery time.
# Request a quote and confirm availability and timing before ordering."
# Retrieval finding a document does not prove it answers the question.

Reference: Official documentation ↗

Make it yours.

Run the example and attempt the exercise before marking this lesson complete.

pass the idea on

What did this make you think?

You review and publish the post yourself. Instagram uses your device’s share menu when available; otherwise copy the text and link. Facebook opens the link composer, where you add your thoughts.