Knowledge vs Memory vs Context vs RAG
Understand the four key information systems in PraisonAI and when to use each
Understanding how agents access and store information is key to building effective AI applications.
Quick Comparison
| Aspect | Context | Memory | Knowledge | RAG |
|---|---|---|---|---|
| What | Runtime data flow | Persistent storage | Pre-loaded docs | Search technique |
| When | During execution | Across sessions | Before execution | Query time |
| Lifetime | Session only | Permanent | Permanent | N/A |
| Direction | Read-only | Read + Write | Read-only | Read-only |
| Agent Param | context= | memory= | knowledge= | Part of knowledge |
| Dependencies | None | None (file) | chromadb | chromadb |
The Four Concepts Explained
1. Context = Runtime Data Flow
What it is: Data passed between agents during a single workflow execution.
from praisonaiagents import Agent, AgentTeam
researcher = Agent(
name="Researcher",
instructions="Research the topic"
)
writer = Agent(
name="Writer",
instructions="Write based on research"
)
# Context flows automatically: Researcher → Writer
team = AgentTeam(
agents=[researcher, writer],
process="sequential"
)
result = team.start("Write about AI")
# Context is LOST after this completes2. Memory = Persistent Learning
What it is: Information stored and recalled across sessions. The agent “remembers”.
from praisonaiagents import Agent
# Session 1: Agent learns
agent = Agent(
name="Assistant",
instructions="Remember user preferences",
memory=True # Enable persistent memory
)
agent.start("I prefer dark mode and formal responses")
# Session 2 (later): Agent recalls
agent = Agent(
name="Assistant",
instructions="Remember user preferences",
memory=True
)
agent.start("What are my preferences?")
# Agent remembers: "dark mode and formal responses"3. Knowledge = Pre-loaded Documents
What it is: Reference documents loaded before the agent runs. Static information.
from praisonaiagents import Agent
agent = Agent(
name="Support Agent",
instructions="Answer questions using the documentation",
knowledge=["docs/manual.pdf", "docs/faq.txt"]
)
# Agent searches knowledge to answer
agent.start("How do I reset my password?")4. RAG = Retrieval Augmented Generation
What it is: A technique (not a separate system) that powers Knowledge search.
from praisonaiagents import Agent, KnowledgeConfig
agent = Agent(
name="RAG Agent",
instructions="Answer using the knowledge base",
knowledge=KnowledgeConfig(
sources=["docs/"],
retrieval_k=5, # Return top 5 chunks
rerank=True, # Rerank for relevance
chunking_strategy="semantic"
)
)Decision Tree: Which to Use?
When to Use What
Use for: Agent-to-agent data flow, tool results, single-session workflows
Don’t use for: Anything that needs to persist
MemoryUse for: User preferences, conversation history, learning over time
Don’t use for: Large document collections
KnowledgeUse for: Reference docs, manuals, FAQs, static information
Don’t use for: Dynamic data that changes frequently
RAGUse for: Semantic search over large documents
Note: This is a technique, not a separate param
Agent Parameters Summary
from praisonaiagents import Agent, MemoryConfig, KnowledgeConfig
agent = Agent(
name="Complete Agent",
instructions="You are a helpful assistant",
# CONTEXT: Auto-enabled when using AgentTeam
# Manages token limits, deduplication, summarization
context=True, # or ManagerConfig for advanced settings
# MEMORY: Persistent storage across sessions
memory=MemoryConfig(
session_id="user-123",
user_id="user-123",
backend="file", # file, sqlite, redis, postgres
auto_memory=True, # Auto-extract important info
),
# KNOWLEDGE: Pre-loaded documents with RAG
knowledge=KnowledgeConfig(
sources=["docs/"],
retrieval_k=5,
rerank=True,
),
)Parameter Quick Reference
| Parameter | Type | Description |
|---|---|---|
context=True | bool | Enable context management |
context=ManagerConfig(...) | ManagerConfig | Custom context settings |
memory=True | bool | Enable file-based memory |
memory={"session_id": "..."} | dict | Memory with session |
memory=MemoryConfig(...) | MemoryConfig | Full memory config |
knowledge=["file.pdf"] | list | Simple knowledge sources |
knowledge=KnowledgeConfig(...) | KnowledgeConfig | Full knowledge config |
Using All Together
The most powerful pattern combines all three:
from praisonaiagents import Agent, AgentTeam, MemoryConfig
# Agent with Knowledge + Memory
support_agent = Agent(
name="Support",
instructions="Answer questions using docs. Remember user issues.",
knowledge=["docs/manual.pdf"], # Pre-loaded reference
memory=MemoryConfig( # Persistent learning
session_id="support-session",
auto_memory=True
)
)
# Agent receives Context from support_agent
escalation_agent = Agent(
name="Escalation",
instructions="Handle complex issues based on support findings"
)
# Context flows between agents in workflow
team = AgentTeam(
agents=[support_agent, escalation_agent],
process="sequential"
)
result = team.start("My account is locked")Performance Comparison
| System | Setup Time | Query Time | Dependencies | Storage |
|---|---|---|---|---|
| Context | 0ms | 0ms | None | Memory only |
| Memory (file) | 0ms | 1-5ms | None | JSON files |
| Memory (sqlite) | 0ms | 5-10ms | Built-in | SQLite DB |
| Knowledge | 1-5s/doc | 50-200ms | chromadb | Vector DB |
Summary
| Concept | One-liner |
|---|---|
| Context | Runtime data flow between agents (lost after session) |
| Memory | Persistent storage for learning and recall |
| Knowledge | Pre-loaded reference documents |
| RAG | Semantic search technique powering Knowledge |