GitHub
Cookbook

Ingestion Governance

Implement a quality assurance layer to filter noise, protect PII, and ensure fact accuracy.

Domain: Healthcare / FinTech
Key Concepts: Validation, Confidence Scores, PII Redaction

Problem Statement

Most memory systems act as "Hoarders," saving everything a user says. This is dangerous. If a user says "I think I might be allergic to peanuts," a naive system saves it as a fact. In regulated industries (Healthcare, Finance), we need a Governance Layer to reject speculation and redact PII.

Architecture: The Ingestion Gate

Implementation Steps

1. Defining Extraction Policies

We can pass Instructions to the ingestion pipeline. These act as a "System Prompt" for the memory extractor.

# Define a strict medical policy
MEDICAL_POLICY = """
RULES:
1. Only extract medical conditions that are EXPLICITLY diagnosed.
2. Ignore phrases like "I think", "maybe", or "possibly".
3. REDACT all Social Security Numbers and Credit Card numbers.
"""
# User speculates
client.memory.add_interaction(
user_id="patient_123",
text="I feel like I might have the flu.",
instructions=MEDICAL_POLICY
)
# Result: Zero facts extracted (Ignored due to Rule 2)

2. Confidence Gating

The SDK provides confidence scores for every extraction. We can filter out low-confidence facts to keep the graph clean.

# Process an interaction and get candidate facts
candidates = client.memory.extract_candidates(
text="My doctor prescribed 10mg of Lisinopril last year."
)
for fact in candidates:
print(f"Fact: {fact.content} | Score: {fact.confidence}")
# Gating Logic
if fact.confidence > 0.85:
client.memory.commit(fact)
else:
print("Discarding low confidence fact.")

3. State Mutation (Deduplication)

If a fact changes (e.g., dosage increase), we should Update the existing memory, not append a new one.

# Existing: "Takes 10mg Lisinopril"
new_input = "I'm upping my dosage to 20mg."
# The system detects the semantic collision
client.memory.ingest(
text=new_input,
user_id="patient_123",
interaction_mode="update" # vs "append"
)
# Result: The original node is updated to "20mg", keeping the graph clean.

Summary

Ingestion Governance transforms your agent from a passive listener into an active curator of its own memory. This is essential for building Trustworthy systems that don't hallucinate based on bad data.