Enterprise API¶
Multi-tenant scoring isolation, declarative policy rules, and audit logging. These modules are lazy-loaded — importing director_ai does not pull them in until accessed.
TenantRouter¶
Isolates scoring configuration per tenant. Each tenant gets its own CoherenceScorer instance with independent thresholds, knowledge bases, and caching.
from director_ai.enterprise import TenantRouter
router = TenantRouter()
router.register("tenant_a", threshold=0.7, use_nli=True)
router.register("tenant_b", threshold=0.5, use_nli=False)
scorer = router.get_scorer("tenant_a")
approved, score = scorer.review(query, response)
Policy¶
Declarative rule engine for content filtering. Runs before coherence scoring.
from director_ai.enterprise import Policy
policy = Policy(rules=[
{"pattern": r"(buy|sell|short)\s+(stock|shares)", "action": "reject"},
{"pattern": r"\b(SSN|social security)\b", "action": "redact"},
])
result = policy.evaluate(response_text)
if result.rejected:
print(f"Policy violation: {result.rule}")
AuditLogger¶
SQLite-backed audit logging for compliance. Records every review decision with full context.
from director_ai.enterprise import AuditLogger
logger = AuditLogger(log_dir="/var/log/director-ai/audit")
logger.log(query, response, score, approved=True)
# Query audit trail
entries = logger.query(tenant_id="tenant_a", since="2026-01-01")
License Matrix¶
| Use Case | License Required |
|---|---|
| Open-source project | AGPL-3.0 (free) |
| Internal tools | AGPL-3.0 (free) |
| SaaS product | Commercial license |
| Proprietary embedding | Commercial license |
See Licensing for pricing and terms.
Full API¶
director_ai.core.tenant.TenantRouter
¶
Routes requests to tenant-isolated GroundTruthStores.
Thread-safe: stores are created lazily on first access. Supports per-tenant fine-tuned model selection.
get_store
¶
Get or create an isolated store for this tenant.
add_fact
¶
Add a fact to a specific tenant's store.
remove_tenant
¶
Remove a tenant and all its data. Returns True if existed.
get_vector_store
¶
Get or create a tenant-isolated VectorGroundTruthStore.
Supported backend_type values: "memory", "chroma", "pinecone", "qdrant". Extra kwargs are forwarded to the backend constructor.
set_model
¶
set_model(tenant_id: str, model_id: str, model_path: str, balanced_accuracy: float = 0.0, regression_pp: float = 0.0, recommendation: str = '', dataset_hash: str = '') -> ModelVersion
Register a fine-tuned model for a tenant.
activate_model
¶
Activate a specific model version for a tenant. Deactivates others.
rollback_model
¶
Deactivate all models for a tenant (revert to baseline).
get_active_model
¶
Return the active model for a tenant, or None for baseline.
list_models
¶
List all model versions for a tenant.
delete_model
¶
Remove a model version. Cannot delete active models.
get_scorer
¶
Build a CoherenceScorer scoped to this tenant's KB and model.
save_manifest
¶
Save all tenant model metadata to a JSON manifest.
load_manifest
¶
Load tenant model metadata from a JSON manifest. Returns count loaded.
director_ai.core.safety.audit.AuditLogger
¶
AuditLogger(path: str | Path | None = None, logger_name: str = 'DirectorAI.Audit', hmac_secret: str | None = None)
Structured audit logger with file and logging sinks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path | None — JSONL file path. None = logging-only.
|
|
None
|
logger_name
|
str — Python logger name for audit events.
|
|
'DirectorAI.Audit'
|
add_sink
¶
Add an external consumer for audit records (e.g. PostgresAuditSink).
log_review
¶
log_review(query: str, response: str, approved: bool, score: float, h_logical: float = 0.0, h_factual: float = 0.0, policy_violations: list[str] | None = None, tenant_id: str = '', halt_reason: str = '', latency_ms: float = 0.0) -> AuditEntry
Record a review decision.