Skip to content

Commit d6d98ee

Browse files
devin-ai-integration[bot]Joe Mourajoaomdmoura
authored
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>
1 parent e0600e3 commit d6d98ee

File tree

1 file changed

+89
-23
lines changed

1 file changed

+89
-23
lines changed

docs/concepts/memory.mdx

+89-23
Original file line numberDiff line numberDiff line change
@@ -58,41 +58,107 @@ my_crew = Crew(
5858
### Example: Use Custom Memory Instances e.g FAISS as the VectorDB
5959

6060
```python Code
61-
from crewai import Crew, Agent, Task, Process
61+
from crewai import Crew, Process
62+
from crewai.memory import LongTermMemory, ShortTermMemory, EntityMemory
63+
from crewai.memory.storage import LTMSQLiteStorage, RAGStorage
64+
from typing import List, Optional
6265

6366
# Assemble your crew with memory capabilities
64-
my_crew = Crew(
65-
agents=[...],
66-
tasks=[...],
67-
process="Process.sequential",
68-
memory=True,
69-
long_term_memory=EnhanceLongTermMemory(
67+
my_crew: Crew = Crew(
68+
agents = [...],
69+
tasks = [...],
70+
process = Process.sequential,
71+
memory = True,
72+
# Long-term memory for persistent storage across sessions
73+
long_term_memory = LongTermMemory(
7074
storage=LTMSQLiteStorage(
71-
db_path="/my_data_dir/my_crew1/long_term_memory_storage.db"
75+
db_path="/my_crew1/long_term_memory_storage.db"
7276
)
7377
),
74-
short_term_memory=EnhanceShortTermMemory(
75-
storage=CustomRAGStorage(
76-
crew_name="my_crew",
77-
storage_type="short_term",
78-
data_dir="//my_data_dir",
79-
model=embedder["model"],
80-
dimension=embedder["dimension"],
78+
# Short-term memory for current context using RAG
79+
short_term_memory = ShortTermMemory(
80+
storage = RAGStorage(
81+
embedder_config={
82+
"provider": "openai",
83+
"config": {
84+
"model": 'text-embedding-3-small'
85+
}
86+
},
87+
type="short_term",
88+
path="/my_crew1/"
89+
)
8190
),
8291
),
83-
entity_memory=EnhanceEntityMemory(
84-
storage=CustomRAGStorage(
85-
crew_name="my_crew",
86-
storage_type="entities",
87-
data_dir="//my_data_dir",
88-
model=embedder["model"],
89-
dimension=embedder["dimension"],
90-
),
92+
# Entity memory for tracking key information about entities
93+
entity_memory = EntityMemory(
94+
storage=RAGStorage(
95+
embedder_config={
96+
"provider": "openai",
97+
"config": {
98+
"model": 'text-embedding-3-small'
99+
}
100+
},
101+
type="short_term",
102+
path="/my_crew1/"
103+
)
91104
),
92105
verbose=True,
93106
)
94107
```
95108

109+
## Security Considerations
110+
111+
When configuring memory storage:
112+
- Use environment variables for storage paths (e.g., `CREWAI_STORAGE_DIR`)
113+
- Never hardcode sensitive information like database credentials
114+
- Consider access permissions for storage directories
115+
- Use relative paths when possible to maintain portability
116+
117+
Example using environment variables:
118+
```python
119+
import os
120+
from crewai import Crew
121+
from crewai.memory import LongTermMemory
122+
from crewai.memory.storage import LTMSQLiteStorage
123+
124+
# Configure storage path using environment variable
125+
storage_path = os.getenv("CREWAI_STORAGE_DIR", "./storage")
126+
crew = Crew(
127+
memory=True,
128+
long_term_memory=LongTermMemory(
129+
storage=LTMSQLiteStorage(
130+
db_path="{storage_path}/memory.db".format(storage_path=storage_path)
131+
)
132+
)
133+
)
134+
```
135+
136+
## Configuration Examples
137+
138+
### Basic Memory Configuration
139+
```python
140+
from crewai import Crew
141+
from crewai.memory import LongTermMemory
142+
143+
# Simple memory configuration
144+
crew = Crew(memory=True) # Uses default storage locations
145+
```
146+
147+
### Custom Storage Configuration
148+
```python
149+
from crewai import Crew
150+
from crewai.memory import LongTermMemory
151+
from crewai.memory.storage import LTMSQLiteStorage
152+
153+
# Configure custom storage paths
154+
crew = Crew(
155+
memory=True,
156+
long_term_memory=LongTermMemory(
157+
storage=LTMSQLiteStorage(db_path="./memory.db")
158+
)
159+
)
160+
```
161+
96162
## Integrating Mem0 for Enhanced User Memory
97163

98164
[Mem0](https://mem0.ai/) is a self-improving memory layer for LLM applications, enabling personalized AI experiences.

0 commit comments

Comments
 (0)