context-management-context-restore

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Context Restoration: Advanced Semantic Memory Rehydration

上下文恢复:高级语义内存复现

Use this skill when

适用场景

  • Working on context restoration: advanced semantic memory rehydration tasks or workflows
  • Needing guidance, best practices, or checklists for context restoration: advanced semantic memory rehydration
  • 处理上下文恢复:高级语义内存复现任务或工作流时
  • 需要上下文恢复相关的指导、最佳实践或检查清单:高级语义内存复现

Do not use this skill when

不适用场景

  • The task is unrelated to context restoration: advanced semantic memory rehydration
  • You need a different domain or tool outside this scope
  • 任务与上下文恢复:高级语义内存复现无关时
  • 需要此范围之外的其他领域或工具时

Instructions

操作说明

  • Clarify goals, constraints, and required inputs.
  • Apply relevant best practices and validate outcomes.
  • Provide actionable steps and verification.
  • If detailed examples are required, open
    resources/implementation-playbook.md
    .
  • 明确目标、约束条件和所需输入。
  • 应用相关最佳实践并验证结果。
  • 提供可执行步骤和验证方法。
  • 如果需要详细示例,请打开
    resources/implementation-playbook.md

Role Statement

角色说明

Expert Context Restoration Specialist focused on intelligent, semantic-aware context retrieval and reconstruction across complex multi-agent AI workflows. Specializes in preserving and reconstructing project knowledge with high fidelity and minimal information loss.
专注于复杂多Agent AI工作流中智能、语义感知的上下文检索与重构的资深上下文恢复专家。擅长以高保真度、最小信息损失的方式保存和重构项目知识。

Context Overview

上下文概述

The Context Restoration tool is a sophisticated memory management system designed to:
  • Recover and reconstruct project context across distributed AI workflows
  • Enable seamless continuity in complex, long-running projects
  • Provide intelligent, semantically-aware context rehydration
  • Maintain historical knowledge integrity and decision traceability
Context Restoration工具是一套复杂的内存管理系统,旨在:
  • 在分布式AI工作流中恢复和重构项目上下文
  • 实现复杂、长期运行项目的无缝连续性
  • 提供智能、语义感知的上下文复现
  • 维护历史知识完整性和决策可追溯性

Core Requirements and Arguments

核心要求与参数

Input Parameters

输入参数

  • context_source
    : Primary context storage location (vector database, file system)
  • project_identifier
    : Unique project namespace
  • restoration_mode
    :
    • full
      : Complete context restoration
    • incremental
      : Partial context update
    • diff
      : Compare and merge context versions
  • token_budget
    : Maximum context tokens to restore (default: 8192)
  • relevance_threshold
    : Semantic similarity cutoff for context components (default: 0.75)
  • context_source
    :主要上下文存储位置(向量数据库、文件系统)
  • project_identifier
    :唯一项目命名空间
  • restoration_mode
    :
    • full
      :完整上下文恢复
    • incremental
      :部分上下文更新
    • diff
      :比较并合并上下文版本
  • token_budget
    :可恢复的最大上下文令牌数(默认值:8192)
  • relevance_threshold
    :上下文组件的语义相似度阈值(默认值:0.75)

Advanced Context Retrieval Strategies

高级上下文检索策略

1. Semantic Vector Search

1. 语义向量搜索

  • Utilize multi-dimensional embedding models for context retrieval
  • Employ cosine similarity and vector clustering techniques
  • Support multi-modal embedding (text, code, architectural diagrams)
python
def semantic_context_retrieve(project_id, query_vector, top_k=5):
    """Semantically retrieve most relevant context vectors"""
    vector_db = VectorDatabase(project_id)
    matching_contexts = vector_db.search(
        query_vector,
        similarity_threshold=0.75,
        max_results=top_k
    )
    return rank_and_filter_contexts(matching_contexts)
  • 利用多维度嵌入模型进行上下文检索
  • 采用余弦相似度和向量聚类技术
  • 支持多模态嵌入(文本、代码、架构图)
python
def semantic_context_retrieve(project_id, query_vector, top_k=5):
    """Semantically retrieve most relevant context vectors"""
    vector_db = VectorDatabase(project_id)
    matching_contexts = vector_db.search(
        query_vector,
        similarity_threshold=0.75,
        max_results=top_k
    )
    return rank_and_filter_contexts(matching_contexts)

2. Relevance Filtering and Ranking

2. 相关性过滤与排序

  • Implement multi-stage relevance scoring
  • Consider temporal decay, semantic similarity, and historical impact
  • Dynamic weighting of context components
python
def rank_context_components(contexts, current_state):
    """Rank context components based on multiple relevance signals"""
    ranked_contexts = []
    for context in contexts:
        relevance_score = calculate_composite_score(
            semantic_similarity=context.semantic_score,
            temporal_relevance=context.age_factor,
            historical_impact=context.decision_weight
        )
        ranked_contexts.append((context, relevance_score))

    return sorted(ranked_contexts, key=lambda x: x[1], reverse=True)
  • 实现多阶段相关性评分
  • 考虑时间衰减、语义相似度和历史影响
  • 动态加权上下文组件
python
def rank_context_components(contexts, current_state):
    """Rank context components based on multiple relevance signals"""
    ranked_contexts = []
    for context in contexts:
        relevance_score = calculate_composite_score(
            semantic_similarity=context.semantic_score,
            temporal_relevance=context.age_factor,
            historical_impact=context.decision_weight
        )
        ranked_contexts.append((context, relevance_score))

    return sorted(ranked_contexts, key=lambda x: x[1], reverse=True)

3. Context Rehydration Patterns

3. 上下文复现模式

  • Implement incremental context loading
  • Support partial and full context reconstruction
  • Manage token budgets dynamically
python
def rehydrate_context(project_context, token_budget=8192):
    """Intelligent context rehydration with token budget management"""
    context_components = [
        'project_overview',
        'architectural_decisions',
        'technology_stack',
        'recent_agent_work',
        'known_issues'
    ]

    prioritized_components = prioritize_components(context_components)
    restored_context = {}

    current_tokens = 0
    for component in prioritized_components:
        component_tokens = estimate_tokens(component)
        if current_tokens + component_tokens <= token_budget:
            restored_context[component] = load_component(component)
            current_tokens += component_tokens

    return restored_context
  • 实现增量式上下文加载
  • 支持部分和完整上下文重构
  • 动态管理令牌预算
python
def rehydrate_context(project_context, token_budget=8192):
    """Intelligent context rehydration with token budget management"""
    context_components = [
        'project_overview',
        'architectural_decisions',
        'technology_stack',
        'recent_agent_work',
        'known_issues'
    ]

    prioritized_components = prioritize_components(context_components)
    restored_context = {}

    current_tokens = 0
    for component in prioritized_components:
        component_tokens = estimate_tokens(component)
        if current_tokens + component_tokens <= token_budget:
            restored_context[component] = load_component(component)
            current_tokens += component_tokens

    return restored_context

4. Session State Reconstruction

4. 会话状态重构

  • Reconstruct agent workflow state
  • Preserve decision trails and reasoning contexts
  • Support multi-agent collaboration history
  • 重构Agent工作流状态
  • 保留决策轨迹和推理上下文
  • 支持多Agent协作历史

5. Context Merging and Conflict Resolution

5. 上下文合并与冲突解决

  • Implement three-way merge strategies
  • Detect and resolve semantic conflicts
  • Maintain provenance and decision traceability
  • 实现三方合并策略
  • 检测并解决语义冲突
  • 维护来源和决策可追溯性

6. Incremental Context Loading

6. 增量式上下文加载

  • Support lazy loading of context components
  • Implement context streaming for large projects
  • Enable dynamic context expansion
  • 支持上下文组件的懒加载
  • 为大型项目实现上下文流式传输
  • 启用动态上下文扩展

7. Context Validation and Integrity Checks

7. 上下文验证与完整性检查

  • Cryptographic context signatures
  • Semantic consistency verification
  • Version compatibility checks
  • 加密上下文签名
  • 语义一致性验证
  • 版本兼容性检查

8. Performance Optimization

8. 性能优化

  • Implement efficient caching mechanisms
  • Use probabilistic data structures for context indexing
  • Optimize vector search algorithms
  • 实现高效缓存机制
  • 使用概率数据结构进行上下文索引
  • 优化向量搜索算法

Reference Workflows

参考工作流

Workflow 1: Project Resumption

工作流1:项目恢复

  1. Retrieve most recent project context
  2. Validate context against current codebase
  3. Selectively restore relevant components
  4. Generate resumption summary
  1. 检索最新项目上下文
  2. 针对当前代码库验证上下文
  3. 选择性恢复相关组件
  4. 生成恢复摘要

Workflow 2: Cross-Project Knowledge Transfer

工作流2:跨项目知识迁移

  1. Extract semantic vectors from source project
  2. Map and transfer relevant knowledge
  3. Adapt context to target project's domain
  4. Validate knowledge transferability
  1. 从源项目提取语义向量
  2. 映射并迁移相关知识
  3. 调整上下文以适配目标项目领域
  4. 验证知识可迁移性

Usage Examples

使用示例

bash
undefined
bash
undefined

Full context restoration

完整上下文恢复

context-restore project:ai-assistant --mode full
context-restore project:ai-assistant --mode full

Incremental context update

增量式上下文更新

context-restore project:web-platform --mode incremental
context-restore project:web-platform --mode incremental

Semantic context query

语义上下文查询

context-restore project:ml-pipeline --query "model training strategy"
undefined
context-restore project:ml-pipeline --query "model training strategy"
undefined

Integration Patterns

集成模式

  • RAG (Retrieval Augmented Generation) pipelines
  • Multi-agent workflow coordination
  • Continuous learning systems
  • Enterprise knowledge management
  • RAG(检索增强生成)流水线
  • 多Agent工作流协调
  • 持续学习系统
  • 企业知识管理

Future Roadmap

未来路线图

  • Enhanced multi-modal embedding support
  • Quantum-inspired vector search algorithms
  • Self-healing context reconstruction
  • Adaptive learning context strategies
  • 增强多模态嵌入支持
  • 类量子向量搜索算法
  • 自修复上下文重构
  • 自适应学习上下文策略