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.
Language model aisa text bana sakta hai jo convincing lage par factual galat ho. Retrieval-augmented generation, ya RAG, pehle relevant material dhoondta hai aur generation ko context deta hai. Grounding improve ho sakti hai, par wrong retrieval, purane sources ya misread context se galat answer phir bhi aa sakta hai.
Basic flow hai question → retrieve → evidence do → generate → support check karo. Source identifiers bachao taaki reader evidence dekh sake. Relevant information missing ho toh clearly bolo. Retrieved document ke andar likhe instructions ko untrusted content samjho, application rules ko override karne ka order nahi.
Example sirf small keyword-retrieval demo hai; full RAG app ya vector database nahi. Yeh model ya API call ke bina context prompt banata hai. Real apps mein evaluation questions, private documents ke access controls aur unsupported answers ke checks chahiye.
Code chalao
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 / kya expect karein
[note-1] English and Hinglish notes are free.
Answer only from evidence. If it is insufficient, say so.
# 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.
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.