ier** | Mem0: 10K memories. Zep: 1,000 credits. | 500 memories, full governance. | Governance features are available immediately, not gated. |
Why this matters: If your compliance officer asks, "What happens to the data?" and your architecture cannot answer with infrastructure guarantees, you are carrying unquantified regulatory risk. Retrieval-first tools require you to build governance on top of them. Governance-first tools provide the guarantees natively.
Core Solution
Implementing AI memory requires selecting an architecture pattern that aligns with your risk tolerance. Below are the implementation patterns for each approach, rewritten to demonstrate the structural differences.
Pattern 1: Retrieval-First Extraction (Mem0 Equivalent)
This pattern focuses on extracting facts and storing them in a vector store. The application is responsible for all governance.
import { FactExtractionClient } from '@ai-memory/standard';
const memoryClient = new FactExtractionClient({
apiKey: process.env.MEMORY_API_KEY,
// Ecosystem integrations: LangChain, CrewAI, AWS Bedrock, etc.
});
async function ingestUserContext(userId: string, rawInput: string) {
// 1. LLM extracts key facts from rawInput.
// 2. Facts are embedded and stored in vector DB.
// 3. Conflicts are resolved based on recency.
await memoryClient.ingest({
userId,
content: rawInput,
// Note: rawInput is processed as-is.
// No PII scan. No TTL. No audit log generated by the client.
});
}
// Usage:
// ingestUserContext("user_123", "My SSN is 078-05-1120 and I prefer dark mode.");
// Result: SSN is stored in the vector store.
// Governance gap: PII persists; no expiration; no access log.
Rationale: Use this when retrieval speed, ecosystem breadth, and personalization are the primary drivers. The trade-off is that governance must be implemented in application code, which introduces latency and error surfaces.
Pattern 2: Temporal Knowledge Graph (Zep Equivalent)
This pattern models facts as nodes with validity windows, enabling temporal reasoning.
import { TemporalGraphEngine } from '@ai-memory/graphiti';
const graphEngine = new TemporalGraphEngine({
apiKey: process.env.ZEP_API_KEY,
// Graphiti engine handles temporal validity.
});
async function updateEntityFact(entityId: string, property: string, value: string, validUntil: string) {
// 1. Creates or updates a node in the knowledge graph.
// 2. Sets validity window (start/end time).
// 3. Old facts are invalidated, not deleted, preserving history.
await graphEngine.upsertNode({
entityId,
property,
value,
validUntil,
// Note: Temporal graph retains history.
// No PII scan. No TTL. No audit log.
});
}
// Usage:
// updateEntityFact("alice", "role", "Project Lead", "2024-12-31");
// Result: Graph node created with validity window.
// Governance gap: History is immutable; PII may persist in invalidated nodes;
// Self-hosting requires Graphiti + graph DB ops (Community Edition deprecated April 2025).
Rationale: Use this when agents must reason about how facts change over time (e.g., "What was Alice's role last quarter?"). The trade-off is operational complexity for self-hosting and the lack of governance controls.
Pattern 3: Governance-First Secure Storage (Trace Continuity Equivalent)
This pattern enforces compliance at the infrastructure layer before data persists.
import { CompliantMemoryService } from '@ai-memory/governance';
const secureMemory = new CompliantMemoryService({
apiKey: process.env.TC_API_KEY, // API key is scoped to a specific tenant.
// Governance actions are automatic.
});
async function storeSecureRecord(agentId: string, payload: string, retentionDays: number) {
// 1. PII scan runs pre-storage. 15+ types detected and redacted.
// 2. Redacted text is stored. Original PII never touches the DB.
// 3. TTL is enforced at infrastructure level.
// 4. Immutable audit event logged: Agent, Tenant, Timestamp, Action, Redactions.
const result = await secureMemory.write({
agentId,
content: payload,
ttlDays: retentionDays,
// Governance guarantees are intrinsic to the API call.
});
return {
recordId: result.id,
auditId: result.governanceEventId,
redactions: result.piiRedacted // e.g., ["SSN", "NAME"]
};
}
// Usage:
// const res = await storeSecureRecord("intake-bot", "Patient John Smith (SSN 078-05-1120) prefers morning appointments.", 365);
// Result: Stored text: "Patient [REDACTED] prefers morning appointments."
// Governance: PII never stored. TTL set to 365 days. Audit log created.
// Isolation: API key ensures tenant boundary. Mismatch returns 403.
Rationale: Use this when compliance is non-negotiable. The architecture eliminates the gap between application logic and data protection. Governance is not a feature you add; it is the environment in which the API operates.
Pitfall Guide
-
Namespace Leakage in Multi-Tenancy
- Explanation: Retrieval tools like Mem0 use
user_id or app_id for isolation. If the application passes an incorrect ID due to a bug, data can leak across tenants.
- Fix: Use architecture-level isolation where the API key itself is scoped to a tenant. A mismatch should result in a hard 403 rejection, not a filtered result.
-
The "Clean Later" Fallacy
- Explanation: Some teams plan to redact PII after storage. This is insufficient for regulations like GDPR or HIPAA, which prohibit storing sensitive data without consent or necessity.
- Fix: Implement pre-storage redaction. The original text must never reach the database. Governance-first tools scan and redact during the write path.
-
Retention Drift
- Explanation: Without infrastructure-level TTL, retention relies on application scripts to delete old memories. These scripts fail, are skipped during deployments, or miss edge cases, leading to data hoarding.
- Fix: Configure TTL at the storage layer. Memories should auto-expire based on policy, regardless of application state.
-
Temporal Graph vs. Right to be Forgotten
- Explanation: Zep's Graphiti invalidates facts but retains history for temporal reasoning. In regulated contexts, retaining invalidated PII may violate deletion requests.
- Fix: Evaluate whether temporal history is legally permissible. If not, ensure PII is redacted before graph ingestion, or use a governance tool that supports cryptographic deletion of sensitive nodes.
-
Audit Blindness
- Explanation: When auditors request access logs ("Show me every time an agent read patient records last quarter"), retrieval tools have no data to provide.
- Fix: Deploy infrastructure that generates immutable audit events for every read, write, and delete. Logs must include agent ID, tenant, timestamp, and action type.
-
Self-Hosting Operational Overhead
- Explanation: Zep's Community Edition was deprecated in April 2025. Self-hosting now requires managing Graphiti and a graph database, increasing operational burden.
- Fix: Factor in DevOps costs for self-hosted solutions. Managed services reduce operational risk but require trust in the vendor's security posture.
-
Graph Memory Cost Surprises
- Explanation: Mem0's graph memory is gated behind the Pro tier at $249/mo. Teams evaluating the free tier may underestimate costs when scaling to graph features.
- Fix: Review pricing tiers early. Governance tools like Trace Continuity include governance features at all tiers, avoiding feature-gating surprises.
Production Bundle
Action Checklist
Decision Matrix
| Scenario | Recommended Approach | Why | Cost Impact |
|---|
| Consumer App / Personalization | Retrieval-First (Mem0) | Fastest onboarding, broad ecosystem, low cost. Governance not required. | Low ($19/mo entry). |
| Temporal Research / Knowledge Graph | Graphiti Engine (Zep) | Superior temporal reasoning (63.8% LongMemEval). Facts evolve over time. | Medium/High (Ops overhead, usage-based). |
| Healthcare / Fintech / Gov | Governance-First (Trace Continuity) | Compliance mandates PII redaction, audit logs, and retention control. | Higher ($99/mo entry), but risk reduction justifies cost. |
| Regulated Enterprise with Graph Needs | Governance-First + Vector | Governance is non-negotiable. Vector search suffices for most compliance use cases. | Enterprise pricing with BAA. |
Configuration Template
Use this template to configure governance policies in a compliance-first architecture.
{
"governance_config": {
"pii_redaction": {
"enabled": true,
"types": ["SSN", "CC", "DOB", "NAME", "EMAIL", "PHONE", "IP_ADDRESS"],
"action": "REDACTE_PRE_STORAGE"
},
"retention": {
"default_ttl_days": 90,
"max_ttl_days": 365,
"auto_purge": true
},
"audit": {
"enabled": true,
"events": ["READ", "WRITE", "DELETE", "REDACT"],
"immutable": true,
"export_format": "JSON"
},
"isolation": {
"model": "API_KEY_SCOPED",
"enforcement": "HARD_REJECT_403"
}
}
}
Quick Start Guide
- Provision Tenant: Create a tenant in the governance console. Receive an API key scoped to that tenant.
- Set Policies: Configure PII redaction rules and TTL policies via the dashboard or config file.
- Write Test Record: Call the
write endpoint with test data containing PII. Verify redaction in the response.
- Verify Audit: Check the audit log for the write event. Confirm PII types are logged as redacted.
- Deploy Agent: Integrate the secure memory client into your agent workflow. Governance is now enforced automatically.