Document QnA
Extract a document once with ARVA OCR, then ask questions over the markdown with a SAGE model. This guide covers the pipeline, chunking, citations, and follow-up turns.
In this guide
- Extract with ARVA and ask with SAGE using grounded prompts
- Chunk 100+ page documents with per-page ask and merge
- Add page-number citations from OCR blocks
- Run follow-up turns and a Nepali invoice example
Extract once, ask many times
Run OCR a single time and reuse the markdown for every question. This keeps answers consistent and avoids paying for repeated extraction.
Keep the system prompt strict so the model answers only from the document. Pass the markdown as context in the user message, then ask a focused question.
For schemas and auth details, see OCR Process and Chat Completions.
Chunk 100+ page documents
Large PDFs overflow context when sent whole. Ask per page or per section, then merge the partial answers with a final SAGE call.
A practical pattern is 1 to 5 pages per chunk, with a short overlap for tables that span pages. Keep each chunk self-contained by prefixing it with the document title and page range.
Use sage-2-5-celer for the fast per-page sweep and sage-2-4-actus for the merge when accuracy matters. For background jobs over many files, see Batch.
Cite pages and handle follow-ups
Readers trust answers with page numbers. Request OCR with bounding boxes, keep the blocks array alongside the markdown, then ask the model to cite the page it used.
For follow-up turns, reuse the same extracted context instead of re-running OCR. Append the prior answer to the message history so pronouns like "that total" still resolve.
If a follow-up drifts off-topic, restate the boundary in the system message and ask the user to upload a new source. See Build an agent for memory patterns.
Nepali invoice example
A Kathmandu supplier sends a two-page Nepali invoice to Aarav Sharma for Rs. 24,500 including VAT. You need the total, PAN, and invoice date with citations.
Expected shape: कुल रकम: Rs. 24,500 (Page 1) plus PAN and date lines. If VAT and subtotal disagree, ask a second pass to show the arithmetic. Related cookbook: Invoice extraction.
Best practices
- Extract once at 300 DPI markdown, then reuse the text for all turns.
- Keep the system prompt grounded: answer only from the document or say it is missing.
- Chunk by pages for 100+ page docs, then merge with a dedicated call.
- Persist
blockswith page numbers so every answer can cite its source. - Prefer
sage-2-5-celerfor sweeps andsage-2-4-actusfor final answers. - Re-extract when confidence is low instead of forcing an answer from noise.
