← Back to Plugins
Tools

Memolo

thdeptrai By thdeptrai 👁 55 views ▲ 0 votes

Memolo Long-term shared memory system for multi-agent AI. Self-hosted with PostgreSQL, Qdrant, Ollama/MiniMax. Includes OpenClaw plugin, real-time dashboard, and Node.js SDK.

GitHub

Configuration Example

const { MemoryClient } = require('memolo');
const memory = new MemoryClient({
  agentId: 'my-agent',
  apiKey: 'agent-api-key-from-register',
  serverUrl: 'http://192.168.1.100:7437',
});

const ctx = await memory.recall('user question', { format: 'context' });
const result = await memory.store({ userMessage: '...', agentResponse: '...' });

README

# ๐Ÿง  Memolo โ€” Intelligent Memory System for Multi-Agent AI

> Persistent, self-organizing memory for AI agents โ€” atomic fact extraction, knowledge graph, LLM deduplication, and semantic recall across your LAN

## Quick Start

### Prerequisites

- **[Docker Desktop](https://www.docker.com/products/docker-desktop/)** โ€” runs PostgreSQL, Qdrant, Server, Dashboard
- **[Ollama](https://ollama.com)** โ€” runs locally on host for embedding generation (needs GPU)
- **[MiniMax API Key](https://platform.minimax.io)** โ€” cloud LLM for fact extraction & deduplication

### Installation

```bash
# 1. Clone
git clone https://github.com/thdeptrai/memolo.git
cd memolo

# 2. Pull embedding model
ollama pull qwen3-embedding:8b

# 3. Configure
cp .env.example .env
# Edit .env โ†’ set these 2 required values:
#   MEMOLO_MASTER_KEY=<random string for API security>
#   MINIMAX_API_KEY=<your MiniMax API key>

# 4. Start everything
docker compose up -d

# โœ… Done!
# API:       http://localhost:7437
# Dashboard: http://localhost:3001
```

### Update to Latest Version

```bash
bash update.sh
# Or: git pull && docker compose up -d --build memolo
```

---

## How Memolo Works

Memolo is a **local-first AI memory system** that turns raw agent conversations into structured, searchable, and self-maintaining knowledge. Here's what happens when an agent sends a message:

### ๐Ÿ“ฅ Store Flow โ€” What happens when `POST /api/memory/store` is called

```
USER MESSAGE + AGENT RESPONSE
            โ”‚
            โ–ผ
    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
    โ”‚ 1. Save Raw Data  โ”‚  Exchange saved to PostgreSQL with sequence number
    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
            โ”‚
            โ–ผ
    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
    โ”‚ 2. Batch Queue    โ”‚  Exchange enqueued into in-memory buffer
    โ”‚ (if batch enabled)โ”‚  (reduces LLM API calls for cloud providers)
    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
            โ”‚
            โ”œโ”€โ”€โ”€โ”€ (flush every 10s or when batch full) โ”€โ”€โ”€โ”€โ”
            โ”‚                                               โ”‚
            โ–ผ                                               โ–ผ
    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”                           โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
    โ”‚ 3. Extract Facts  โ”‚                           โ”‚ 5. Update Graph  โ”‚
    โ”‚ + Dedup (combined)โ”‚  1 LLM call per batch:    โ”‚                  โ”‚
    โ”‚                   โ”‚   โ€ข Extract atomic facts   โ”‚ Entities โ†’ DB    โ”‚
    โ”‚                   โ”‚   โ€ข ADD/UPDATE/DELETE/NONE  โ”‚ Co-occurring โ†’   โ”‚
    โ”‚                   โ”‚   โ€ข User + Agent facts      โ”‚ relationships    โ”‚
    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                           โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
            โ”‚
            โ–ผ
    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
    โ”‚ 4. Embed & Store  โ”‚  Generate 4096-dim embedding via Ollama,
    โ”‚                   โ”‚  store in Qdrant for semantic search
    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
```

### ๐Ÿ“ค Recall Flow โ€” What happens when `POST /api/memory/recall` is called

```
QUERY: "What tools does the user prefer?"
            โ”‚
            โ–ผ
    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
    โ”‚ 1. Query Enrich   โ”‚  Enrich query using conversation profile
    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  (active topic, preferences, context)
            โ”‚
            โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
            โ–ผ                    โ–ผ                   โ–ผ
    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
    โ”‚ 2. Semantic   โ”‚   โ”‚ 3. Cross-    โ”‚    โ”‚ 4. Knowledge โ”‚
    โ”‚    Search     โ”‚   โ”‚    Agent     โ”‚    โ”‚    Graph     โ”‚
    โ”‚ (Qdrant,      โ”‚   โ”‚    Search   โ”‚    โ”‚    Query     โ”‚
    โ”‚  topic-aware)โ”‚   โ”‚ (shared KB) โ”‚    โ”‚ (neighbors)  โ”‚
    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
            โ”‚                  โ”‚                   โ”‚
            โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
            โ–ผ
    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
    โ”‚ 5. LLM Rerank     โ”‚  Score each result 0.0-1.0 by
    โ”‚ (configurable)    โ”‚  semantic relevance to query
    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
            โ”‚
            โ–ผ
        RANKED RESULTS
```

---

## Core Mechanisms

### ๐Ÿ” Atomic Fact Extraction
Unlike batch summarization that processes groups of messages, Memolo extracts atomic facts from **every individual exchange** in real-time. Each fact is a standalone, searchable unit of knowledge. Facts from both user messages and agent responses (configurable) are extracted.

**Example:**
```
User:  "Tao dang lam project ecommerce bang Next.js va Prisma ORM, database la PostgreSQL"
Agent: "Hay lam! Stack rat manh."

Extracted Facts:
 1. "User ฤ‘ang lร m project ecommerce"
 2. "Project sแปญ dแปฅng Next.js framework"
 3. "Database lร  PostgreSQL"
```

### ๐Ÿง  Combined Extract + Dedup (1 LLM call)
When a new exchange arrives, Memolo performs extraction AND deduplication in a **single LLM call** (optimized for cloud providers like MiniMax to minimize API costs):

1. **Extract** atomic facts from user + agent messages
2. **Compare** against existing memories (fetched via vector search)
3. **Decide** action for each fact: ADD / UPDATE / DELETE / NONE

This prevents memory bloat and handles contradictions automatically:

```
Existing:  "Database lร  PostgreSQL"
New fact:  "ฤรฃ chuyแปƒn sang MySQL thay vรฌ PostgreSQL"

LLM Decision: UPDATE
Result:    "ฤรฃ chuyแปƒn sang sแปญ dแปฅng MySQL thay vรฌ PostgreSQL" (old superseded)
```

**Key technique:** UUIDs are mapped to integers `[0], [1], [2]...` before sending to the LLM to prevent hallucination (inspired by mem0).

### ๐Ÿ“ฆ Batch Processing
Exchanges are queued and processed in batches (configurable interval + max size) to **dramatically reduce LLM API calls** for cloud providers. A batch of 10 exchanges โ†’ 1 LLM call instead of 10.

### ๐Ÿ•ธ๏ธ Knowledge Graph
Entities mentioned in conversations are automatically extracted and linked:

```
Entities:  [Next.js, TypeScript, PostgreSQL, Vercel]
Relations: Next.js --related_to--> TypeScript
           PostgreSQL --related_to--> Next.js
```

During recall, the graph provides **contextual connections** โ€” asking about "Next.js" also surfaces related technologies, preferences, and decisions.

### ๐Ÿ“Š Search Reranking
After initial vector similarity search, an LLM scores each result's relevance (0.0-1.0) to the actual query. This catches cases where vector similarity alone misses semantic nuance. Can be disabled via config.

### ๐Ÿ“œ Memory History (Audit Trail)
Every ADD, UPDATE, and DELETE operation is logged with:
- Before/after content
- Who changed it (agent ID or system)
- Why (dedup_merge, contradiction, manual, etc.)

---

## Architecture

```
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚   Agent 1    โ”‚   โ”‚   Agent 2    โ”‚   โ”‚   Agent N    โ”‚
โ”‚ (Device A)   โ”‚   โ”‚ (Device B)   โ”‚   โ”‚ (Device C)   โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
       โ”‚ X-API-Key        โ”‚ X-API-Key        โ”‚ X-API-Key
       โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                          โ”‚ LAN (WiFi)
                   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”
                   โ”‚   Memolo    โ”‚ โ† 0.0.0.0:7437
                   โ”‚   Server    โ”‚   API + Dashboard
                   โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
                   โ”‚ Batch Queue โ”‚ โ† queue + flush periodically
                   โ”‚ Fact Extractโ”‚ โ† per-exchange atomic facts
                   โ”‚ Deduplicatorโ”‚ โ† LLM ADD/UPDATE/DELETE
                   โ”‚ Graph Engineโ”‚ โ† entities + relationships
                   โ”‚ Reranker    โ”‚ โ† LLM relevance scoring
                   โ”‚ Contradict. โ”‚ โ† detect & supersede conflicts
                   โ”‚ Intelligenceโ”‚ โ† decay, dedup
                   โ”‚ LLM Service โ”‚ โ† MiniMax M2.5
                   โ”‚ Auth Layer  โ”‚ โ† master + per-agent keys
                   โ”‚ Config API  โ”‚ โ† live runtime settings
                   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”˜
              โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
         โ”Œโ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”
         โ”‚PostgreSQLโ”‚ โ”‚ Qdrant  โ”‚ โ”‚ Ollama  โ”‚
         โ”‚ 9 tables โ”‚ โ”‚ vectors โ”‚ โ”‚ (host)  โ”‚
         โ”‚ + graph  โ”‚ โ”‚ 4096dim โ”‚ โ”‚embed onlyโ”‚
         โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
```

## Technology Stack

| Component | Technology |
|-----------|-----------|
| Server | Node.js + Express 4.18 |
| Database | PostgreSQL 16 (9 tables, 11 migrations) |
| Vector Store | Qdrant (Cosine similarity, 4096 dim) |
| Embeddings | Ollama `qwen3-embedding:8b` (local) |
| LLM (Facts/Dedup/Rerank) | MiniMax M2.5 (cloud, Anthropic-compatible API) |
| Auth | API key (master + per-agent) via `X-API-Key` header |
| Dashboard | Next.js 16 + TailwindCSS v4 + shadcn/ui (dark theme) |
| Deployment | Docker Compose (single command) |

## Database Schema

| Table | Purpose |
|-------|---------|
| `agents` | Registered AI agents with API keys |
| `conversations` | Conversation sessions per agent |
| `exchanges` | Raw user/agent message pairs |
| `memories` | Extracted facts, decisions, insights (with content_hash, actor_id, superseded_by) |
| `knowledge_base` | Curated knowledge entries |
| `memory_history` | Audit trail for all memory mutations |
| `entities` | Named entities from the knowledge graph |
| `relationships` | Typed links between entities |
| `memory_conversations` | Many-to-many memory โ†” conversation linking |

---

## Authentication

### 2-Tier API Keys

| Key Type | Set In | Purpose |
|----------|--------|---------|
| **Master key** | `.env` (`MEMOLO_MASTER_KEY`) | Admin: register agents, full access |
| **Per-agent key** | Auto-generated on register | Agent: store, recall, search |

- `GET /api/health` โ€” **no auth required**
- If `MEMOLO_MASTER_KEY` not set โ†’ auth disabled (dev mode)

## Agent Integration

### SDK (Node.js)
```javascript
const { MemoryClient } = require('memolo');
const memory = new MemoryClient({
  agentId: 'my-agent',
  apiKey: 'agent-api-key-from-register',
  serverUrl: 'http://192.168.1.100:7437',
});

const ctx = await memory.recall('user question', { format: 'context' });
const result = await memory.store({ userMessage: '...', agentResponse: '...' });
```

### OpenClaw Plugin (Example Integration)
```json
{
  "memolo": {
    "agentId": "my-agent",
    "apiKey": "${MEMOLO_API_KEY}",
    "serverUrl": "http://192.168.1.100:7437"
  }
}
```

---

## API Reference

### Memory
| Method | Path | Descri

... (truncated)
tools

Comments

Sign in to leave a comment

Loading comments...