Knowledge Erasure
Clear, delete, and inspect knowledge with loud, predictable guarantees
Erasure clears an agent’s knowledge base between sessions, with clear errors when an adapter can’t support an operation.
from praisonaiagents import Agent
agent = Agent(name="privacy-aware", instructions="Answer, then clear context between sessions.", knowledge=["policy.md"])
agent.start("Summarise the policy")
agent.knowledge.reset() # clears the knowledge base between sessionsQuick Start
- Reset the knowledge base
python from praisonaiagents import Agent agent = Agent(name="assistant", instructions="Answer from the docs", knowledge=["policy.md"]) agent.start("Summarise the policy") # Clear the knowledge base between sessions agent.knowledge.reset() - Delete all scoped memories
python # Delete everything for a given scope agent.knowledge.delete_all(user_id="user-123") - Inspect change history
python # History is only available on Mem0-backed knowledge changes = agent.knowledge.history(memory_id="mem-abc")
How It Works
Knowledge erasure calls route to the underlying memory adapter. Unsupported operations fail loudly instead of raising AttributeError.
| Operation | Behaviour when unsupported |
|---|---|
reset() | Logs a WARNING, no-ops, and returns False (returns True on a real reset) |
delete_all() | Raises NotImplementedError |
history(memory_id) | Raises NotImplementedError |
Adapter Capabilities
Support differs per adapter — verify against praisonaiagents/knowledge/adapters/ before relying on an operation.
| Operation | Chroma | SQLite | Mongo | Mem0 |
|---|---|---|---|---|
reset() | ✅ | ✅ | ⚠️ warning + no-op | ✅ |
delete_all() | ✅ | ✅ | ❌ NotImplementedError | ✅ |
history(id) | ❌ NotImplementedError | ❌ NotImplementedError | ❌ NotImplementedError | ✅ |
Common Patterns
Guard erasure calls so your code works across adapters:
from praisonaiagents import Agent
agent = Agent(name="assistant", instructions="Answer from the docs", knowledge=["policy.md"])
# reset() never raises — it warns and no-ops on adapters without native reset
agent.knowledge.reset()
# delete_all() / history() may not be supported
try:
agent.knowledge.delete_all(user_id="user-123")
except NotImplementedError:
# Fall back to reset() on adapters without scoped delete
agent.knowledge.reset()Report to users honestly on a destructive path — check the return value before claiming success:
from praisonaiagents import Agent
agent = Agent(name="assistant", knowledge=["policy.md"])
# Never claim success on a destructive path without checking
if agent.knowledge.reset():
print("Knowledge cleared")
else:
backend = type(agent.knowledge.memory).__name__
print(f"Knowledge was NOT cleared — backend {backend} has no reset()")Best Practices
Reset between sessions
Call agent.knowledge.reset() at the end of a session to clear context for privacy-sensitive workflows. reset() returns True when the backend actually reset, and False when the adapter had no reset — it warns and no-ops instead. On destructive paths check the return value before telling a user their data was erased; a False means nothing was cleared.
Wrap delete_all() and history()
Both raise NotImplementedError on adapters that don’t support them. Wrap them in try/except so multi-adapter code degrades gracefully.
Use Mem0 for history
Only Mem0-backed knowledge implements history(memory_id). Choose Mem0 when you need an audit trail of memory changes.
Check logs after upgrade
reset() returns False and logs a warning when the adapter can’t reset. Prefer the return value over log-scraping — it’s a reliable signal that the tier was actually cleared (True) or silently skipped (False).