Cross-Document Consistency Memory¶
director_ai.core.memory.consistency.CrossDocumentConsistencyMemory
¶
CrossDocumentConsistencyMemory(db_path: str | Path = ':memory:', *, score_fn: ConsistencyScoreFn | None = None, use_builtin_similarity: bool = False, warn_threshold: float = 0.65, contradiction_threshold: float = 0.85, max_documents_per_tenant: int = 1000)
SQLite-backed tenant memory for cross-document consistency checks.
Initialise SQLite storage and retention policy settings.
check_document
¶
Evaluate an incoming document against tenant memory.
record_document
¶
record_document(tenant_id: str, document_id: str, text: str, metadata: Mapping[str, Any] | None = None) -> CrossDocumentConsistencyReport
Record a document unless consistency checks block it.
get_document
¶
Return one stored tenant document by identifier.
list_documents
¶
Return stored documents for a tenant in retention order.
count
¶
Return total document count globally or for one tenant.
delete_tenant
¶
Delete all documents for a tenant and return the removed count.
director_ai.core.memory.consistency.CrossDocumentConsistencyReport
dataclass
¶
CrossDocumentConsistencyReport(decision: str, tenant_id: str, document_id: str, incoming_hash: str, checked_documents: int, conflicts: tuple[CrossDocumentConflict, ...] = tuple())
Decision for an incoming document against tenant memory.
to_dict
¶
Serialise the consistency decision for API or audit output.
director_ai.core.memory.consistency.CrossDocumentConflict
dataclass
¶
director_ai.core.memory.consistency.StoredDocument
dataclass
¶
StoredDocument(tenant_id: str, document_id: str, text: str, content_hash: str, created_at: float, metadata: Mapping[str, Any] = dict())
One tenant-scoped document retained for consistency checks.
to_dict
¶
Serialise the stored document with optional raw text.
Tenant and Privacy Model¶
CrossDocumentConsistencyMemory is a SQLite-backed memory for checking whether
a new generated document contradicts earlier documents from the same tenant.
It is intended for long-running agents, support bots, and regulated workflows
where yesterday's answer must stay consistent with today's answer.
- all reads and comparisons are tenant-scoped
- tenant ids are validated against
^[A-Za-z0-9_-]{1,64}$ - blocked reports do not persist the incoming document
- report serialization omits raw text unless
include_text=True delete_tenant()removes retained tenant documents for right-to-delete workflowsmax_documents_per_tenantenforces bounded retention
from director_ai.core import CrossDocumentConsistencyMemory
memory = CrossDocumentConsistencyMemory(
"consistency.sqlite",
score_fn=contradiction_score,
contradiction_threshold=0.85,
)
report = memory.record_document(
tenant_id="tenant-a",
document_id="answer-2026-05-13",
text=response,
)
if report.blocked:
escalate(report.to_dict())
Use an NLI, verified-scorer, or domain verifier as score_fn(previous, incoming).
The memory layer owns storage, tenant isolation, reporting, and retention; it
does not pretend to be a contradiction model by itself.