pi-hmem

extensionmaintained

HMEM hybrid memory for Pi Agent — FTS + vector + HRR holographic retrieval with knowledge graph, reflection, and shared-namespace tiering

by — · v0.3.0 · published 4w ago

$ pi install npm:pi-hmem
downloads/mo
273
stars
5
last push
2w ago
open issues
0

Signals

license: MITtestspi manifest: missinginstall size: —deps: 0peer deps: 0

Download trend

686 downloads · last 12 weeks (weekly)

README

pi-hmem — HMEM Hybrid Memory Extension for Pi Agent

Let your Pi Agent have long-term memory and learn from experience.

A Pi extension that connects to the HMEM Server to provide:

  • 🧠 Long-term memory — store and retrieve facts, experiences, and insights
  • 🔍 Hybrid search — keyword + semantic vector + knowledge graph + time decay
  • 🧠 Reflection engine — learns mental models from your interactions
  • 🕸️ Knowledge graph — relationships between memories

Install

From npm (recommended)

pi install npm:pi-hmem

From source

pi install /path/to/pi-hmem

Or load directly

pi -e npm:pi-hmem
pi -e /path/to/pi-hmem/extensions/index.ts

Quick Start

Prerequisites

  1. HMEM Server must be running. See hmem_hermes_agent for setup.

Configuration

Three configuration methods (priority high → low):

1. Environment variables (recommended)

export PIAGENT_HMEM_API_URL="http://localhost:8000"
export PIAGENT_HMEM_API_KEY="your-hmem-api-key"
export PIAGENT_HMEM_NAMESPACE="piagent"
export PIAGENT_HMEM_SHARED_NS="shared"   # optional: shared tier memory (user prefs / mental models)

2. Project config file

Create .pi-hmem.json in your project root:

{
  "apiUrl": "http://localhost:8000",
  "apiKey": "your-hmem-api-key",
  "namespace": "my-project",
  "sharedNs": "shared"
}

3. Runtime command

/hmem config set apiUrl http://localhost:8002
/hmem config set apiKey your-hmem-api-key
/hmem config set namespace piagent
/hmem config set sharedNs shared

Tiered Shared Memory (graded sharing)

Role-based memory isolation by default: each role keeps its own namespace (business memories + knowledge graph stay self-contained), while a shared tier (sharedNs) carries cross-role knowledge — user preferences, common mental models, environment layout.

  • Every hmem_search also queries the sharedNs namespace (0.8× weight) when set
  • Shared hits are tagged _ns / shared: true in results
  • Business memories always go to your own namespace; write shared-tier content explicitly with namespace: "shared"
┌──────────┐   ┌──────────┐   ┌──────────┐   ┌──────────┐
│ lingjia  │   │   dev    │   │   wu     │   │  create  │  ← role namespaces (isolated, graph closed-loop)
└────┬─────┘   └────┬─────┘   └────┬─────┘   └────┬─────┘
     └──────────────┴──────┬──────┴──────────────┘
                    ┌──────┴──────┐
                    │   shared    │  ← prefs / mental models (queried at 0.8x)
                    └─────────────┘

Memory Hierarchy

observation ──write──→ experience ──reflect──→ insight ──aggregate──→ mental_model
TypeDescriptionWrite
observationRaw facts, user preferences✅ hmem_write
experienceStructured experiences (action/context/outcome)✅ hmem_write
insightPatterns discovered by reflection❌ Auto-generated only
mental_modelAbstract behavioral models❌ Auto-generated only

⚠️ Only observation and experience can be written manually. insight and mental_model are generated exclusively by the hmem_reflect reflection engine.

Available Tools

ToolDescription
hmem_writeStore a memory (observation or experience)
hmem_searchHybrid semantic search (FTS + vector + local HRR + graph expand) with rerank; supports min_score threshold
hmem_listList recent memories, optionally by type
hmem_getGet a single memory by ID
hmem_deleteDelete a memory by ID
hmem_statsMemory statistics
hmem_reflectTrigger reflection engine
hmem_modelsList mental models and insights
hmem_graphKnowledge graph nodes + edges
hmem_namespacesList all namespaces
hmem_doc_importImport a plain-text document (auto-chunked + vectorized) into a knowledge base
hmem_doc_listList documents in a knowledge base
hmem_doc_getGet full document content (all chunks)
hmem_doc_deleteCascade-delete a document and all its chunks
hmem_kb_putAdd a single knowledge entry
hmem_kb_queryList knowledge entries (filter by category/doc_id/tags)
hmem_kb_categoriesKnowledge base category summary
hmem_kb_createCreate/activate a knowledge base
hmem_kb_listList all knowledge bases
hmem_kb_deleteDelete a knowledge base

Available Commands

CommandDescription
/hmemShow help
/hmem configShow current configuration
/hmem config set <key> <value>Set configuration
/hmem statsMemory statistics
/hmem search <query>Quick search (limit 5)
/hmem list [type]List memories
/hmem modelsList mental models
/hmem reflectTrigger reflection
/hmem namespacesList namespaces
/hmem kb listList knowledge bases
/hmem kb create <ns>Create a knowledge base
/hmem kb delete <ns>Delete a knowledge base
/hmem doc listList documents in default namespace
/hmem doc get <id>Get document detail
/hmem doc delete <id>Delete document

Namespace

Default namespace is piagent-default. Each namespace maps to an independent SQLite database.

  • Same namespace → shared memory across sessions/agents
  • Different namespace → complete isolation

Multi-Agent Support

Multiple Pi agents using the same namespace will share memories and mental models — enabling collaborative learning.

Architecture

Pi Agent ──HTTP──▶ HMEM Server (FastAPI)
                     │
              /api/v1/memories
              /api/v1/search
              /api/v1/stats
              /api/v1/reflect
              /api/v1/mental-models
              /api/v1/graph
              /api/v1/namespaces
              /api/v1/documents         ← knowledge base docs
              /api/v1/knowledge          ← knowledge entries
              /api/v1/knowledge-bases    ← library management
                     │
              ┌──────┴──────┐
              │ namespace-  │
              │   db.db     │
              └─────────────┘

Memory Lifecycle

hmem_write (observation / experience)
        │
        ▼
  hmem_reflect
  ┌─ Accumulate experiences ─┐
  │   LLM clustering         │
  └─→ insights ─→ mental models
        │
        ▼
  hmem_search / auto-prefetch
  ←─ Patterns guide behavior

Memory Prefetch

The extension auto-fetches relevant memories before each turn based on the user's message content, injecting up to 3 relevant memories into the context. When sharedNs is configured, shared-tier memories are merged into the results at 0.8× weight.

Version History

VersionDateNotes
0.3.02026-08-26Knowledge base support: document import/CRUD, knowledge entries, library management (10 new tools)
0.2.12026-08-25README: tiered-shared-memory docs, v0.2.0 notes
0.2.02026-08-25Tiered shared memory (sharedNs), min_score threshold, HRR local holographic retrieval integration
0.1.02026-08-05Initial release: 10 tools, 10 commands, reflection integration, auto-prefetch

License

MIT