<!-- source: https://deepwiki.com/MervinPraison/PraisonAI/4-memory-and-knowledge-systems -->

# Memory and Knowledge Systems

- README.md
- api.md
- src/praisonai/README.md

## Purpose and Scope

This document provides an overview of PraisonAI's memory and knowledge architecture, which enables agents to maintain context, learn from interactions, and retrieve relevant information. The system consists of four integrated subsystems:

- Memory Management ( 4.1 ) - Multi-tier memory for conversation context and learned facts
- Knowledge Management ( 4.2 ) - Document ingestion, chunking, and storage
- RAG System ( 4.3 ) - Retrieval-augmented generation with hybrid search and reranking
- Context Management ( 4.4 ) - Context optimization and compression strategies

For tool integration and MCP protocol support, see [Tool Systems](/MervinPraison/PraisonAI/5-tool-systems). For agent orchestration patterns, see [Multi-Agent Orchestration](/MervinPraison/PraisonAI/2.5-multi-agent-orchestration).

## Architecture Overview

The memory and knowledge systems form a layered architecture where each component serves a distinct purpose while sharing common storage backends.

### System Component Diagram

```

```

Sources: [src/praisonai-agents/praisonaiagents/agent/agent.py](https://github.com/MervinPraison/PraisonAI/blob/ab80807b/src/praisonai-agents/praisonaiagents/agent/agent.py) [src/praisonai-agents/praisonaiagents/memory/memory.py](https://github.com/MervinPraison/PraisonAI/blob/ab80807b/src/praisonai-agents/praisonaiagents/memory/memory.py) [src/praisonai-agents/praisonaiagents/knowledge/knowledge.py](https://github.com/MervinPraison/PraisonAI/blob/ab80807b/src/praisonai-agents/praisonaiagents/knowledge/knowledge.py) [src/praisonai-agents/praisonaiagents/rag/pipeline.py](https://github.com/MervinPraison/PraisonAI/blob/ab80807b/src/praisonai-agents/praisonaiagents/rag/pipeline.py)

### Data Flow and Processing Pipeline

```

```

Sources: [src/praisonai-agents/praisonaiagents/knowledge/knowledge.py](https://github.com/MervinPraison/PraisonAI/blob/ab80807b/src/praisonai-agents/praisonaiagents/knowledge/knowledge.py) [src/praisonai-agents/praisonaiagents/rag/pipeline.py](https://github.com/MervinPraison/PraisonAI/blob/ab80807b/src/praisonai-agents/praisonaiagents/rag/pipeline.py) [src/praisonai-agents/praisonaiagents/memory/auto_memory.py](https://github.com/MervinPraison/PraisonAI/blob/ab80807b/src/praisonai-agents/praisonaiagents/memory/auto_memory.py)

## Memory Tiers

PraisonAI implements a four-tier memory architecture that balances recency, importance, and semantic relevance. The `Memory` class ([memory/memory.py](https://github.com/MervinPraison/PraisonAI/blob/ab80807b/memory/memory.py)) coordinates these tiers:

### Memory Configuration

```

```

Sources: [src/praisonai-agents/praisonaiagents/agent/agent.py](https://github.com/MervinPraison/PraisonAI/blob/ab80807b/src/praisonai-agents/praisonaiagents/agent/agent.py) [src/praisonai-agents/praisonaiagents/config/feature_configs.py](https://github.com/MervinPraison/PraisonAI/blob/ab80807b/src/praisonai-agents/praisonaiagents/config/feature_configs.py)

### Memory Storage Locations

The `FileMemory` backend ([memory/file_memory.py](https://github.com/MervinPraison/PraisonAI/blob/ab80807b/memory/file_memory.py)) uses the following directory structure:

```
~/.praison/memory/
|-- <user_id>/
|   |-- short_term.json       # Recent context
|   |-- long_term.json        # Important facts
|   |-- entities.json         # Extracted entities
|   |-- episodic.json         # Interaction history
|   `-- sessions/
|       |-- <session_name>.json
|       `-- checkpoints/
|           `-- <checkpoint_id>.json
```

Sources: [src/praisonai-agents/praisonaiagents/memory/file_memory.py](https://github.com/MervinPraison/PraisonAI/blob/ab80807b/src/praisonai-agents/praisonaiagents/memory/file_memory.py)

For detailed memory operations and quality scoring, see [Memory Management](/MervinPraison/PraisonAI/4.1-memory-management).

## Knowledge Base

The `Knowledge` class ([knowledge/knowledge.py](https://github.com/MervinPraison/PraisonAI/blob/ab80807b/knowledge/knowledge.py)) manages document ingestion, chunking, and indexing for retrieval. It supports multiple document formats and chunking strategies.

### Document Ingestion Pipeline

```

```

Sources: [src/praisonai-agents/praisonaiagents/knowledge/knowledge.py](https://github.com/MervinPraison/PraisonAI/blob/ab80807b/src/praisonai-agents/praisonaiagents/knowledge/knowledge.py) [src/praisonai-agents/praisonaiagents/knowledge/markdown.py](https://github.com/MervinPraison/PraisonAI/blob/ab80807b/src/praisonai-agents/praisonaiagents/knowledge/markdown.py)

### Chunking Strategies

The `Chunking` class ([knowledge/chunking.py](https://github.com/MervinPraison/PraisonAI/blob/ab80807b/knowledge/chunking.py)) supports multiple strategies via `ChunkingStrategy` enum:

```

```

Sources: [src/praisonai-agents/praisonaiagents/knowledge/chunking.py](https://github.com/MervinPraison/PraisonAI/blob/ab80807b/src/praisonai-agents/praisonaiagents/knowledge/chunking.py) [src/praisonai-agents/praisonaiagents/knowledge/knowledge.py](https://github.com/MervinPraison/PraisonAI/blob/ab80807b/src/praisonai-agents/praisonaiagents/knowledge/knowledge.py)

For document readers, indexing strategies, and corpus statistics, see [Knowledge Management](/MervinPraison/PraisonAI/4.2-knowledge-management).

## RAG Pipeline

The `RAG` class ([rag/pipeline.py](https://github.com/MervinPraison/PraisonAI/blob/ab80807b/rag/pipeline.py)) implements retrieval-augmented generation with hybrid search, reranking, and citation support.

### RAG Query Flow

```

```

Sources: [src/praisonai-agents/praisonaiagents/rag/pipeline.py](https://github.com/MervinPraison/PraisonAI/blob/ab80807b/src/praisonai-agents/praisonaiagents/rag/pipeline.py) [src/praisonai-agents/praisonaiagents/rag/retrieval_config.py](https://github.com/MervinPraison/PraisonAI/blob/ab80807b/src/praisonai-agents/praisonaiagents/rag/retrieval_config.py) [src/praisonai-agents/praisonaiagents/rag/models.py](https://github.com/MervinPraison/PraisonAI/blob/ab80807b/src/praisonai-agents/praisonaiagents/rag/models.py)

### RAG Configuration

The `RetrievalConfig` class ([rag/retrieval_config.py](https://github.com/MervinPraison/PraisonAI/blob/ab80807b/rag/retrieval_config.py)) controls retrieval behavior:

```

```

Sources: [src/praisonai-agents/praisonaiagents/rag/retrieval_config.py](https://github.com/MervinPraison/PraisonAI/blob/ab80807b/src/praisonai-agents/praisonaiagents/rag/retrieval_config.py) [src/praisonai-agents/praisonaiagents/agent/agent.py](https://github.com/MervinPraison/PraisonAI/blob/ab80807b/src/praisonai-agents/praisonaiagents/agent/agent.py)

### RAG Result Structure

The `RAGResult` dataclass ([rag/models.py](https://github.com/MervinPraison/PraisonAI/blob/ab80807b/rag/models.py)) encapsulates retrieval results:

```

```

Sources: [src/praisonai-agents/praisonaiagents/rag/models.py](https://github.com/MervinPraison/PraisonAI/blob/ab80807b/src/praisonai-agents/praisonaiagents/rag/models.py)

For hybrid retrieval algorithms, reranking strategies, and citation modes, see [RAG System](/MervinPraison/PraisonAI/4.3-rag-system).

## Context Management

The `ContextManager` class ([context/manager.py](https://github.com/MervinPraison/PraisonAI/blob/ab80807b/context/manager.py)) optimizes context size through compression and selection strategies.

### Context Optimization Pipeline

```

```

Sources: [src/praisonai-agents/praisonaiagents/context/manager.py](https://github.com/MervinPraison/PraisonAI/blob/ab80807b/src/praisonai-agents/praisonaiagents/context/manager.py) [src/praisonai-agents/praisonaiagents/compaction/](https://github.com/MervinPraison/PraisonAI/blob/ab80807b/src/praisonai-agents/praisonaiagents/compaction/)

### Compaction Strategies

The `ContextCompactor` ([compaction/compactor.py](https://github.com/MervinPraison/PraisonAI/blob/ab80807b/compaction/compactor.py)) implements multiple strategies:

```

```

Sources: [src/praisonai-agents/praisonaiagents/compaction/compactor.py](https://github.com/MervinPraison/PraisonAI/blob/ab80807b/src/praisonai-agents/praisonaiagents/compaction/compactor.py)

For context policies, token budgets, and optimization algorithms, see [Context Management](/MervinPraison/PraisonAI/4.4-context-management).

## Storage Backends

All memory and knowledge systems share a common storage abstraction through `MemoryBackend` ([memory/backend.py](https://github.com/MervinPraison/PraisonAI/blob/ab80807b/memory/backend.py)).

### Backend Comparison

### Backend Configuration

```

```

Sources: [src/praisonai-agents/praisonaiagents/memory/file_memory.py](https://github.com/MervinPraison/PraisonAI/blob/ab80807b/src/praisonai-agents/praisonaiagents/memory/file_memory.py) [src/praisonai-agents/praisonaiagents/config/feature_configs.py](https://github.com/MervinPraison/PraisonAI/blob/ab80807b/src/praisonai-agents/praisonaiagents/config/feature_configs.py)

### Storage File Paths

Sources: [src/praisonai-agents/praisonaiagents/memory/file_memory.py](https://github.com/MervinPraison/PraisonAI/blob/ab80807b/src/praisonai-agents/praisonaiagents/memory/file_memory.py)

## Agent Integration

Agents integrate memory, knowledge, and RAG through declarative configuration.

### Memory Integration

```

```

Sources: [src/praisonai-agents/praisonaiagents/agent/agent.py](https://github.com/MervinPraison/PraisonAI/blob/ab80807b/src/praisonai-agents/praisonaiagents/agent/agent.py)

### Knowledge Integration

```

```

Sources: [src/praisonai-agents/praisonaiagents/agent/agent.py](https://github.com/MervinPraison/PraisonAI/blob/ab80807b/src/praisonai-agents/praisonaiagents/agent/agent.py) [src/praisonai-agents/praisonaiagents/knowledge/knowledge.py](https://github.com/MervinPraison/PraisonAI/blob/ab80807b/src/praisonai-agents/praisonaiagents/knowledge/knowledge.py)

### RAG Integration

```

```

Sources: [src/praisonai-agents/praisonaiagents/agent/agent.py](https://github.com/MervinPraison/PraisonAI/blob/ab80807b/src/praisonai-agents/praisonaiagents/agent/agent.py) [src/praisonai-agents/praisonaiagents/rag/models.py](https://github.com/MervinPraison/PraisonAI/blob/ab80807b/src/praisonai-agents/praisonaiagents/rag/models.py)

### Combined Example

```

```

Sources: [src/praisonai-agents/praisonaiagents/agent/agent.py](https://github.com/MervinPraison/PraisonAI/blob/ab80807b/src/praisonai-agents/praisonaiagents/agent/agent.py) [src/praisonai-agents/praisonaiagents/config/feature_configs.py](https://github.com/MervinPraison/PraisonAI/blob/ab80807b/src/praisonai-agents/praisonaiagents/config/feature_configs.py)

## Configuration Presets

The framework provides preset configurations through the `resolve()` function ([config/resolution.py](https://github.com/MervinPraison/PraisonAI/blob/ab80807b/config/resolution.py)).

### Memory Presets

```

```

Sources: [src/praisonai-agents/praisonaiagents/config/presets.py](https://github.com/MervinPraison/PraisonAI/blob/ab80807b/src/praisonai-agents/praisonaiagents/config/presets.py)

### Knowledge Presets

```

```

Sources: [src/praisonai-agents/praisonaiagents/config/feature_configs.py](https://github.com/MervinPraison/PraisonAI/blob/ab80807b/src/praisonai-agents/praisonaiagents/config/feature_configs.py)

### RAG Presets

```

```

Sources: [src/praisonai-agents/praisonaiagents/config/presets.py](https://github.com/MervinPraison/PraisonAI/blob/ab80807b/src/praisonai-agents/praisonaiagents/config/presets.py)

## API Surface Summary

### Core Classes

Sources: [api.md](https://github.com/MervinPraison/PraisonAI/blob/ab80807b/api.md?plain=1)

### Configuration Classes

Sources: [api.md](https://github.com/MervinPraison/PraisonAI/blob/ab80807b/api.md?plain=1) [src/praisonai-agents/praisonaiagents/config/feature_configs.py](https://github.com/MervinPraison/PraisonAI/blob/ab80807b/src/praisonai-agents/praisonaiagents/config/feature_configs.py)

### Result Classes

Sources: [src/praisonai-agents/praisonaiagents/rag/models.py](https://github.com/MervinPraison/PraisonAI/blob/ab80807b/src/praisonai-agents/praisonaiagents/rag/models.py)
