mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-08 23:58:34 +00:00
docs: fix long term memory class name in examples (#2049)
* docs: fix long term memory class name in examples - Replace EnhanceLongTermMemory with LongTermMemory to match actual implementation - Update code examples to show correct usage - Fixes #2026 Co-Authored-By: Joe Moura <joao@crewai.com> * docs: improve memory examples with imports, types and security - Add proper import statements - Add type hints for better readability - Add descriptive comments for each memory type - Add security considerations section - Add configuration examples section - Use environment variables for storage paths Co-Authored-By: Joe Moura <joao@crewai.com> * Update memory.mdx * Update memory.mdx --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: Joe Moura <joao@crewai.com> Co-authored-by: João Moura <joaomdmoura@gmail.com>
This commit is contained in:
committed by
GitHub
parent
e0600e3bb9
commit
d6d98ee969
@@ -58,41 +58,107 @@ my_crew = Crew(
|
|||||||
### Example: Use Custom Memory Instances e.g FAISS as the VectorDB
|
### Example: Use Custom Memory Instances e.g FAISS as the VectorDB
|
||||||
|
|
||||||
```python Code
|
```python Code
|
||||||
from crewai import Crew, Agent, Task, Process
|
from crewai import Crew, Process
|
||||||
|
from crewai.memory import LongTermMemory, ShortTermMemory, EntityMemory
|
||||||
|
from crewai.memory.storage import LTMSQLiteStorage, RAGStorage
|
||||||
|
from typing import List, Optional
|
||||||
|
|
||||||
# Assemble your crew with memory capabilities
|
# Assemble your crew with memory capabilities
|
||||||
my_crew = Crew(
|
my_crew: Crew = Crew(
|
||||||
agents=[...],
|
agents = [...],
|
||||||
tasks=[...],
|
tasks = [...],
|
||||||
process="Process.sequential",
|
process = Process.sequential,
|
||||||
memory=True,
|
memory = True,
|
||||||
long_term_memory=EnhanceLongTermMemory(
|
# Long-term memory for persistent storage across sessions
|
||||||
|
long_term_memory = LongTermMemory(
|
||||||
storage=LTMSQLiteStorage(
|
storage=LTMSQLiteStorage(
|
||||||
db_path="/my_data_dir/my_crew1/long_term_memory_storage.db"
|
db_path="/my_crew1/long_term_memory_storage.db"
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
short_term_memory=EnhanceShortTermMemory(
|
# Short-term memory for current context using RAG
|
||||||
storage=CustomRAGStorage(
|
short_term_memory = ShortTermMemory(
|
||||||
crew_name="my_crew",
|
storage = RAGStorage(
|
||||||
storage_type="short_term",
|
embedder_config={
|
||||||
data_dir="//my_data_dir",
|
"provider": "openai",
|
||||||
model=embedder["model"],
|
"config": {
|
||||||
dimension=embedder["dimension"],
|
"model": 'text-embedding-3-small'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
type="short_term",
|
||||||
|
path="/my_crew1/"
|
||||||
|
)
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
entity_memory=EnhanceEntityMemory(
|
# Entity memory for tracking key information about entities
|
||||||
storage=CustomRAGStorage(
|
entity_memory = EntityMemory(
|
||||||
crew_name="my_crew",
|
storage=RAGStorage(
|
||||||
storage_type="entities",
|
embedder_config={
|
||||||
data_dir="//my_data_dir",
|
"provider": "openai",
|
||||||
model=embedder["model"],
|
"config": {
|
||||||
dimension=embedder["dimension"],
|
"model": 'text-embedding-3-small'
|
||||||
),
|
}
|
||||||
|
},
|
||||||
|
type="short_term",
|
||||||
|
path="/my_crew1/"
|
||||||
|
)
|
||||||
),
|
),
|
||||||
verbose=True,
|
verbose=True,
|
||||||
)
|
)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Security Considerations
|
||||||
|
|
||||||
|
When configuring memory storage:
|
||||||
|
- Use environment variables for storage paths (e.g., `CREWAI_STORAGE_DIR`)
|
||||||
|
- Never hardcode sensitive information like database credentials
|
||||||
|
- Consider access permissions for storage directories
|
||||||
|
- Use relative paths when possible to maintain portability
|
||||||
|
|
||||||
|
Example using environment variables:
|
||||||
|
```python
|
||||||
|
import os
|
||||||
|
from crewai import Crew
|
||||||
|
from crewai.memory import LongTermMemory
|
||||||
|
from crewai.memory.storage import LTMSQLiteStorage
|
||||||
|
|
||||||
|
# Configure storage path using environment variable
|
||||||
|
storage_path = os.getenv("CREWAI_STORAGE_DIR", "./storage")
|
||||||
|
crew = Crew(
|
||||||
|
memory=True,
|
||||||
|
long_term_memory=LongTermMemory(
|
||||||
|
storage=LTMSQLiteStorage(
|
||||||
|
db_path="{storage_path}/memory.db".format(storage_path=storage_path)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
```
|
||||||
|
|
||||||
|
## Configuration Examples
|
||||||
|
|
||||||
|
### Basic Memory Configuration
|
||||||
|
```python
|
||||||
|
from crewai import Crew
|
||||||
|
from crewai.memory import LongTermMemory
|
||||||
|
|
||||||
|
# Simple memory configuration
|
||||||
|
crew = Crew(memory=True) # Uses default storage locations
|
||||||
|
```
|
||||||
|
|
||||||
|
### Custom Storage Configuration
|
||||||
|
```python
|
||||||
|
from crewai import Crew
|
||||||
|
from crewai.memory import LongTermMemory
|
||||||
|
from crewai.memory.storage import LTMSQLiteStorage
|
||||||
|
|
||||||
|
# Configure custom storage paths
|
||||||
|
crew = Crew(
|
||||||
|
memory=True,
|
||||||
|
long_term_memory=LongTermMemory(
|
||||||
|
storage=LTMSQLiteStorage(db_path="./memory.db")
|
||||||
|
)
|
||||||
|
)
|
||||||
|
```
|
||||||
|
|
||||||
## Integrating Mem0 for Enhanced User Memory
|
## Integrating Mem0 for Enhanced User Memory
|
||||||
|
|
||||||
[Mem0](https://mem0.ai/) is a self-improving memory layer for LLM applications, enabling personalized AI experiences.
|
[Mem0](https://mem0.ai/) is a self-improving memory layer for LLM applications, enabling personalized AI experiences.
|
||||||
|
|||||||
Reference in New Issue
Block a user