定制 mitmelon/zionxmemory 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

mitmelon/zionxmemory

最新稳定版本:v2.0.0

Composer 安装命令:

composer require mitmelon/zionxmemory

包简介

Production-ready, research-backed, enterprise-grade adaptive memory system that maintains the core principle: ZionXMemory is memory infrastructure, not an agent controller.

README 文档

README

ZionXMemory Logo

🧠 ZionXMemory v2

Next-Generation Epistemic Memory Infrastructure with Adaptive Intelligence

⚠️ Work in Progress — Unstable

This project is under active development and may contain bugs or breaking changes.

🆕 What's New in v2

ZionXMemory v2 extends the proven v1 architecture with adaptive memory capabilities inspired by cutting-edge research:

New Features

MIRAS-Inspired Adaptive Memory

  • Surprise/novelty scoring without model internals
  • Importance weighting and retention gating
  • Controlled forgetting with preservation policies

ATLAS Priority Management

  • Optimal long-term memory prioritization
  • Usage-based importance learning
  • Context-aware retrieval optimization

Hierarchical Compression

  • Multi-level compression with semantic preservation
  • Surprise-aware compression (high-surprise → less compression)
  • Automatic storage optimization

ResFormer/Reservoir Principles

  • Linear-time memory operations
  • Efficient handling of ultra-long contexts
  • Hierarchical sparse attention support

Cognitive Chunking (CHREST-inspired)

  • Pattern-based memory organization
  • Efficient retrieval structures
  • Logarithmic query complexity

Core Principles (Unchanged)

✅ ZionXMemory IS:

  • A memory substrate for any AI agent or LLM
  • Epistemically honest (preserves uncertainty)
  • Non-destructive (append-only)
  • Agent-neutral (no behavior control)
  • Model-agnostic (Gemini, OpenAI, Claude etc.)

❌ ZionXMemory IS NOT:

  • An agent framework
  • A decision-making system
  • A behavior controller
  • A workflow engine

ZionXMemory provides memory intelligence, not control.

Architecture v2

Three-Layer Core (v1)

  1. Mindscape RAG - Narrative memory with temporal stratification
  2. Graph RAG - Structured knowledge with temporal versioning
  3. Gnosis - Epistemic state tracking with belief lifecycle

Adaptive Extensions (v2)

  1. Adaptive Memory Module - MIRAS-inspired importance weighting
  2. ATLAS Priority - Optimal context prioritization
  3. Hierarchical Compression - Multi-level semantic compression
  4. Retention Gate - Controlled forgetting policies

Quick Start

Installation

composer require mitmelon/zionxmemory

Basic Usage (v2)

use ZionXMemory\Orchestrator\HybridMemoryV2;
use ZionXMemory\Storage\Adapters\RedisAdapter;
use ZionXMemory\AI\Adapters\GeminiAdapter;
use ZionXMemory\Audit\AuditLogger;

// Initialize
$storage = new RedisAdapter();
$storage->connect(['host' => '127.0.0.1', 'port' => 6379]);

$ai = new GeminiAdapter();
$ai->configure([
    'api_key' => getenv('GEMINI_API_KEY'),
    'model' => 'gemini-3-flash-preview',
    // Optional: tune retry behaviour for production
    'retry' => ['max_attempts' => 4, 'base_delay_ms' => 250]
]);

$audit = new AuditLogger($storage);

// Create v2 orchestrator (adaptive features enabled)
$memory = new HybridMemoryV2($storage, $ai, $audit, [
    'enable_adaptive' => true
]);

// Store memory with surprise signal
$result = $memory->storeMemoryAdaptive('tenant_id', 'agent_id', [
    'type' => 'research_finding',
    'content' => 'Discovered unexpected pattern contradicting existing theory...',
    'claims' => [
        ['text' => 'Pattern X contradicts theory Y', 'confidence' => ['min' => 0.8, 'max' => 0.95, 'mean' => 0.9]]
    ]
], [
    'magnitude' => 0.85,  // Agent's surprise signal
    'momentum' => 0.2,
    'components' => [
        'novelty' => 0.9,
        'contradiction' => 0.8
    ]
]);

// Get ATLAS-optimized context
$context = $memory->buildOptimizedContext('tenant_id', 'agent_id', [
    'max_tokens' => 8000,
    'query_context' => [
        'query_type' => 'important'  // Prioritize important memories
    ]
]);

// Query by surprise threshold
$highSurprise = $memory->queryAdaptive('tenant_id', [
    'surprise_threshold' => 0.7,
    'prioritize' => true
]);

Adaptive Features Deep Dive

1. Surprise Metric Scoring

External surprise calculation without model internals:

// Automatic surprise computation
$surprise = $memory->computeSurprise($existingMemories, $newMemory);

// Components:
// - Novelty: semantic difference from existing context
// - Contradiction: conflicts with existing beliefs
// - Evidence: accumulation of supporting evidence
// - Confidence shift: magnitude of belief updates
// - Agent disagreement: multi-agent conflict signals

Surprise Score Range: 0.0 (routine) to 1.0 (revolutionary)

2. Retention Gate & Forgetting

Configurable retention policies (non-enforcing):

$memory->configureAdaptive('tenant_id', [
    'retention_policy' => [
        'name' => 'research_focused',
        'retention_weights' => [
            'surprise' => 0.35,      // High surprise = high retention
            'contradiction' => 0.25,  // Preserve contradictions
            'temporal' => 0.10,       // Recency weight
            'evidence' => 0.20,       // Evidence-based retention
            'usage' => 0.10          // Access patterns
        ],
        'promotion_threshold' => 0.7,   // Move to hot layer
        'compression_threshold' => 0.3,  // Compress to cold
        'compression_age_days' => 30,    // Age before compression
        'decay_rate' => 0.1              // Importance decay per day
    ]
]);

Retention evaluates but never enforces:

$evaluation = $memory->evaluateRetention('tenant_id');
// Returns:
// - Compression recommendations (agent decides)
// - Promotion candidates (agent decides)
// - Current distribution by layer

3. ATLAS Priority Management

Optimal context prioritization:

// Priority factors:
// - Relevance to query
// - Recency (configurable half-life)
// - Importance (learned from usage)
// - Surprise score
// - Usage frequency
// - Context fit (epistemic coherence)

$context = $memory->buildOptimizedContext('tenant_id', 'agent_id', [
    'max_tokens' => 8000,
    'query_context' => [
        'query_type' => 'novel',  // Options: recent, important, novel
        'text' => 'breakthrough discoveries patterns'
    ]
]);

Usage-based learning:

// System learns which memories are useful
$memory->recordMemoryUsage('tenant_id', [
    ['memory_id' => 'mem_123', 'utility' => 0.9],
    ['memory_id' => 'mem_456', 'utility' => 0.7]
]);

// Importance scores adapt over time

4. Hierarchical Compression

Multi-level compression with surprise preservation:

// Compression Levels:
// Level 0: Full (100% - no compression)
// Level 1: Light (70% - selective detail)
// Level 2: Medium (40% - key points)
// Level 3: Heavy (20% - core summary)
// Level 4: Extreme (10% - minimal reference)

// High-surprise memories get less compression
// Low-surprise memories compressed more aggressively

$metrics = $memory->getAdaptiveMetrics('tenant_id');
echo "Compression ratio: {$metrics['compression_ratio']}\n";
echo "Storage saved: {$metrics['storage_saved_bytes']} bytes\n";

5. Memory Layers

Dynamic layer assignment:

Layer Surprise Range Compression Access Speed Retention
Hot 0.7 - 1.0 None (Level 0) Instant High
Warm 0.4 - 0.7 Light (Level 1) Fast Medium
Cold 0.2 - 0.4 Medium (Level 2) Normal Low
Frozen 0.0 - 0.2 Heavy (Level 3-4) Slow Minimal

Memories automatically promoted/demoted based on:

  • Surprise score
  • Usage patterns
  • Age
  • Importance

Research Integration

MIRAS (Memory Importance-weighted Retention Adaptation System)

Key Concepts Implemented:

  • ✅ Adaptive surprise metric (external to model)
  • ✅ Importance weighting
  • ✅ Retention gating (controlled forgetting)
  • ✅ Temporal memory regularization

ATLAS (Adaptive Long-Term Attention)

Key Concepts Implemented:

  • ✅ Optimal context streaming
  • ✅ Usage-based learning
  • ✅ Representational capacity optimization
  • ✅ Priority-based retrieval

ResFormer/Reservoir Memory

Key Concepts Implemented:

  • ✅ Linear-time sequence handling
  • ✅ Variable-length context support
  • ✅ Efficient memory banks

Logarithmic Memory Networks

Key Concepts Implemented:

  • ✅ Hierarchical indexing
  • ✅ O(log n) query complexity
  • ✅ Efficient long-sequence retrieval

CHREST (Cognitive Chunking)

Key Concepts Implemented:

  • ✅ Pattern-based organization
  • ✅ Cognitive chunk creation
  • ✅ Efficient retrieval structures

API Reference

New v2 Methods

// Adaptive storage
storeMemoryAdaptive(
    string $tenantId,
    string $agentId,
    array $data,
    array $surpriseSignal = []
): array

// Optimized context
buildOptimizedContext(
    string $tenantId,
    string $agentId,
    array $options = []
): array

// Adaptive queries
queryAdaptive(
    string $tenantId,
    array $query
): array

// Retention evaluation (non-enforcing)
evaluateRetention(string $tenantId): array

// Usage tracking (ATLAS learning)
recordMemoryUsage(
    string $tenantId,
    array $accessLog
): void

// Configuration
configureAdaptive(
    string $tenantId,
    array $config
): bool

// Metrics
getAdaptiveMetrics(string $tenantId): array

Surprise Signal Format

[
    'magnitude' => 0.0-1.0,        // Overall surprise
    'momentum' => 0.0-1.0,         // Rate of change (optional)
    'components' => [              // Breakdown (optional)
        'novelty' => 0.0-1.0,
        'contradiction' => 0.0-1.0,
        'evidence' => 0.0-1.0,
        'confidence_shift' => 0.0-1.0,
        'disagreement' => 0.0-1.0
    ],
    'timestamp' => int
]

Performance

Benchmarks (v2 with Adaptive Features)

Operation Time Throughput
Store with surprise <50ms 20/sec
Optimized context build <200ms 5/sec
Surprise computation <100ms 10/sec
Retention evaluation <150ms 7/sec
Query by surprise <75ms 13/sec

Scaling

  • ✅ Handles millions of memories
  • Sub-second retrieval with ATLAS priority
  • 30-60% storage savings via compression
  • Linear time complexity for most operations
  • Logarithmic query complexity with indexing

Memory Efficiency

Without compression:  1000 memories = 10 MB
With v2 compression:  1000 memories = 4-7 MB (40-70% savings)

High-surprise memories: Minimal compression (preserve detail)
Low-surprise memories: Aggressive compression (save space)

Multi-Agent Support (Enhanced)

v2 adds adaptive features to multi-agent scenarios:

// Each agent gets surprise-optimized context
$agent1Context = $memory->buildOptimizedContext($tenantId, 'agent1');
$agent2Context = $memory->buildOptimizedContext($tenantId, 'agent2');

// High-surprise contradictions preserved for both
// Each sees their own priority-ranked memories
// No forced consensus—disagreements persist

Configuration Examples

Conservative (Research/Legal)

$memory->configureAdaptive($tenantId, [
    'retention_policy' => [
        'retention_weights' => [
            'surprise' => 0.40,      // High surprise preservation
            'contradiction' => 0.30, // Preserve conflicts
            'evidence' => 0.20,      // Evidence-based
            'temporal' => 0.05,      // Low recency bias
            'usage' => 0.05
        ],
        'compression_age_days' => 90,  // Long retention
        'decay_rate' => 0.05            // Slow decay
    ]
]);

Aggressive (High-Volume/Operational)

$memory->configureAdaptive($tenantId, [
    'retention_policy' => [
        'retention_weights' => [
            'temporal' => 0.40,      // Favor recent
            'usage' => 0.30,         // Favor accessed
            'surprise' => 0.20,
            'evidence' => 0.10
        ],
        'compression_age_days' => 7,   // Fast compression
        'decay_rate' => 0.3             // Rapid decay
    ]
]);

Migration from v1

v2 is fully backward compatible with v1:

// v1 code works unchanged
$memory = new HybridMemory($storage, $ai, $audit);
$result = $memory->storeMemory($tenantId, $agentId, $data);

// v2 adds adaptive features (optional)
$memoryV2 = new HybridMemoryV2($storage, $ai, $audit);
$result = $memoryV2->storeMemoryAdaptive($tenantId, $agentId, $data, $surpriseSignal);

// Disable adaptive features if needed
$memoryV2 = new HybridMemoryV2($storage, $ai, $audit, [
    'enable_adaptive' => false  // Acts like v1
]);

Roadmap

v2.1 (Q2 2026)

  • Vector similarity search integration
  • Cross-model surprise calibration
  • Advanced chunking strategies
  • Sparse attention optimizations

v2.2 (Q3 2026)

  • Federated adaptive memory
  • Multi-modal surprise scoring
  • Real-time retention adaptation
  • Benchmark suite release

v3.0 (Q4 2027)

  • Human-AI shared adaptive memory
  • Formal epistemic guarantees
  • Production-scale optimization
  • Enterprise dashboard

Citations

If you use ZionXMemory v2 in research:

@software{zionxmemory_v2_2026,
  title={ZionXMemory v2: Adaptive Epistemic Memory Infrastructure},
  author={ZionXMemory Contributors},
  year={2026},
  url={https://github.com/mitmelon/zionxmemory},
  note={Integrates MIRAS, ATLAS, ResFormer, and cognitive chunking principles}
}

Research References

  1. MIRAS/Titans - Google Research - Surprise-based retention
  2. ATLAS - Optimal long-term memory
  3. Ultra-Long Context - Hierarchical sparse attention
  4. ResFormer - Reservoir memory for sequences
  5. Logarithmic Memory - Efficient retrieval structures
  6. CHREST - Wikipedia - Cognitive chunking principles

License

MIT License - see LICENSE

Built for AI systems that need to remember intelligently across years, not just conversations.

v2: Now with adaptive intelligence inspired by the latest memory research.

统计信息

  • 总下载量: 0
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 3
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-16

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固