11# Memory Extraction Strategies
22
3- The Redis Agent Memory Server supports configurable memory extraction strategies that determine how memories are extracted from conversations when they are promoted from working memory to long-term storage .
3+ This reference documents the configurable extraction strategies that determine how memories are extracted from conversations during [ background extraction ] ( memory-integration-patterns.md#pattern-3-background-extraction-automatic ) .
44
5- ## Overview
6-
7- Memory strategies allow you to customize the extraction behavior for different use cases:
5+ ## Available Strategies
86
9- - ** Discrete Strategy** : Extract individual facts and preferences (default)
10- - ** Summary Strategy** : Create conversation summaries
11- - ** Preferences Strategy** : Focus on user preferences and characteristics
12- - ** Custom Strategy** : Use domain-specific extraction prompts
7+ | Strategy | Description | Best For |
8+ | ----------| -------------| ----------|
9+ | ** Discrete** (default) | Extract individual facts and preferences | General chat, factual information |
10+ | ** Summary** | Create conversation summaries | Meeting notes, long conversations |
11+ | ** Preferences** | Focus on user preferences and characteristics | Personalization, user profiles |
12+ | ** Custom** | Use domain-specific extraction prompts | Technical, legal, medical domains |
1313
14- Each strategy produces different types of memories optimized for specific applications.
15-
16- ## Available Strategies
14+ ## Strategy Reference
1715
1816### 1. Discrete Memory Strategy (Default)
1917
@@ -214,121 +212,11 @@ else:
214212!!! info "Full Security Documentation"
215213 For comprehensive security guidance, attack examples, and production recommendations, see the [ Security Guide] ( security-custom-prompts.md ) .
216214
217- ## Strategy-Aware MCP Tools
218-
219- Each working memory session can generate MCP tools that understand its configured strategy:
220-
221- ``` python
222- # Get strategy-specific tool description
223- tool_description = working_memory.get_create_long_term_memory_tool_description()
224-
225- # Create strategy-aware MCP tool
226- create_memories_tool = working_memory.create_long_term_memory_tool()
227- ```
228-
229- The generated tools include strategy-specific guidance in their descriptions, helping LLMs understand the expected extraction behavior.
230-
231- ** Example Tool Descriptions:**
232-
233- === "Discrete Strategy"
234- ```
235- Create long-term memories by extracting discrete semantic and episodic facts.
236- Focus on individual facts, user preferences, and specific events.
237- ```
238-
239- === "Summary Strategy"
240- ```
241- Create long-term memories by summarizing conversation content.
242- Generate concise summaries capturing key discussion points.
243- ```
244-
245- === "Custom Strategy"
246- ```
247- Create long-term memories using custom extraction focused on:
248- - Technology choices made
249- - Architecture decisions
250- - Implementation details
251- ```
252-
253- ## Usage Examples
254-
255- ### Basic Strategy Configuration
256-
257- ``` python
258- from agent_memory_client import MemoryAPIClient
259- from agent_memory_server.models import MemoryStrategyConfig
260-
261- client = MemoryAPIClient()
262-
263- # Configure strategy for technical discussions
264- tech_strategy = MemoryStrategyConfig(
265- strategy = " custom" ,
266- config = {
267- " custom_prompt" : """
268- Extract technical decisions from: {message}
269- Focus on technology choices, architecture, and implementation details.
270- Return JSON with memories array.
271- """
272- }
273- )
274-
275- # Apply to working memory
276- working_memory = await client.set_working_memory(
277- session_id = " tech-session" ,
278- messages = [
279- {" role" : " user" , " content" : " Let's use PostgreSQL for the database and Redis for caching" },
280- {" role" : " assistant" , " content" : " Good choices! That architecture will scale well." }
281- ],
282- long_term_memory_strategy = tech_strategy
283- )
284- ```
285-
286- ### Strategy Selection by Use Case
287-
288- ``` python
289- def get_strategy_for_domain (domain : str ) -> MemoryStrategyConfig:
290- """ Select appropriate strategy based on application domain."""
291-
292- if domain == " customer_support" :
293- return MemoryStrategyConfig(
294- strategy = " preferences" ,
295- config = {}
296- )
297-
298- elif domain == " meeting_notes" :
299- return MemoryStrategyConfig(
300- strategy = " summary" ,
301- config = {" max_summary_length" : 800 }
302- )
303-
304- elif domain == " technical_consulting" :
305- return MemoryStrategyConfig(
306- strategy = " custom" ,
307- config = {
308- " custom_prompt" : """
309- Extract technical recommendations from: {message}
310- Focus on: technology stack, architecture patterns, best practices.
311- Format as JSON memories.
312- """
313- }
314- )
315-
316- else :
317- # Default to discrete strategy
318- return MemoryStrategyConfig(
319- strategy = " discrete" ,
320- config = {}
321- )
322-
323- # Use domain-specific strategy
324- strategy = get_strategy_for_domain(" technical_consulting" )
325- ```
326-
327- ### REST API Integration
215+ ## REST API Usage
328216
329217``` bash
330218# Configure memory strategy via REST API
331- curl -X POST " http://localhost:8000/v1/working-memory/" \
219+ curl -X PUT " http://localhost:8000/v1/working-memory/my-session " \
332220 -H " Content-Type: application/json" \
333221 -d ' {
334222 "session_id": "api-session",
@@ -342,6 +230,8 @@ curl -X POST "http://localhost:8000/v1/working-memory/" \
342230 }'
343231```
344232
233+ For more comprehensive integration examples, see [ Memory Integration Patterns] ( memory-integration-patterns.md ) .
234+
345235## Best Practices
346236
347237### 1. Strategy Selection Guidelines
0 commit comments