semantica.provenance tracks the full lineage of every fact: from raw ingestion through extraction, chunking, and relationship building:
  • W3C PROV-O compliant: suitable for HIPAA, SOX, GDPR, FDA 21 CFR Part 11 audit trails
  • SHA-256 checksums for tamper detection on every stored ProvenanceEntry
  • SQLiteStorage for persistence across restarts; InMemoryStorage for development
  • ProvenanceManager provides track_entity, track_relationship, track_chunk, and get_lineage
  • Bridges to W3C PROV-O ontology via BridgeAxiom for semantic web export

Exported Classes

Getting Started

Zero configuration: fast, no disk writes. Use for notebooks, testing, and single-run scripts.
In-memory storage is lost when the process exits. Use SQLiteStorage for anything that needs to survive restarts.

ProvenanceManager

ProvenanceManager is the central tracker for all lineage data. Every call to track_entity, track_relationship, or track_chunk automatically computes and stores a SHA-256 checksum for tamper detection.

Constructor

If both storage and storage_path are omitted, an InMemoryStorage is used.
InMemoryStorage does not persist across restarts. Pass storage_path="provenance.db" or an explicit SQLiteStorage instance in any environment where the audit trail must survive process exits.

Tracking Methods

Batch Tracking

Batch tracking methods process items in blocks (default batch_size=1000) inside a shared transaction per block. Only entities or chunks that successfully commit to storage are added to the returned count, preventing rolled-back entries from inflating success counts.

Retrieving Lineage

get_lineage() returns an aggregated dict, not a ProvenanceEntry. Use trace_lineage() to get the raw ProvenanceEntry objects when you need field-level access such as entry.checksum.

Utility Methods

ProvenanceManager Methods Reference

ProvenanceEntry Fields

ProvenanceEntry is the core dataclass. Every tracking method returns one on success (or None on storage failure):

SourceReference Fields

SourceReference provides a citable pointer to a location within a source document:

Storage Backends

InMemoryStorage

Fast, no persistence. Suitable for development, tests, and short-lived processes:

SQLiteStorage

Persists to disk. Suitable for production, audit trails, and regulatory compliance:
SQLiteStorage creates the database and indexes automatically on first use.
  • Atomicity & Concurrency: Configures Write-Ahead Logging (PRAGMA journal_mode=WAL), PRAGMA busy_timeout=5000, and PRAGMA synchronous=NORMAL. Read-modify-write methods (track_entity(), store()) open a single connection and execute inside an immediate write transaction (BEGIN IMMEDIATE), ensuring these sequences are serialized across concurrent connections without leaving open file handles across calls. Plain reads (retrieve(), trace_lineage()) use a separate connection with no explicit write lock, so concurrent reads don’t serialize behind writers or each other.
  • Backward Compatibility: Custom storage subclasses overriding trace_lineage(self, entity_id) remain backward compatible; ProvenanceManager inspects the override signature and automatically calls it with one argument if max_depth is unsupported.

Tamper-Evident Checksums

compute_checksum and verify_checksum are auto-used by track_entity and all other tracking methods. You can also call them directly:
The checksum covers entity_id, entity_type, activity_id, source_document, timestamp, and confidence.
Run verify_checksum(entry) before any compliance export. Pass the ProvenanceEntry object returned by trace_lineage() directly. If the stored checksum no longer matches, raise an error before the export proceeds.

Bridge Axiom Translation Chains

BridgeAxiom and TranslationChain are available in semantica.provenance.bridge_axiom for tracking multi-layer domain translations with full coefficient attribution:

Integration with GraphBuilder

GraphBuilderWithProvenance (from semantica.kg) automatically records provenance for every node and edge:

Integration with NERExtractor

NERExtractor and other extractors accept provenance=True to embed provenance metadata on each extracted entity. You must track the results manually using ProvenanceManager:
Setting provenance=True on NERExtractor embeds metadata on the extracted entity objects — it does not automatically call ProvenanceManager.track_entity(). You must call track_entity() yourself after extraction.

Common Workflows

Compliance Notes

Provenance tracking in Semantica produces the following audit artifacts:
ProvenanceManager does not include built-in Turtle or JSON-LD serialization. Use entry.to_dict() and get_lineage() to retrieve provenance data, then serialize with your preferred RDF library if W3C PROV-O RDF output is required.
  • Change Management — Version control and snapshot audit trails.
  • Ingest — Provenance begins at the ingestion stage.
  • Export — Include provenance metadata in RDF exports.
  • Context — Decision provenance via AgentContext.