Prompt
How do I build RAG over PDFs, wikis, and tickets with citations?
Latest observation
To build RAG over PDFs, wikis, and tickets with citations, think of it as four layers:
- Ingest
- Chunk + enrich
- Retrieve + rank
- Answer with evidence/citations
Below is a practical blueprint.
1) Ingest documents from each source
PDFs
- Extract text with layout awareness if possible.
- Preserve:
- page number
- section heading
- figure/table references
- document title / version
- If PDFs are scanned, run OCR.
Wikis
- Pull page content via API or export.
- Preserve:
- page title
- section headings
- last updated time
- page URL
Tickets
- Ingest the ticket body, comments, resolution, and tags.
- Preserve:
- ticket ID
- subject
- timestamps
- author/assignee
- status
- URL
2) Normalize into one common schema
Convert every source into a shared document format, for example:
{
"doc_id": "unique-id",
"source_type": "pdf|wiki|ticket",
"source_name": "Acme Handbook",
"source_url": "https://...",
"title": "How to Reset Passwords",
"section": "Authentication > Password Reset",
"text": "chunk text here",
"page": 12,
"ticket_id": "INC-1234",
"updated_at": "2026-01-01T10:00:00Z",
"metadata": {
"author": "Jane",
"version": "v3"
}
}
This makes retrieval and citation generation much easier.
3) Chunk the content carefully
Good citations depend on good chunk boundaries.
Best practices
- Chunk by semantic structure:
- headings
- paragraphs
- ticket comment boundaries
- page boundaries for PDFs
- Keep chunks small enough to retrieve precisely, but large enough to retain context.
Typical chunking
- 200–500 tokens per chunk
- 10–20% overlap if needed
- Store chunk IDs and provenance
Example chunk record:
{
"chunk_id": "wiki-456#section-2#chunk-3",
"doc_id": "wiki-456",
"text": "The password reset process requires...",
"citation": {
"source_type": "wiki",
"title": "Password Reset Policy",
"url": "https://wiki.company.com/page/123",
"section": "Process",
"page": null
}
}
4) Index for retrieval
Use at least one of:
- Vector index for semantic search
- Keyword/BM25 index for exact matches
- Often best: hybrid search
Recommended retrieval pipeline
- User query
- Query rewrite/expansion if needed
- Hybrid retrieve top 20–50 chunks
- Rerank with a cross-encoder or LLM reranker
- Select top evidence chunks for generation
Why hybrid?
- PDFs often contain exact terms, codes, IDs
- Wikis are semantic and structured
- Tickets often include noisy but critical phrasing
Hybrid improves recall across all three.
5) Attach citations at the chunk level
Citations should point to the exact retrieved chunk, not just the source document.
For each chunk, keep:
- source type
- document title
- URL
- page number or section
- chunk offset/range if available
- ticket ID if relevant
Example citation format
In the answer:
- “Passwords expire every 90 days. [1]”
- “The rollback procedure is documented in the release wiki. [2]”
Then provide references:
- Acme Security Policy, page 12, “Password Expiration”, PDF
- Release Process Wiki, section “Rollback”, URL
6) Generate answers grounded in evidence
Prompt the model to:
- answer only from retrieved evidence
- cite every factual claim
- say “I couldn’t find that in the sources” if evidence is insufficient
Useful prompt instruction
Use only the supplied context. For every important statement, include one or more citations. If the context does not support the answer, say so.
Safer generation pattern
- First, retrieve evidence.
- Second, have the model draft an answer with inline citations.
- Third, optionally verify citation coverage.
7) Make citations trustworthy
Citations should be:
- traceable: user can open the original source
- specific: page/section/comment, not just doc title
- stable: use immutable IDs where possible
- verifiable: chunk text should match the cited source
Good citation metadata
- PDF: title, page number, page anchor, document version
- Wiki: page title, section heading, URL, revision ID
- Ticket: ticket ID, comment ID, timestamp, URL
8) Handle source-specific quirks
PDFs
- Tables may need special extraction.
- Multi-column layouts can scramble text.
- Use OCR for scans.
- Preserve page numbers.
Wikis
- Some pages are long and poorly structured.
- Use heading-based splitting.
- Track page revisions to avoid stale citations.
Tickets
- Conversation threads can contradict each other.
- Prefer the resolution/accepted answer if present.
- Keep comment timestamps so the model can weigh latest info.
9) Recommended architecture
Simple version
- Ingestion jobs -> document store
- Chunking pipeline -> vector DB
- Retrieval API -> reranker -> LLM answer
More robust version
- Raw source store: S3/GCS
- Metadata DB: Postgres
- Search:
- vector DB (Pinecone, Weaviate, pgvector, Milvus)
- keyword index (Elasticsearch/OpenSearch)
- Reranker
- Citation-aware answer service
- Audit logs for retrieved evidence
10) Minimal implementation checklist
- Extract text from PDFs, wiki pages, tickets
- Normalize metadata into one schema
- Chunk semantically
- Store chunk text + metadata + source pointer
- Build hybrid retrieval
- Rerank results
- Generate answer from retrieved chunks only
- Return inline citations and reference list
- Add source URLs/page numbers/IDs to every chunk
- Test citation accuracy with QA samples
11) Example answer format
Answer:
The password reset policy requires users to verify their identity before resetting a password. Passwords expire every 90 days, and users are notified 7 days before expiry. [1][2]
References:
[1] Security Policy, PDF, page 12, “Password Expiration”
[2] Help Center Wiki, section “Password Reset”, https://wiki.company.com/reset
12) Practical advice on quality
To improve answer quality:
- deduplicate near-identical chunks
- use metadata filters like product, team, date, source type
- prefer latest revision for wikis
- surface source confidence or freshness
- log which chunks were used for each answer
To improve citation quality:
- cite at sentence or clause level when possible
- avoid citing an entire source if only one paragraph was used
- include page/section anchors in the citation object
13) If you want a strong baseline stack
A common setup:
- Parsing: Unstructured, Apache Tika, pdfplumber, OCR engine
- Storage: S3 + Postgres
- Search: Elasticsearch/OpenSearch + vector DB
- Reranker: bge-reranker or a hosted reranker
- LLM: your chosen chat model
- Framework: LlamaIndex or LangChain if you want orchestration
If you want, I can also give you:
- a reference architecture diagram,
- a Python implementation skeleton, or
- a citation format and prompt template for production use.