Retrieval-Augmented Generation
Contract and corpus
Define users/questions, answer/citation requirements, freshness, latency/cost, permissions, deletion, languages, and failure policy. Inventory source ownership, formats, versioning, sensitive data, access controls, and update cadence. Do not index content the application is not authorized to reveal.
Pipeline
- Parse deterministically and preserve source ID, version/hash, page/section/line, title, ACL, and timestamps.
- Chunk on semantic/structural boundaries with limited overlap; keep tables/code and parent context intentionally.
- Build a lexical baseline. Add embeddings only when evaluation shows benefit; keep backend/model configurable and record exact versions.
- Filter by authorization before retrieval and again before answer assembly.
- Retrieve bounded candidates, combine lexical/semantic ranks when useful, rerank a small set, diversify duplicates, and pass only relevant evidence.
- Instruct the answer layer to use provided evidence, cite source IDs/ranges, distinguish inference, and abstain when support is insufficient.
- Incrementally update by content hash and remove stale/deleted chunks and caches.
External embedding/vector/reranking services require authorization and a privacy/retention review. Do not install infrastructure or send private corpora outside the approved boundary automatically.
Evaluation
Create labeled queries with relevant sources and expected abstentions. Measure retrieval recall@k/MRR or nDCG, citation correctness, answer support, unsupported-claim rate, ACL leakage, freshness, latency, cost, and failure recovery. Compare no-retrieval, lexical, semantic, and hybrid baselines. Test injection inside documents, conflicting sources, stale updates, deleted documents, and permission changes.
Completion report
Document corpus/provenance, parser/chunker, index and versioning, ACL/deletion, retrieval/reranking, prompt/output contract, evaluation results, observability, deployment/rollback, and unresolved coverage.
1---2name: rag-implementation3description: Design, implement, and evaluate retrieval-augmented generation with traceable ingestion, privacy-aware indexing, hybrid retrieval, grounded answers, and.4license: MIT5---67# Retrieval-Augmented Generation89## Contract and corpus1011Define users/questions, answer/citation requirements, freshness, latency/cost, permissions, deletion, languages, and failure policy. Inventory source ownership, formats, versioning, sensitive data, access controls, and update cadence. Do not index content the application is not authorized to reveal.1213## Pipeline14151. Parse deterministically and preserve source ID, version/hash, page/section/line, title, ACL, and timestamps.162. Chunk on semantic/structural boundaries with limited overlap; keep tables/code and parent context intentionally.173. Build a lexical baseline. Add embeddings only when evaluation shows benefit; keep backend/model configurable and record exact versions.184. Filter by authorization before retrieval and again before answer assembly.195. Retrieve bounded candidates, combine lexical/semantic ranks when useful, rerank a small set, diversify duplicates, and pass only relevant evidence.206. Instruct the answer layer to use provided evidence, cite source IDs/ranges, distinguish inference, and abstain when support is insufficient.217. Incrementally update by content hash and remove stale/deleted chunks and caches.2223External embedding/vector/reranking services require authorization and a privacy/retention review. Do not install infrastructure or send private corpora outside the approved boundary automatically.2425## Evaluation2627Create labeled queries with relevant sources and expected abstentions. Measure retrieval recall@k/MRR or nDCG, citation correctness, answer support, unsupported-claim rate, ACL leakage, freshness, latency, cost, and failure recovery. Compare no-retrieval, lexical, semantic, and hybrid baselines. Test injection inside documents, conflicting sources, stale updates, deleted documents, and permission changes.2829## Completion report3031Document corpus/provenance, parser/chunker, index and versioning, ACL/deletion, retrieval/reranking, prompt/output contract, evaluation results, observability, deployment/rollback, and unresolved coverage.