SMT / CASE STUDY 04 / 05
Local PDF question answering
Folio
Follow the answer back to the page.
Retrieves passages from a PDF and uses a local language model to answer questions with page references and a supporting quote check.
- Python
- FAISS
- llama.cpp
A cache stores a working copy near the reader.
Replace the cached copy after the source document changes.
01 / Brief
The problem
A fluent answer is difficult to trust if the reader cannot find the underlying passage. PDF question answering needs a way to keep page identity through retrieval and surface the text that supports an answer.
Context and constraints
Folio runs retrieval and inference on the local machine. Its extraction path works with the PDF text layer, so scans without extractable text need OCR before they can contribute searchable passages.
My contribution
I built the local document-answering pipeline, including page-aware retrieval, local inference, and the quote match that connects a claimed quotation to source text.
02 / System
Architecture
PDF ingestion
The extractor reads page text and the chunker carries page numbers into overlapping passages.
Local retrieval
Embeddings and a FAISS index find candidate passages. A local reranker selects context for the question.
Inference and verification
llama.cpp generates the answer. A quote-matching pass checks a proposed excerpt against the source passages.
Core functionality
- Index a document
- Search works over extracted passages, with page references preserved alongside chunk text.
- Answer with context
- The model receives retrieved passages and page labels with the question.
- Inspect verification
- A quote match gives the reader a page and source wording. Weak or absent support can leave the answer unverified.
03 / Engineering
Decisions and evidence
Separate generating an answer from checking the quote
Generation can paraphrase or make mistakes. Comparing the proposed quote with extracted source text gives a narrower, inspectable check. It establishes a passage match, while judging the broader answer still requires reading the evidence.
Observed in source or example
Verify a passage against a real page
The controlled example extracts the original two-page sample and matches the cache sentence on page 1. An unrelated sentence returns no match. This check exercises extraction and quote matching with supplied text.
Revisit the evidence plate04 / References