Mental model
Every indexed text chunk in an enterprise AI system should operate as an auditable evidence artifact rather than an anonymous string in RAM. Provenance binds each retrievable unit cryptographically and structurally to its authoritative origin (source_id, immutable content_sha256, revision), exact transformation toolchain (parser_version, chunker_version, embedding_model), authorized access group, and retrieval/generation decision trace.
Learning outcomes
- Model complete
Entity->Activity->Agentlineage chains grounded cleanly in the W3C PROV data model across RAG pipelines. - Distinguish mutable public URLs from immutable content-addressed source snapshots and chunk coordinates needed for historical audit replay.
- Propagate source corrections, revocations, and re-chunking schema upgrades cleanly without leaving silent orphan versions active.
Theory
When a compliance reviewer inspects why an AI assistant cited an outdated HR limit six months ago, pointing vaguely at "https://docs.company.com/hr" fails completely if that webpage updated four times since the answer generated! Applying W3C PROV (Entity: stored document/chunk; Activity: OCR/parse/chunk/embed job; Agent: ingestion pipeline service or owner team) records exact deterministic transformations cleanly end to end:
| Lineage Layer | Mandatory Metadata Fields | What Question It Answers During Incident Review |
|---|---|---|
Source Origin (SourceEntity) | source_id, canonical_uri, doc_revision, content_sha256, owner_group | Exactly which file bytes and revision backed the retrieved quote? |
Transformation (TransformActivity) | ingestion_run_id, parser_version, chunker_version, embedding_model_id | Which parser/splitter/model version created this index slice? |
Indexed Chunk (ChunkEntity) | chunk_id, char_offset_span, section_breadcrumb, acl_epoch, verified_at | Where inside the doc did the span originate, and who could read it? |
Inference Ledger (ClaimDerivation) | prompt_packet_id, retrieved_chunk_ids[], cited_span_ids[], policy_sha | Which exact packet context generated and validated the final user claim? |
Crucially, recording only ingestion timestamps leaves regressions untraceable whenever teams swap PDF extractors (pypdf -> unstructured) cleanly without changing document source hashes. Stamping parser_version and ingestion_run_id inside every indexed chunk lets engineers compare search quality cleanly across extraction builds and selectively purge corrupted runs cleanly by ingestion_run_id.
pythonimport hashlibfrom dataclasses import dataclass@dataclass(frozen=True)class ProvenanceRecord:chunk_id: strsource_id: strsource_revision: strsource_sha256: stringestion_run_id: strparser_version: strembedding_model: stracl_epoch: intchar_start: intchar_end: intdef create_prov_chunk_record(source_id: str,source_revision: str,raw_doc_bytes: bytes,char_start: int,char_end: int,ingestion_run_id: str,parser_version: str,embedding_model: str,acl_epoch: int,) -> ProvenanceRecord:"""Bind chunk coordinates cryptographically to source digest, toolchain, and ACL epoch."""source_sha = hashlib.sha256(raw_doc_bytes).hexdigest()seed = f"{source_id}:{source_revision}:{source_sha[:12]}:{parser_version}:{char_start}:{char_end}"chunk_id = hashlib.sha256(seed.encode()).hexdigest()[:24]return ProvenanceRecord(chunk_id=chunk_id,source_id=source_id,source_revision=source_revision,source_sha256=source_sha,ingestion_run_id=ingestion_run_id,parser_version=parser_version,embedding_model=embedding_model,acl_epoch=acl_epoch,char_start=char_start,char_end=char_end,)
Trade-offs
Full transformation-level provenance (source digest + parser build + span offsets + packet snapshot) makes regulatory audits, selective re-indexing on PDF bugs, and causal regression tracking nearly effortless across complex enterprises, adding modest metadata storage (~150–300 bytes per chunk + append-only snapshot refs). Lightweight snapshot-only versioning cuts metadata plumbing on small low-risk public FAQ sites, yet fails cleanly under financial, legal, or medical compliance audits where proving exact historical bytes shown to the model months ago is mandatory.
Failure modes and misconceptions
- Assuming URLs Are Immutable Identifiers: Live corporate docs and external specifications mutate silently at identical URLs without breaking links while changing policy numbers completely.
- Confusing Metadata Presence With Access Control: Attaching
"visibility: restricted"labels onto chunks without filtering queries cleanly before reranking exposes protected text to generators anyway. - Overwriting Revisions In-Place Without Lineage History: Deleting old chunk records silently without keeping archived digest manifests breaks post-incident replay completely.
- Omitting Ingestion Toolchain Versions: Shipping a buggy PDF table parser into production without tagging
parser_versionforces blind full-corpus wipes instead of targeted run rollbacks.
Decision scenario
A regulatory policy assistant answers audit questions across 12,000 quarterly compliance bulletins. Last month's PDF table parser upgrade silently dropped column headers on multi-page Annexes, and legal auditors now demand exact traceability from historical chat outputs back to exact bulletin revisions. Design W3C-PROV-aligned chunk lineage fields, ingestion_run_id tagging, and non-destructive revision invalidation cleanly.
Which lineage identifiers must travel with a retrieved chunk so an auditor can deterministically reproduce why an AI claim appeared six months later?