mcpField
C
context-retrieval

context-retrieval

github.com/d-o-hubAgent workflows1344 installsUpdated today
Repository

About context-retrieval

A skill for retrieving relevant episodic context from memory to inform an agent's decisions. It supports semantic search with keyword fallback and filtering by domain, task type, and time.

Key features

  1. 01Prefers semantic retrieval
  2. 02Falls back to keyword search without embeddings
  3. 03Checks redb cache before Turso
  4. 04Ranks results by relevance or recency
  5. 05Filters by domain, task type, and date

Use cases

  1. 01Find similar implementation tasks
  2. 02Recall common tool sequences
  3. 03Retrieve recent experience by domain
  4. 04Gather relevant past context before a decision

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/d-o-hub/rust-self-learning-memory --skill context-retrieval

After installing, type/context-retrievalin Claude Code to confirm it loaded.

Details

From the project README

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

  1. Parse query (key terms, domain, task type)
  2. Check embedding availability
  3. Query cache (redb) first, fall back to Turso
  4. Rank by relevance or recency
  5. Filter and limit results
  6. 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

IssueSolution
Low recallCheck embeddings, expand tags, increase limit
Slow retrievalCheck cache, verify indexes, reduce result set
Poor relevanceUse semantic search, improve query, filter by domain

Comments

Markdown supported