context-retrieval
Context Retrieval
Retrieve relevant episodic context from memory for informed decision-making.
Retrieval Methods
Semantic Search (Preferred)
When embeddings available:
let context = memory
.retrieve_relevant_context(
"implement async batch updates",
task_context,
limit: 5
)
.await?;
Advantages: Finds semantically similar tasks, captures intent
Keyword Search (Fallback)
// SQL index-based search
SELECT * FROM episodes
WHERE task_type = ? AND tags LIKE ?
ORDER BY timestamp DESC
LIMIT ?;
Advantages: Fast, no embedding computation, deterministic
Retrieval Strategy
- Parse query (key terms, domain, task type)
- Check embedding availability
- Query cache (redb) first, fall back to Turso
- Rank by relevance or recency
- Filter and limit results
- Format context structure
Context Filtering
// By domain
TaskContext { domain: "storage".to_string(), .. }
// By task type
task_type_filter: Some("implementation")
// By recency (last 30 days)
since: Some(now - Duration::days(30))
// By success only
verdict: Some(Verdict::Success)
Response Format
pub struct RetrievedContext {
pub episodes: Vec<EpisodeSummary>,
pub patterns: Vec<Pattern>,
pub heuristics: Vec<Heuristic>,
pub relevance_scores: Vec<f32>,
}
pub struct EpisodeSummary {
pub id: String,
pub task_description: String,
pub verdict: Verdict,
pub key_steps: Vec<String>,
pub reflection: String,
pub relevance: f32,
}
Usage Examples
// Find similar implementation tasks
let retrieved = memory
.retrieve_relevant_context(query, context, 10)
.await?;
// Find common tool sequences
let patterns = memory
.get_patterns_by_type("ToolSequence")
.filter(|p| p.success_rate > 0.8)
.await?;
// Find error resolutions
let solutions = memory
.retrieve_error_resolutions("borrow checker error", 5)
.await?;
Troubleshooting
| Issue | Solution |
|---|---|
| Low recall | Check embeddings, expand tags, increase limit |
| Slow retrieval | Check cache, verify indexes, reduce result set |
| Poor relevance | Use semantic search, improve query, filter by domain |
More from d-o-hub/rust-self-learning-memory
loop-agent
Execute workflow agents iteratively for refinement and progressive improvement until quality criteria are met. Use when tasks require repetitive refinement, multi-iteration improvements, progressive optimization, or feedback loops until convergence.
51web-search-researcher
Research topics using web search and content fetching to find accurate, current information. Use when you need modern information, official documentation, best practices, technical solutions, or comparisons beyond your training data.
46perplexity-researcher-reasoning-pro
Highest level of research and reasoning capabilities for complex decision-making with significant consequences, strategic planning, technical architecture decisions, multi-stakeholder problems, or high-complexity troubleshooting requiring expert-level judgment and sophisticated reasoning chains. Prioritizes actively maintained repositories and validates website sources for 2025 relevance.
44rust-code-quality
Perform comprehensive Rust code quality reviews against best practices for async Rust, error handling, testing, and project structure
43codebase-analyzer
Analyze implementation details, trace data flow, explain technical workings, locate files, and consolidate codebases. Use when you need to understand HOW code works, find file locations, or assess technical debt.
40perplexity-researcher-pro
Complex research requiring deeper analysis, multi-step reasoning, and sophisticated source evaluation for technical, academic, or specialized domain queries needing expert-level analysis, high-stakes decisions, or multi-layered problem solving.
39