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.

Diagram

Information Systems

search

ephemeral

recall

retrieve

store

🤖 Agent

LLM

📋 Context
Runtime data flow

🧠 Memory
Persistent learning

📚 Knowledge
Pre-loaded docs

🔍 RAG
Semantic search

Quick Comparison

AspectContextMemoryKnowledgeRAG
WhatRuntime data flowPersistent storagePre-loaded docsSearch technique
WhenDuring executionAcross sessionsBefore executionQuery time
LifetimeSession onlyPermanentPermanentN/A
DirectionRead-onlyRead + WriteRead-onlyRead-only
Agent Paramcontext=memory=knowledge=Part of knowledge
DependenciesNoneNone (file)chromadbchromadb

The Four Concepts Explained

1. Context = Runtime Data Flow

What it is: Data passed between agents during a single workflow execution.

Diagram

output as context

output as context

👤 User

Agent 1

Agent 2

Agent 3

📤 Result

python
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 completes

2. Memory = Persistent Learning

What it is: Information stored and recalled across sessions. The agent “remembers”.

Diagram

Session 2 (Later)

Session 1

learn

recall

🤖 Agent

💾 Memory Store

🤖 Agent

python
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.

Diagram

Load Phase

search

📄 PDF

Knowledge

📝 TXT

🌐 URL

Vector DB

🤖 Agent

python
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.

Diagram

RAG Process

1. embed

2. search

3. retrieve

4. augment

5. generate

❓ Query

Query Vector

Vector DB

📄 Relevant Chunks

🧠 LLM

✅ Answer

python
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?

Diagram

No

Yes

No

Yes

Yes

Yes

No

No

Yes

No

🤔 What do I need?

Need data after
session ends?

Passing data
between agents?

✅ Use Context

External documents
or files?

Need semantic
search?

✅ Use Knowledge + RAG

Agent should
learn/remember?

✅ Use Memory


When to Use What


Agent Parameters Summary

python
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

ParameterTypeDescription
context=TrueboolEnable context management
context=ManagerConfig(...)ManagerConfigCustom context settings
memory=TrueboolEnable file-based memory
memory={"session_id": "..."}dictMemory with session
memory=MemoryConfig(...)MemoryConfigFull memory config
knowledge=["file.pdf"]listSimple knowledge sources
knowledge=KnowledgeConfig(...)KnowledgeConfigFull knowledge config

Using All Together

The most powerful pattern combines all three:

python
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")
Diagram

Memory (Persistent)

Context (Runtime)

Knowledge (Pre-loaded)

RAG

findings

store

recall

📚 Docs

Support Agent

Escalation Agent

🧠 Memory


Performance Comparison

SystemSetup TimeQuery TimeDependenciesStorage
Context0ms0msNoneMemory only
Memory (file)0ms1-5msNoneJSON files
Memory (sqlite)0ms5-10msBuilt-inSQLite DB
Knowledge1-5s/doc50-200mschromadbVector DB

Summary

Diagram

Technique

Persistent

powers

Ephemeral

📋 Context

🧠 Memory

📚 Knowledge

🔍 RAG

ConceptOne-liner
ContextRuntime data flow between agents (lost after session)
MemoryPersistent storage for learning and recall
KnowledgePre-loaded reference documents
RAGSemantic search technique powering Knowledge

Related Documentation