Summary
I'd like to propose adding a three-tier hierarchical memory layer (L0/L1/L2) to memory-lancedb-pro, inspired by the architecture in jzOcb/ai-agent-memory.
While memory-lancedb-pro excels at hybrid retrieval (Vector + BM25) and cross-encoder reranking for large-scale semantic search, the L0/L1/L2 hierarchy from ai-agent-memory offers a complementary approach that could significantly reduce token consumption and improve retrieval efficiency.
Background: What is L0/L1/L2?
The hierarchical memory system from ai-agent-memory organizes memories into three layers:
| Layer |
Location |
Content |
When to Read |
| L0 |
.abstract files |
Directory overview (one-sentence index) |
Always first |
| L1 |
insights/, lessons/ |
Distilled patterns and structured summaries |
On demand |
| L2 |
YYYY-MM-DD.md |
Full daily logs and raw narratives |
Deep dive only |
Key benefit: 90% of queries need only L0 + L1, dramatically reducing token usage while maintaining context quality.
This design is inspired by OpenViking (ByteDance) and aligns with the "reflection" mechanism from Stanford Generative Agents.
Why This Complements memory-lancedb-pro
memory-lancedb-pro already has excellent features:
- ✅ Hybrid retrieval (Vector + BM25)
- ✅ Cross-encoder reranking
- ✅ Smart extraction with 6-category classification
- ✅ Weibull decay + 3-tier promotion (Peripheral ⟷ Working ⟷ Core)
However, the current system treats all memories at the same granularity level. Adding L0/L1/L2 would:
- Reduce token consumption: Most queries can be answered with L0 (index) + L1 (summary) without loading full L2 (narrative)
- Improve retrieval precision: L0 acts as a fast filter before expensive vector search
- Enable progressive disclosure: Start with L0 overview → drill down to L1 insights → access L2 details only when needed
- Complement existing features: L0/L1/L2 can work alongside the existing 6-category system (profile, preferences, entities, events, cases, patterns)
Proposed Implementation
Option A: Metadata-Based Layers (Minimal Change)
Add a layer field to the existing memory schema:
interface Memory {
// ... existing fields ...
layer: 'L0' | 'L1' | 'L2'; // New field
l0_index?: string; // One-sentence summary for L0
l1_summary?: string; // Structured summary for L1
l2_narrative?: string; // Full content for L2
}
Retrieval flow:
- Query L0 entries first (fast, low token cost)
- If L0 matches, retrieve corresponding L1 summaries
- Only fetch L2 narratives when explicitly needed
Option B: Separate Tables (Clean Separation)
Create three LanceDB tables:
memories_l0 — Index layer (one-sentence per memory)
memories_l1 — Summary layer (structured insights)
memories_l2 — Narrative layer (full content)
Link them via memory_id foreign key.
Option C: Hybrid Approach
- Keep existing
memories table for L2 (full content)
- Add
memories_index table for L0/L1 (lightweight summaries)
- Use existing smart extraction to automatically generate L0/L1 from L2
Integration with Existing Features
1. Smart Extraction Enhancement
Extend the existing LLM-powered extraction to generate all three layers:
// Current: 6-category extraction
{ category: 'profile', content: '...' }
// Proposed: 6-category + 3-layer extraction
{
category: 'profile',
l0_index: 'User prefers dark mode',
l1_summary: 'User explicitly requested dark mode for all interfaces',
l2_narrative: 'During setup, user mentioned they work late nights and find dark mode easier on the eyes...'
}
2. Adaptive Retrieval
Modify src/adaptive-retrieval.ts to:
- Start with L0 for simple queries
- Escalate to L1 for moderate complexity
- Access L2 only for deep context needs
3. Lifecycle Management
Apply existing Weibull decay + tier promotion to all layers:
- L0 entries decay faster (lightweight, easy to regenerate)
- L1 entries have medium decay (valuable insights)
- L2 entries decay slower (full context preservation)
Benefits
- Token Efficiency: Reduce context window usage by 70-90% for typical queries
- Faster Retrieval: L0 index enables quick filtering before expensive vector search
- Better UX: Progressive disclosure matches human information-seeking behavior
- Backward Compatible: Can be implemented as an optional feature flag
- Synergy with Existing Features: Complements rather than replaces current architecture
References
Questions for Discussion
- Which implementation approach (A/B/C) would fit best with the current architecture?
- Should L0/L1/L2 be opt-in (feature flag) or always-on?
- How should the existing 6-category system interact with the 3-layer hierarchy?
- Should we add a CLI command like
openclaw memory-pro compact to generate L0/L1 from existing L2 memories?
I'm happy to contribute to the implementation if this aligns with the project's roadmap. Thank you for building such a powerful memory system!
Summary
I'd like to propose adding a three-tier hierarchical memory layer (L0/L1/L2) to
memory-lancedb-pro, inspired by the architecture in jzOcb/ai-agent-memory.While
memory-lancedb-proexcels at hybrid retrieval (Vector + BM25) and cross-encoder reranking for large-scale semantic search, the L0/L1/L2 hierarchy fromai-agent-memoryoffers a complementary approach that could significantly reduce token consumption and improve retrieval efficiency.Background: What is L0/L1/L2?
The hierarchical memory system from
ai-agent-memoryorganizes memories into three layers:.abstractfilesinsights/,lessons/YYYY-MM-DD.mdKey benefit: 90% of queries need only L0 + L1, dramatically reducing token usage while maintaining context quality.
This design is inspired by OpenViking (ByteDance) and aligns with the "reflection" mechanism from Stanford Generative Agents.
Why This Complements memory-lancedb-pro
memory-lancedb-proalready has excellent features:However, the current system treats all memories at the same granularity level. Adding L0/L1/L2 would:
Proposed Implementation
Option A: Metadata-Based Layers (Minimal Change)
Add a
layerfield to the existing memory schema:Retrieval flow:
Option B: Separate Tables (Clean Separation)
Create three LanceDB tables:
memories_l0— Index layer (one-sentence per memory)memories_l1— Summary layer (structured insights)memories_l2— Narrative layer (full content)Link them via
memory_idforeign key.Option C: Hybrid Approach
memoriestable for L2 (full content)memories_indextable for L0/L1 (lightweight summaries)Integration with Existing Features
1. Smart Extraction Enhancement
Extend the existing LLM-powered extraction to generate all three layers:
2. Adaptive Retrieval
Modify
src/adaptive-retrieval.tsto:3. Lifecycle Management
Apply existing Weibull decay + tier promotion to all layers:
Benefits
References
Questions for Discussion
openclaw memory-pro compactto generate L0/L1 from existing L2 memories?I'm happy to contribute to the implementation if this aligns with the project's roadmap. Thank you for building such a powerful memory system!