Lesson 59 — Intermediate

Grounding, Citations & Abstention

RAG ka asli faayda tab milta hai jab har claim ka source traceable ho — aur kabhi kabhi sahi jawab yehi hai ki "mujhe nahi pata". Is lesson mein hum evidence se jawabna, claims ko sources se jodna, citations ≠ grounding ka farq, aur insufficient evidence pe abstain dekhenge.

⏱ 10 min• Intermediate• Query Transformation & RAG-Fusion

Grounding kya hai

Kya hai?

Grounding matlab model ka jawab retrieved evidence pe anchored hona — jo kuchh bhi bolo wo context mein maujood baat se ho, model ke andar ke "yaad se" nahi. Citations iska visible proof hain.

Kab kaam aata hai?

Compliance-heavy domains (legal, medical, finance), customer-facing answers jahan "policy ke hisaab se" zaroori hai, aur har high-stakes answer pe.

Kahan milta hai?

Prompt contract mein ([n] citations), output parser mein (cited ids extract), aur evaluation mein (groundedness checks). Tumhare baseline RAG ke upar ek layer.

Retrieval tumhara kaam hai, generation LLM ka — par dono ke beech ka trust contract tum define karte ho. "Sirf context se bolo, cite karo, warna abstain karo" — yehi teen rules grounding banate hain.

Pehla rule: Prompt mein citation contract likho — block numbers kaise aate hain ([1], [2]), kahan lagte hain, aur context mein na hone pe kya likhna hai. Bina contract ke model format khud invent karega.

Claims ko sources se jodna

def grounded_prompt(context_blocks, question):
    lines = []
    for i, b in enumerate(context_blocks, start=1):
        lines.append("[{}] {}\n{}".format(i, b["heading"], b["text"]))
    numbered = "\n\n".join(lines)
    return TEMPLATE.format(context=numbered, question=question)

# output contract:
# - har claim ke saath [n]
# - last line: "sources: [1], [3]"    <- UI mein dikhao
UI tip: Citations ko answer ke neeche list karo, hover pe snippet dikha do. Users jab source dekh lete hain toh trust badhta hai — aur tumhe debugging mein wahi snippet help karta hai.

Citations ka matlab grounding nahi

import re
def cited_ids(answer):
    return {int(x) for x in re.findall(r"\[(\d+)\]", answer)}

def groundedness_check(answer, n_blocks):
    bad = [i for i in cited_ids(answer) if i > n_blocks]
    return len(bad) == 0     # bahar ka citation = fabricated source

# par sirf ye check kaafi nahi:
# [2] lagaya bhi ho, par us block mein claim ka support hai ya nahi —
# uske liye claim-source match chahiye (LLM judge ya keyword overlap)
Muh jawab: Q: "Citations theek hain toh grounding hai?" A: Nahi — citation sirf pointer hai. Support check chahiye: cited text claim ko actually support karta hai ya nahi. Interview mein yahi farq poochha jaata hai.

Kab abstain karna hai

NO_ANSWER = "Insufficient information — is corpus mein iska jawab nahi hai."

def answer_or_abstain(query, hits, min_score):
    if not hits or hits[0]["score"] < min_score:
        return {"text": NO_ANSWER, "citations": [], "abstained": True}
    prompt = GROUNDED.format(context=assemble(hits), question=query)
    ans = chat(prompt)
    # prompt mein bhi likha hai: context mein na ho toh "Insufficient information"
    return {"text": ans, "citations": cited_ids(ans), "abstained": False}
Abstain nahi, dhokha: Model ko hamesha jawab dene pe majboor karo toh wo hallucinate karega — ye RAG ka sabse bada failure mode hai. Abstain ek feature hai: "nahi pata" bolna hi trust banata hai.

Exercise

Question: Evidence insufficient ho toh model ko kya karna chahiye? (ek word English)

Question: Answer mein likha [3] — ye number kis cheez ka hai?

Question: Citation hone ka matlab grounding — true ya false?

Question: Abstain ke do layers kaunsi hain — retrieval aur generation mein se?

Common mistakes

Desi example: Court ka judgment

Judge sirf case file ke pages cite karta hai — file mein nahi hai toh order nahi deta, "insufficient evidence" kehta hai. Aur page number dikhana hi kaafi nahi, us page pe wahi baat likhi honi chahiye:

text
claim  : "refund 7 din mein aata hai"
cite   : [3]  <- page exist karta hai?      FORMAT CHECK
support: page 3 pe "7 business days" likha?  SUPPORT CHECK

page nahi mili -> abstain; page hai par baat alag -> fake citation
Interview angle — yahan se sawaal aate hain
  • Q: Grounding aur citations ka farq? — Citations pointers hain, grounding matlab claims sach mein cited evidence se support hona.
  • Q: Citation contract kaise banaoge? — Numbered context blocks, explicit [n] format, abstain option, parse karke chunk id se map.
  • Q: Fake citations kaise pakdoge? — Format check (id exists) + support check (block actually support karta hai).
  • Q: Kab abstain? — Retrieval score weak, ya context mein jawab absent — dono pe valid "insufficient information" response.
Lesson complete?

Grounding, citations aur abstention clear — ab tumhara RAG trustable hai. Agla lesson — RAG Variants & Advanced Patterns — mein dekhenge baseline fail hone pe kaunsa advanced pattern lagta hai.

Popular courses: Data Science Course in Lucknow · AI Course in Lucknow · Python Course in Lucknow · Power BI Course · Data Analytics Course