Install
openclaw skills install memory-system-completeComplete memory system with causal graph, knowledge graph, auto-detection, and evolution features
openclaw skills install memory-system-complete完整记忆系统:双脑架构 + 因果图谱 + 知识图谱 + 自动检测 + 进化系统
完整的记忆管理系统,支持:
⚠️ 重要说明
此技能不包含任何预置的记忆数据。
安装后,用户将获得:
用户需要根据自己的需求添加记忆数据。
功能: 自动检测和存储记忆之间的因果关系
因果类型:
direct - 直接因果indirect - 间接因果conditional - 条件因果probabilistic - 概率因果核心功能:
使用示例:
from scripts.causal_knowledge_graphs import CausalGraph
causal_graph = CausalGraph("memory/database/xiaozhi_memory.db")
# 添加因果关系
causal_graph.add_causal_relation(
cause_id=1,
effect_id=2,
causal_type='direct',
strength=0.8,
confidence=0.9,
evidence='Test evidence'
)
# 获取原因
causes = causal_graph.get_causes(effect_id=2)
# 获取结果
effects = causal_graph.get_effects(cause_id=1)
# 获取因果链
chain = causal_graph.get_causal_chain(start_id=1, max_depth=5)
# 检测因果循环
cycles = causal_graph.detect_causal_cycles()
功能: 自动检测和存储知识点之间的各种关系
关系类型:
is_a - 是一种(继承)part_of - 是一部分(组成)related_to - 相关similar_to - 相似opposite_of - 相反depends_on - 依赖precedes - 先于follows - 跟随causes - 导致(因果关系)caused_by - 由...导致(因果关系)contains - 包含contained_in - 包含于exemplifies - 例证exemplified_by - 被例证context_for - 是...的上下文context_of - ...的上下文核心功能:
使用示例:
from scripts.causal_knowledge_graphs import KnowledgeGraph
knowledge_graph = KnowledgeGraph("memory/database/xiaozhi_memory.db")
# 添加关系
knowledge_graph.add_relation(
source_id=1,
target_id=2,
relation_type='related_to',
strength=0.7,
direction='bidirectional'
)
# 获取关系
relations = knowledge_graph.get_relations(memory_id=1)
# 获取相关记忆(多跳)
related = knowledge_graph.get_related_memories(memory_id=1, relation_type='related_to', max_depth=2)
# 查找最短路径
path = knowledge_graph.find_shortest_path(source_id=1, target_id=3)
# 检测社区
communities = knowledge_graph.detect_communities()
功能: 基于关键词、相似度、类别自动检测关系
检测方法:
使用示例:
from scripts.auto_relation_detector import AutoRelationManager
manager = AutoRelationManager("memory/database/xiaozhi_memory.db")
# 自动检测并添加关系
result = manager.auto_detect_and_add_relations(memory_id=1)
print(f"Found {len(result['causal_relations'])} causal relations")
print(f"Found {len(result['knowledge_relations'])} knowledge relations")
# 批量检测
results = manager.batch_detect_relations(limit=100)
功能: 基于llm-wiki最佳实践的记忆系统进化
核心改进:
使用示例:
from scripts.memory_system_v2 import MemorySystemV2
memory = MemorySystemV2()
memory.initialize()
# 保存记忆(自动触发两步摄入)
memory_id = memory.save(
type='learning',
title='New Learning',
content='This is a new learning',
category='knowledge'
)
# 四阶段检索
results = memory.search("python best practices")
# 获取统计信息
stats = memory.get_statistics()
安装后运行以下命令初始化数据库:
# 初始化数据库(v2.0)
python scripts/init_database_v2.py
# 或使用Python API
from scripts.memory_system_v2 import MemorySystemV2
memory = MemorySystemV2()
memory.initialize()
数据库文件将创建在:
memory/database/xiaozhi_memory.dbmemory/database/lancedb/安装后的目录结构:
memory-system-complete/
├── scripts/
│ ├── memory_system_v2.py # v2.0核心代码
│ ├── init_database_v2.py # v2.0数据库初始化
│ ├── verify_install_v2.py # v2.0安装验证
│ ├── causal_knowledge_graphs.py # 因果和知识图谱
│ └── auto_relation_detector.py # 自动关系检测
├── examples/
│ └── usage_demo_v2.py # v2.0使用示例
├── memory/
│ └── database/ # 数据库目录(空)
│ ├── xiaozhi_memory.db # 安装后创建
│ └── lancedb/ # 安装后创建
├── SKILL.md
└── README.md
python scripts/verify_install_v2.py
from scripts.memory_system_v2 import MemorySystemV2
# 初始化
memory = MemorySystemV2()
success = memory.initialize()
if success:
print("✅ Installation verified!")
# 保存测试记忆
test_id = memory.save(
type='test',
title='Installation Test v2.0',
content='Testing memory system v2.0 installation',
importance=5
)
# 查询测试
result = memory.get(test_id)
if result:
print("✅ Memory system v2.0 working!")
memory.delete(test_id) # 清理测试数据
else:
print("❌ Memory system v2.0 failed!")
else:
print("❌ Initialization failed!")
安装脚本会自动:
pip install numpy>=1.20.0
pip install networkx>=2.0
pip install lancedb>=0.3.0
pip install sentence-transformers>=2.0.0
# 安装Ollama
# 访问: https://ollama.com
# 拉取嵌入模型
ollama pull nomic-embed-text
ollama pull mxbai-embed-large
ollama pull all-minilm
# 启动Ollama服务
ollama serve
clawhub install memory-system-complete
cd ~/.openclaw/skills/memory-system-complete
python scripts/init_database_v2.py
python scripts/verify_install_v2.py
from scripts.memory_system_v2 import MemorySystemV2
memory = MemorySystemV2()
memory.initialize()
# 保存第一条记忆
memory_id = memory.save(
type='learning',
title='My First Memory v2.0',
content='This is my first memory in the system v2.0',
category='knowledge',
tags=['first', 'v2.0'],
importance=7
)
print("Memory system v2.0 ready!")
from scripts.auto_relation_detector import AutoRelationManager
manager = AutoRelationManager("memory/database/xiaozhi_memory.db")
# 自动检测并添加关系
result = manager.auto_detect_and_add_relations(memory_id)
print(f"Found {len(result['causal_relations'])} causal relations")
print(f"Found {len(result['knowledge_relations'])} knowledge relations")
from scripts.factor_inference_system import FactorInferenceSystem
system = FactorInferenceSystem()
# 因子分析
import numpy as np
X = np.random.randn(100, 10)
result = system.analyze_factors(X, n_components=3)
print(f"Explained variance: {result.explained_variance_ratio}")
# 因果推断
treatment = np.random.randint(0, 2, 100)
outcome = np.random.randn(100) + 0.5 * treatment
result = system.infer_causal_effect(treatment, outcome)
print(f"Treatment effect: {result.treatment_effect}")
# 潜在变量模型
result = system.discover_latent_variables(X, n_components=3)
print(f"Log likelihood: {result.log_likelihood}")
# 贝叶斯推断
def log_likelihood(x):
return -0.5 * np.sum(x ** 2)
prior_mean = np.zeros(10)
prior_cov = np.eye(10)
result = system.bayesian_infer(log_likelihood, prior_mean, prior_cov, n_samples=1000)
print(f"Log evidence: {result.log_evidence}")
# 矩阵分解
result = system.factorize_matrix(X, rank=3)
print(f"Reconstruction error: {result.error}")
# 结构方程模型
model = {'variables': ['X1', 'X2', 'Y'], 'paths': [('X1', 'X2'), ('X2', 'Y')]}
sem_data = np.random.randn(100, 3)
result = system.fit_sem(sem_data, model)
print(f"Path coefficients: {result.path_coefficients}")
from scripts.genetic_neuron_memory_system import GeneticNeuronMemorySystem
system = GeneticNeuronMemorySystem()
system.initialize()
# 创建神经元
neuron_id = system.create_neuron(type='excitatory')
# 创建连接
connection_id = system.create_connection(neuron_id, target_id, strength=0.8)
# 调整突触权重
system.adjust_weights(learning_rate=0.01)
# 巩固记忆
system.consolidate_memory(memory_id, consolidation_threshold=0.7)
# 计算注意力
attention = system.compute_attention(inputs, query)
# 调制神经元
system.modulate_neurons(dopamine=0.5, serotonin=0.3)
# 计算脉冲
spikes = system.compute_spikes(inputs, time_steps=100)
# 适应结构
system.adapt_structure()
# 检测模块
modules = system.detect_modules()
# 进化优化
optimized = system.evolve(generations=100)
# 检查权限
chmod +w memory/database
# 重新初始化
python scripts/init_database_v2.py --force
# 安装networkx
pip install networkx
# 或使用纯SQLite模式
# 系统会自动降级到基础功能
# 检查数据库连接
python -c "import sqlite3; conn = sqlite3.connect('memory/database/xiaozhi_memory.db'); print('OK')"
# 重新运行检测
python scripts/batch_detect_relations.py
更新时间: 2026-04-12 版本: 3.0.0
init_database.py)verify_install.py)