← 返回
未分类 中文

knowledge-graph-memory

Builds and maintains a knowledge graph for long-term memory with concept drift detection and temporal reasoning. Use when storing structured knowledge, detec...
构建并维护用于长期记忆的知识图谱,具备概念漂移检测与时序推理能力。适用于存储结构化知识、检测概念漂移及进行时序推理。
jpengcheng523-netizen
未分类 clawhub v1.0.0 1 版本 100000 Key: 无需
★ 0
Stars
📥 879
下载
💾 3
安装
1
版本
#latest

概述

Knowledge Graph Memory

Long-term memory system with knowledge graph, concept drift detection, and temporal reasoning.

When to Use

  • Building knowledge graphs from concepts and relationships
  • Detecting concept drift over time
  • Temporal reasoning and time-based queries
  • Long-term memory storage with consolidation

Usage

const { KnowledgeGraph, Memory } = require('./skills/knowledge-graph-memory');

// Create a knowledge graph
const kg = new KnowledgeGraph();

// Add concepts
kg.addConcept('AI', { category: 'technology', importance: 0.9 });
kg.addConcept('Machine Learning', { category: 'technology' });

// Link concepts
kg.link('AI', 'Machine Learning', 'includes');

// Find related concepts
const related = kg.getRelated('AI');

// Detect concept drift
const drift = kg.detectDrift('AI');

// Search concepts
const results = kg.search({ name: 'AI' });

Features

  • Knowledge Graph: Nodes (concepts) and edges (relationships)
  • Concept Drift Detection: ADWIN, DDM, statistical methods
  • Temporal Reasoning: Time-based queries and event tracking
  • Memory Consolidation: Promote important memories, forget unused ones

API

KnowledgeGraph

const kg = new KnowledgeGraph({
  maxNodes: 10000,
  consolidationThreshold: 0.1,
  driftDetection: { method: 'statistical', threshold: 2.0 }
});

// Add and get concepts
kg.addConcept(name, properties);
kg.getConcept(idOrName);

// Create relationships
kg.link(sourceId, targetId, edgeType, properties);

// Query
kg.getRelated(conceptId, edgeType);
kg.findPath(startId, endId, maxDepth);
kg.search({ name: 'pattern', type: 'concept' });

// Drift detection
kg.detectDrift(conceptId);

// Memory management
kg.consolidate();
kg.removeConcept(id);

// Serialization
kg.toJSON();
KnowledgeGraph.fromJSON(data);

Concept

const concept = new Concept({
  name: 'AI',
  type: 'concept',
  properties: { category: 'technology' },
  importance: 0.8
});

concept.access();  // Increment access count
concept.update({ newProperty: 'value' });  // Update with history

DriftDetector

const detector = new DriftDetector({
  method: 'statistical',
  windowSize: 100,
  threshold: 2.0
});

const result = detector.addSample(value);
// { drift: boolean, warning: boolean, mean, stdDev }

TemporalReasoner

const reasoner = new TemporalReasoner();

reasoner.addEvent({ type: 'concept_added', conceptId: 'AI' });
reasoner.getEventsInRange(start, end);
reasoner.getEventsBefore(time);
reasoner.getEventsAfter(time);
reasoner.getRecentEvents(10);

Memory

const memory = new Memory({
  shortTermMaxSize: 100,
  consolidationInterval: 3600000
});

memory.remember('key', { data: 'value' }, { importance: 0.8 });
memory.recall('key');
memory.forget('key');
memory.consolidate();

Node Types

  • CONCEPT: Abstract concept
  • ENTITY: Concrete entity
  • EVENT: Time-based event
  • FACT: Verified fact
  • RELATION: Relationship node

Edge Types

  • IS_A: Inheritance relationship
  • HAS_A: Composition relationship
  • RELATED_TO: Generic relationship
  • CAUSES: Causal relationship
  • PRECEDES: Temporal ordering
  • INCLUDES: Set membership
  • SIMILAR_TO: Similarity relationship
  • DERIVED_FROM: Derivation relationship

Example: Building a Knowledge Base

const { KnowledgeGraph, EdgeType } = require('./skills/knowledge-graph-memory');

const kg = new KnowledgeGraph();

// Build knowledge structure
kg.addConcept('Technology', { category: 'domain' });
kg.addConcept('AI', { category: 'field' });
kg.addConcept('Machine Learning', { category: 'subfield' });
kg.addConcept('Neural Networks', { category: 'technique' });
kg.addConcept('Deep Learning', { category: 'technique' });

// Create relationships
kg.link('AI', 'Technology', EdgeType.IS_A);
kg.link('Machine Learning', 'AI', EdgeType.IS_A);
kg.link('Neural Networks', 'Machine Learning', EdgeType.IS_A);
kg.link('Deep Learning', 'Neural Networks', EdgeType.IS_A);
kg.link('Deep Learning', 'Machine Learning', EdgeType.RELATED_TO);

// Query the graph
const mlRelated = kg.getRelated('Machine Learning');
const path = kg.findPath('Deep Learning', 'Technology');

console.log('ML related concepts:', mlRelated.map(r => r.concept.name));
console.log('Path:', path?.map(c => c.name));

Example: Concept Drift Detection

const { KnowledgeGraph } = require('./skills/knowledge-graph-memory');

const kg = new KnowledgeGraph();
kg.addConcept('User Behavior', { pattern: 'initial' });

// Simulate concept evolution
for (let i = 0; i < 50; i++) {
  const concept = kg.getConcept('User Behavior');
  concept.update({ pattern: `evolved_${i}` });
  
  const drift = kg.detectDrift('User Behavior');
  if (drift.drift) {
    console.log('Drift detected at iteration', i);
  }
}

Example: Memory Consolidation

const { Memory } = require('./skills/knowledge-graph-memory');

const memory = new Memory();

// Store memories
memory.remember('important_fact', { value: 'critical data' }, { importance: 0.9 });
memory.remember('temporary_note', { value: 'temp data' }, { importance: 0.3 });

// Access important memory multiple times
for (let i = 0; i < 5; i++) {
  memory.recall('important_fact');
}

// Consolidate - promotes frequently accessed to long-term
const result = memory.consolidate();
console.log('Promoted:', result.promoted, 'Removed:', result.removed);

版本历史

共 1 个版本

  • v1.0.0 当前
    2026-05-03 03:49 安全 安全

安全检测

腾讯云安全 (Keen)

安全,无风险
查看报告

腾讯云安全 (Sanbu)

安全,无风险
查看报告

🔗 相关推荐

Self-Improving Agent (Proactive Self-Reflection)

jpengcheng523-netizen
自我反思、自我批评、自主学习与自组织记忆。智能体能评估自身工作、发现错误并实现永久性改进。
★ 0 📥 1,030

Data Analyzer

jpengcheng523-netizen
数据分析与可视化技能,支持 CSV、Excel、JSON 数据,提供统计分析、图表与报告功能
★ 0 📥 704

Web Scraper

jpengcheng523-netizen
支持 JavaScript 渲染的网页抓取技能,使用 CSS 选择器、XPath 或 AI 提取网站数据。
★ 0 📥 530