Spaces:
Running
Running
File size: 10,332 Bytes
18dc680 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 | # Memory Reader Node
**Type:** `memory-reader`
**Category:** Memory Agent
**Version:** v0.9.4+
## Overview
The Memory Reader performs semantic search and retrieval using **RedisStack HNSW indexing** with sub-millisecond vector search performance (100x faster than basic Redis). It combines semantic similarity, keyword matching, and temporal ranking for intelligent memory retrieval.
## Basic Configuration
```yaml
- id: memory_search
type: memory-reader
namespace: knowledge_base
params:
limit: 10
similarity_threshold: 0.8
enable_context_search: true
prompt: "Find: {{ input }}"
```
## Parameters
### Required Parameters
| Parameter | Type | Description |
|-----------|------|-------------|
| `id` | string | Unique identifier |
| `type` | string | Must be `memory-reader` |
| `namespace` | string | Memory namespace to search |
| `prompt` | string | Search query |
### Optional Parameters (in `params`)
| Parameter | Type | Default | Description |
|-----------|------|---------|-------------|
| `limit` | int | `10` | Max memories to return |
| `similarity_threshold` | float | `0.7` | Min relevance (0.0-1.0) |
| `enable_context_search` | bool | `false` | Use conversation history |
| `context_weight` | float | `0.4` | Context importance (0.0-1.0) |
| `temporal_weight` | float | `0.3` | Recency importance (0.0-1.0) |
| `enable_temporal_ranking` | bool | `false` | Boost recent memories |
| `memory_type_filter` | string | - | Filter: `short_term` or `long_term` |
| `memory_category_filter` | string | - | Filter by category |
| `timeout` | float | `10.0` | Search timeout |
## Performance
- **Search Latency:** 0.5-5ms (vs 50-200ms with basic Redis)
- **Throughput:** 100x faster with HNSW indexing
- **Accuracy:** Sub-millisecond semantic search
## Usage Examples
### Example 1: Basic Semantic Search
```yaml
- id: knowledge_search
type: memory-reader
namespace: knowledge_base
params:
limit: 5
similarity_threshold: 0.8
prompt: "{{ input }}"
```
### Example 2: Context-Aware Search
```yaml
- id: contextual_search
type: memory-reader
namespace: conversations
params:
limit: 10
similarity_threshold: 0.7
enable_context_search: true
context_weight: 0.4 # 40% weight for conversation context
temporal_weight: 0.3 # 30% weight for recency
enable_temporal_ranking: true
prompt: |
Find relevant memories for: {{ input }}
Consider conversation history and recent context.
```
### Example 3: Filtered Search
```yaml
- id: filtered_search
type: memory-reader
namespace: knowledge_base
params:
limit: 15
similarity_threshold: 0.75
memory_type_filter: "long_term" # Only long-term memories
memory_category_filter: "facts" # Only facts category
prompt: "{{ input }}"
```
### Example 4: Broad vs Narrow Search
```yaml
# Broad search - cast wide net
- id: broad_search
type: memory-reader
namespace: all_knowledge
params:
limit: 20
similarity_threshold: 0.6 # Lower threshold
enable_temporal_ranking: false # Don't bias to recent
prompt: "{{ input }}"
# Narrow search - precise matches
- id: narrow_search
type: memory-reader
namespace: technical_docs
params:
limit: 5
similarity_threshold: 0.9 # High threshold
memory_type_filter: "long_term"
prompt: "{{ input }}"
```
### Example 5: Multi-Namespace Search
```yaml
- id: fork_search
type: fork
targets:
- [search_conversations]
- [search_knowledge]
- [search_procedures]
- id: search_conversations
type: memory-reader
namespace: conversations
params:
limit: 5
similarity_threshold: 0.8
prompt: "{{ input }}"
- id: search_knowledge
type: memory-reader
namespace: knowledge_base
params:
limit: 10
similarity_threshold: 0.75
prompt: "{{ input }}"
- id: search_procedures
type: memory-reader
namespace: procedures
params:
limit: 3
similarity_threshold: 0.85
prompt: "{{ input }}"
- id: combine_searches
type: join
prompt: |
Combine search results:
Conversations: {{ previous_outputs.search_conversations }}
Knowledge: {{ previous_outputs.search_knowledge }}
Procedures: {{ previous_outputs.search_procedures }}
```
## Memory Presets
Use presets for pre-configured settings:
```yaml
- id: episodic_search
type: memory-reader
memory_preset: "episodic" # 7 days, limit=8, threshold=0.6
namespace: experiences
prompt: "{{ input }}"
- id: semantic_search
type: memory-reader
memory_preset: "semantic" # 30 days, limit=10, threshold=0.75
namespace: knowledge
prompt: "{{ input }}"
```
| Preset | TTL | Limit | Threshold | Use Case |
|--------|-----|-------|-----------|----------|
| `sensory` | 5 min | 5 | 0.5 | Raw inputs |
| `working` | 2 hours | 6 | 0.6 | Active tasks |
| `semantic` | 30 days | 10 | 0.75 | Facts/knowledge |
| `procedural` | 60 days | 8 | 0.8 | Skills/processes |
| `episodic` | 90 days | 8 | 0.6 | Experiences |
| `meta` | 180 days | 12 | 0.7 | System insights |
## Output Format
```python
{
"memories": [
{
"content": "Memory content here...",
"similarity_score": 0.92,
"metadata": {
"timestamp": "2025-10-16T12:00:00Z",
"namespace": "knowledge_base",
"memory_type": "long_term",
"category": "facts"
},
"id": "mem_abc123"
}
],
"num_results": 5,
"search_query": "original query",
"namespace": "knowledge_base"
}
```
Access in templates:
```yaml
prompt: |
Found {{ previous_outputs.memory_search.num_results }} memories:
{% for memory in previous_outputs.memory_search.memories %}
- {{ memory.content }} (score: {{ memory.similarity_score }})
{% endfor %}
```
## Threshold Guide
| Threshold | Behavior | Use Case |
|-----------|----------|----------|
| 0.95-1.0 | Exact/near-exact matches | Duplicate detection |
| 0.85-0.94 | Very similar | Fact verification |
| 0.75-0.84 | Clearly related | Knowledge retrieval |
| 0.65-0.74 | Somewhat related | Exploratory search |
| 0.50-0.64 | Loosely related | Broad context |
| < 0.50 | Weak connection | Not recommended |
## Best Practices
### 1. Namespace Organization
```yaml
# ✅ GOOD: Specific namespaces
namespace: user_conversations
namespace: technical_documentation
namespace: error_logs
# ❌ BAD: Too generic
namespace: data
namespace: stuff
```
### 2. Appropriate Thresholds
```yaml
# High threshold for facts
- id: fact_search
type: memory-reader
namespace: verified_facts
params:
similarity_threshold: 0.85
# Lower threshold for exploration
- id: related_search
type: memory-reader
namespace: general_knowledge
params:
similarity_threshold: 0.65
```
### 3. Limit Based on Use Case
```yaml
# Few high-quality results
params:
limit: 3
similarity_threshold: 0.9
# Many results for context
params:
limit: 20
similarity_threshold: 0.7
```
### 4. Context-Aware Search
```yaml
- id: contextual_search
type: memory-reader
namespace: conversations
params:
enable_context_search: true
context_weight: 0.4 # Balance with similarity
temporal_weight: 0.3 # Recent matters
enable_temporal_ranking: true
prompt: "{{ input }}"
```
## Troubleshooting
| Issue | Cause | Solution |
|-------|-------|----------|
| No results found | Threshold too high | Lower to 0.6-0.7 |
| Too many irrelevant results | Threshold too low | Raise to 0.8+ |
| Slow searches | Basic Redis backend | Use `redisstack` backend |
| Missing recent memories | No temporal ranking | Enable `enable_temporal_ranking: true` |
| Stale results | Decay not enabled | Enable memory decay |
## Integration Patterns
### With Binary Decision
```yaml
- id: memory_search
type: memory-reader
namespace: knowledge
params:
limit: 5
similarity_threshold: 0.8
prompt: "{{ input }}"
- id: has_sufficient_info
type: openai-binary
prompt: |
Memories found: {{ previous_outputs.memory_search }}
Query: {{ input }}
Is this sufficient to answer?
- id: router
type: router
params:
decision_key: has_sufficient_info
routing_map:
"true": [answer_from_memory]
"false": [search_web]
```
### With Failover
```yaml
- id: search_with_fallback
type: failover
children:
- id: try_memory
type: memory-reader
namespace: knowledge
params:
limit: 10
similarity_threshold: 0.85
prompt: "{{ input }}"
- id: fallback_search
type: duckduckgo
prompt: "{{ input }}"
```
### In Loops
```yaml
- id: iterative_search
type: loop
max_loops: 3
score_threshold: 0.9
score_extraction_pattern: "SCORE:\\s*([0-9.]+)"
internal_workflow:
agents:
- id: refined_search
type: memory-reader
namespace: knowledge
params:
limit: 10
similarity_threshold: 0.7
prompt: |
Iteration {{ loop_number }}
Original: {{ input }}
{% if has_past_loops() %}
Previous attempts: {{ get_past_loops() }}
{% endif %}
- id: evaluate
type: openai-answer
prompt: |
Rate search quality (0.0-1.0):
{{ previous_outputs.refined_search }}
SCORE: X.XX
```
## Configuration
### Global Memory Setup
```yaml
orchestrator:
memory:
enabled: true
backend: redisstack # 100x faster
config:
redis_url: redis://localhost:6380/0
memory_config:
decay:
enabled: true
default_short_term_hours: 2
default_long_term_hours: 168
```
## Environment Variables
```bash
# RedisStack (recommended)
export ORKA_MEMORY_BACKEND=redisstack
export REDIS_URL=redis://localhost:6380/0
# Memory decay
export ORKA_MEMORY_DECAY_ENABLED=true
export ORKA_MEMORY_DECAY_SHORT_TERM_HOURS=2
export ORKA_MEMORY_DECAY_LONG_TERM_HOURS=168
```
## Related Documentation
- [Memory Writer Node](./memory-writer.md)
- [Memory System Guide](../MEMORY_SYSTEM_GUIDE.md)
- [Memory Presets](../memory-presets.md)
- [RedisStack Setup](../redis-stack-setup.md)
## Version History
- **v0.9.4**: Current version with RedisStack HNSW
- **v0.9.0**: Added context-aware search
- **v0.8.0**: Added memory presets
- **v0.7.0**: Initial release
|