HackIndia Logo
HackathonsNewsSkillsGrowth
HackIndia LogoContact: +91 9910125804

General

  • Companies
  • Colleges
  • Board of Advisors
  • Brand Ambassadors
  • FAQ
  • Contact
  • Report a Bug

Hackathons

  • Upcoming Hackathons
  • Judges
  • Mentors
  • Partners
  • Participating Colleges

Resources

  • About Us
  • Branding
  • Latest News
  • Growth
  • Skills
  • Ecosystem
  • Forum
  • Ideas
  • Prompt Optimizer

© 2026 HackIndia. All rights reserved.

Privacy PolicyTerms of ServiceCode of ConductSitemap
    HackIndia
    HackathonsNewsInternshipsSkillsGrowth
    ← RAGLesson 5 of 7 5 min

    RAG

    Cite sources users can verify

    • +10 XP for this lesson
    • +100 XP when the skill is proved
    • Nobody here has proved it yet
    In 30 seconds
    • Return answers with citations that point to exact document chunks.
    • Store source metadata during retrieval so users can verify claims.
    • Add a simple citation format to your app and sample answers.
    Key point

    One rule

    A citation is useful only if a user can find the same evidence again. Cite the retrieved chunk, not the model’s memory or a vague file name.

    For this track, a good citation has document name, page or section if available, and a chunk id or quoted line.

    What to cite

    Your answer should cite every important factual claim that comes from the documents. If the answer has three facts from two chunks, show both sources.

    Do not cite general filler like “based on the documents”. Cite claims such as dates, fees, eligibility, deadlines, policy rules, product limits, and names.

    ← Lesson 4Skip to lesson 6 →
    Working towards
    RAG +100 XP

    0 of 7 lessons done · proved by a submitted project with a public repository

    See the track
    Your to-do

    Keep source metadata

    Do each one yourself, then tap it to tick it off. The ticks are only a checklist for you: they are not marked or scored.

    0 of 5 done

    Example

    Chunk record example

    This is the kind of record your vector index should return. The exact database can change. The idea stays the same: text plus metadata.

    {
      "id": "fee_policy_p2_c1",
      "text": "Students can pay semester fees by UPI, net banking, or demand draft. Late payment after 15 August has a fine of Rs 500.",
      "metadata": {
        "source": "college_fee_policy.pdf",
        "page": 2,
        "section": "Payment modes"
      }
    }
    Example

    Prompt for citations

    Ask the model to use only the retrieved evidence and to cite source ids inline. Keep the citation format simple so you can test it later.

    You are answering questions using only the evidence below.
    If the evidence does not contain the answer, say: I don’t know from the provided documents.
    For every factual claim, add a citation in this format: [source: id, page].
    
    Evidence:
    1. id: fee_policy_p2_c1, source: college_fee_policy.pdf, page: 2
    Text: Students can pay semester fees by UPI, net banking, or demand draft. Late payment after 15 August has a fine of Rs 500.
    
    Question: Can I pay fees using UPI? What happens if I pay late?
    
    Answer:
    Example

    Answer users can verify

    A useful answer is not just correct. It tells the user where to check it.

    For your repo, save a few example questions and cited answers. Recruiters should be able to open the sample document and verify the citation.

    Yes. You can pay semester fees using UPI, net banking, or demand draft [source: fee_policy_p2_c1, page 2]. If you pay after 15 August, the late fine is Rs 500 [source: fee_policy_p2_c1, page 2].
    Common mistake

    Avoid fake citations

    A common bug is letting the model invent file names or page numbers. Do not ask the model to create citations from memory.

    Give it the exact citation labels in the evidence. Then tell it to cite only those labels. After generation, check that every cited id exists in the retrieved chunks.

    Tip

    Add a verifier

    Before showing the answer, run a small check in code. Extract citation ids from the answer and confirm they are in the retrieved result ids.

    This does not prove the answer is fully grounded. Lesson 6 handles evaluation. But it catches many broken citations.

    import re
    
    retrieved_ids = {"fee_policy_p2_c1", "hostel_rules_p1_c3"}
    answer = "You can pay by UPI [source: fee_policy_p2_c1, page 2]."
    
    cited_ids = set(re.findall(r"source:\s*([a-zA-Z0-9_\-]+)", answer))
    missing = cited_ids - retrieved_ids
    
    if missing:
        raise ValueError(f"Answer cites sources not retrieved: {missing}")
    Your to-do

    Do this now

    Do each one yourself, then tap it to tick it off. The ticks are only a checklist for you: they are not marked or scored.

    0 of 5 done

    Quick check

    0 of 2 right
    1.Your answer says the late fee is Rs 500. What should the citation point to?
    2.A model cites hostel_rules_p9_c4, but that id was not retrieved. What should your app do?

    Answer the quick check to finish this lesson.