RAG Application Contracts
Provider-neutral document, chunk, evidence, citation, and grounded-answer contracts.
Build and test a production RAG architecture with versioned ingestion, hybrid keyword and vector retrieval, RRF fusion, authorization filtering, reranking, context assembly, citation validation, evaluation metrics, and release gates.

Build and test a production RAG architecture with versioned ingestion, hybrid keyword and vector retrieval, RRF fusion, authorization filtering, reranking, context assembly, citation validation, evaluation metrics, and release gates.
Provider-neutral document, chunk, evidence, citation, and grounded-answer contracts.
Content hashes, source versions, replay safety, upserts, and deletes.
Deterministic chunking interface that emits version metadata.
Provider-neutral document, chunk, evidence, citation, and grounded-answer contracts.
src/contracts.tsContent hashes, source versions, replay safety, upserts, and deletes.
src/ingestion/idempotency.tsDeterministic chunking interface that emits version metadata.
src/ingestion/chunker.tsStable source, chunk, URI, location, version, and authorization metadata.
src/ingestion/provenance.tsDeterministic lexical retrieval abstraction for the local harness.
src/retrieval/keyword.tsVector retrieval abstraction with a deterministic local implementation.
src/retrieval/vector.tsFuse keyword and vector ranked lists with deterministic RRF.
src/retrieval/rrf.tsGenerate lexical/vector candidates and combine them before reranking.
src/retrieval/hybrid.tsTenant and ACL filtering before candidates can enter answer generation.
src/retrieval/authorization.tsReranker interface with a deterministic local scoring implementation.
src/retrieval/reranker.tsDeduplicate, diversify, order, and enforce a context budget while preserving evidence IDs.
src/context/context-builder.tsConstruct citation contracts from retrieved evidence metadata.
src/citations/citation-builder.tsReject citations that do not map to evidence in the current retrieval context.
src/citations/citation-validator.tsProvider-neutral orchestration for filtering, retrieval, fusion, reranking, context assembly, generation, and citation validation.
src/pipeline/rag-pipeline.tsRecall@k, MRR, and nDCG helpers for deterministic retrieval evaluation.
src/eval/retrieval-metrics.tsCitation precision and coverage calculations.
src/eval/citation-metrics.tsFail CI when retrieval, citation, authorization, freshness, latency, or other configured thresholds regress.
src/eval/release-gate.tsCompare keyword, vector, and RRF-fused hybrid retrieval on the same evaluation queries.
Evaluate multiple deterministic chunk configurations on the same source/query set.
Compare fused ranking with deterministic reranking over the same candidate set.
Vary candidate count and context budget while keeping the evaluation corpus fixed.
Use multi-tenant test data and queries that would otherwise match unauthorized content.
Validate citations against retrieved evidence and expected claim-source relationships.
Update and delete source documents, rerun ingestion, and verify serving-index behavior.
git clone https://github.com/sarvab-dev/prodai-stack-labs
cd prodai-stack-labs/production-rag-architecture
npm install
npm test