LEVEL 2 · BUILDER

Document QA With Citations and LangChain

A citation receipt that separates exact source support from relevance to the question. Import query(directory, question, model). A model callback returns JSON {source:chunk_id,quote:exact_text}. --response accepts a recorded response and applies the same gate.

4 stages~8 hoursPythoncore
Load local documents with stable provenanceRank chunks with an inspectable keyword scoreAccept only answers grounded in retrieved spansUse a framework splitter without losing offsets
YOU END UP WITH

A citation receipt that separates exact source support from relevance to the question.

USEFUL FOR
  • Import query(directory, question, model). A model callback returns JSON {source:chunk_id,quote:exact_text}. --response accepts a recorded response and applies the same gate.
LEARN FIRST
  • Python 3.10+
  • pathlib, strings, offsets, dictionaries and callback functions. Optional LangChain dependencies are pinned separately.
WHY THESE LANGUAGES
  • Python Stdlib data structures, explicit algorithms and deterministic local tests.
PROJECT OUTLINE

Document QA With Citations and LangChain in 4 stages

A citation receipt that separates exact source support from relevance to the question.

  1. Load local documents with stable provenance

    The second overlapping chunk of abcdef starts at offset 3 when size=4 and overlap=1.

    starter · ~2 hours · Python

    loadlocaldocumentswith
  2. Rank chunks with an inspectable keyword score

    A socket query selects the socket chunk, while an unknown term abstains.

    core · ~2 hours · Python

    rankchunkswithan
  3. Accept only answers grounded in retrieved spans

    A model response containing words absent from its cited chunk is rejected.

    core · ~2 hours · Python

    acceptonlyanswersgrounded
  4. Use a framework splitter without losing offsets

    Framework chunks are converted to the same source-span contract used by the baseline.

    stretch · ~2 hours · Python

    useaframeworksplitter

All projects · Course catalog · Source on GitHub