← Back to Plugins
Tools

Dali Memory Openclaw

linnaxis By linnaxis 👁 3 views ▲ 0 votes

Local vector memory system with MCP server and OpenClaw plugin

GitHub

Install

npm install
npm

Configuration Example

{
  "mcpServers": {
    "dali": {
      "type": "stdio",
      "command": "node",
      "args": ["/absolute/path/to/dali-memory-openclaw/dist/index.js"],
      "env": {
        "DALI_DB_PATH": "~/.claude/dali/dali.db",
        "OLLAMA_BASE_URL": "http://localhost:11434",
        "OLLAMA_MODEL": "nomic-embed-text"
      }
    }
  }
}

README

# ๐Ÿฆž Dali Memory

<p align="center">
  <img src="image.png" alt="Dali" width="400">
</p>

Local vector memory system for AI coding assistants. Gives Claude Code (or any MCP client) persistent semantic memory across sessions using SQLite + [sqlite-vec](https://github.com/asg017/sqlite-vec) + [Ollama](https://ollama.com) embeddings.

Includes an optional [OpenClaw](https://github.com/openclaw) plugin adapter for automatic context injection.

## Why

AI coding assistants forget everything between sessions. The typical workaround โ€” dumping large `.md` files into every prompt โ€” wastes tokens on irrelevant context.

Dali replaces static context dumps with **semantic retrieval**: only memories relevant to the current conversation are injected, saving ~1,000 tokens per turn.

## Architecture

```
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  Claude Code / MCP Client                           โ”‚
โ”‚                                                     โ”‚
โ”‚  store_memory โ”€โ”€โ”    search_memory โ”€โ”€โ”              โ”‚
โ”‚  search_by_type โ”ค    forget_memory   โ”ค              โ”‚
โ”‚  get_audit_log  โ”ค    list_recent     โ”ค              โ”‚
โ”‚  get_session    โ”˜                    โ”˜              โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
               โ”‚ stdio (MCP)          โ”‚
               v                      v
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  Dali MCP Server (src/)                              โ”‚
โ”‚                                                      โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚
โ”‚  โ”‚ memory/  โ”‚  โ”‚ embeddings/โ”‚  โ”‚ audit/           โ”‚ โ”‚
โ”‚  โ”‚ store.ts โ”‚  โ”‚ ollama.ts  โ”‚โ”€โ”€โ”‚ logger.ts        โ”‚ โ”‚
โ”‚  โ”‚ search.tsโ”‚  โ”‚            โ”‚  โ”‚ query.ts         โ”‚ โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚
โ”‚       โ”‚              โ”‚                               โ”‚
โ”‚       v              v                               โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”                         โ”‚
โ”‚  โ”‚  SQLite + sqlite-vec    โ”‚                         โ”‚
โ”‚  โ”‚  768-dim cosine KNN     โ”‚                         โ”‚
โ”‚  โ”‚  WAL mode               โ”‚                         โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                         โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
               โ”‚
               v
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  Ollama (local)          โ”‚
โ”‚  nomic-embed-text        โ”‚
โ”‚  768-dim embeddings      โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
```

## Quickstart

### 1. Install Ollama

```bash
brew install ollama        # macOS
ollama pull nomic-embed-text
ollama serve               # start the server
```

### 2. Clone and Build

```bash
git clone https://github.com/linnaxis/dali-memory-openclaw.git
cd dali-memory-openclaw
npm install
npm run build
```

### 3. Configure MCP

Copy `.mcp.json.example` to `~/.mcp.json` (or merge into your existing config):

```json
{
  "mcpServers": {
    "dali": {
      "type": "stdio",
      "command": "node",
      "args": ["/absolute/path/to/dali-memory-openclaw/dist/index.js"],
      "env": {
        "DALI_DB_PATH": "~/.claude/dali/dali.db",
        "OLLAMA_BASE_URL": "http://localhost:11434",
        "OLLAMA_MODEL": "nomic-embed-text"
      }
    }
  }
}
```

### 4. Verify

Start Claude Code. You should see 7 new tools:
- `store_memory` โ€” persist a memory with auto-embedding
- `search_memory` โ€” semantic vector search
- `search_by_type` โ€” filter by type + text query
- `get_audit_log` โ€” query tool invocation history
- `get_session_summary` โ€” all memories for a session
- `list_recent_memories` โ€” chronological listing
- `forget_memory` โ€” archive or delete

## Efficiency Benchmarks

Based on a real deployment with 165 memories (3.5 MB database):

### Token Savings Per Turn

| Metric | Static (Before) | Dynamic (After) | Savings |
|--------|-----------------|------------------|---------|
| Managed .md files | 1,287 tokens | ~20 token stubs | -1,267 |
| Dali context injection | 0 | ~100-400 avg | +100-400 |
| **Net per turn** | **1,287 tokens** | **~220-420 tokens** | **~870-1,070** |

### Cost Projections (Claude Sonnet 4, $3/M input tokens)

| Scenario | Tokens/turn | 100 turns/day | Monthly cost |
|----------|-------------|---------------|-------------|
| Static (all .md) | 3,373 | 337,300 | $30.36 |
| With Dali (avg) | 2,406 | 240,600 | $21.65 |
| **Savings** | **~967** | **96,700** | **$8.70** |

### Latency

| Operation | Latency | Notes |
|-----------|---------|-------|
| Ollama embed (nomic-embed-text) | 15-50ms | Local inference |
| SQLite KNN search (768-dim) | <5ms | In-memory after first query |
| Full retrieval pipeline | 20-60ms | Dominated by Ollama |
| Ollama down (fallback) | 0ms | Graceful no-op |

### Database Size

| Memories | Size |
|----------|------|
| 165 | 3.5 MB |
| ~1,000 | ~15 MB |
| ~10,000 | ~120 MB |

Run `npm run benchmark` for live measurements against your instance.

## OpenClaw Integration

The `openclaw/` directory contains an optional plugin adapter that integrates Dali into [OpenClaw](https://github.com/openclaw). It provides:

- **Automatic context injection** โ€” a `before_prompt_build` hook embeds the user's message, searches for relevant memories, and injects them into the system prompt
- **Agent tools** โ€” `dali_search` and `dali_store` let the agent query and persist memories
- **Workspace indexer** โ€” one-time script to seed Dali from existing `.md` workspace files

### Install the Plugin

```bash
# From npm
openclaw plugins install @openclaw/dali-memory

# From GitHub (no npm publish required)
openclaw plugins install github:linnaxis/dali-memory-openclaw

# From a local clone
openclaw plugins install ./openclaw
```

See [`openclaw/README.md`](openclaw/README.md) for configuration and detailed setup.

## Claude Code Integration Prompts

The `prompts/` directory contains ready-to-paste prompts for Claude Code:

| Prompt | Purpose |
|--------|---------|
| [`INSTALL_DALI.md`](prompts/INSTALL_DALI.md) | Install and configure the Dali MCP server |
| [`INSTALL_OPENCLAW_PLUGIN.md`](prompts/INSTALL_OPENCLAW_PLUGIN.md) | Wire the plugin into an OpenClaw instance |
| [`VERIFY_INTEGRATION.md`](prompts/VERIFY_INTEGRATION.md) | Test the full integration end-to-end |

## Configuration

### Environment Variables

| Variable | Default | Description |
|----------|---------|-------------|
| `DALI_DB_PATH` | `~/.claude/dali/dali.db` | SQLite database path |
| `DALI_PROJECT` | Current directory name | Default project name |
| `OLLAMA_BASE_URL` | `http://localhost:11434` | Ollama API endpoint |
| `OLLAMA_MODEL` | `nomic-embed-text` | Embedding model |

## Database Schema

Dali uses SQLite with the sqlite-vec extension for vector search.

### Tables

| Table | Purpose |
|-------|---------|
| `memories` | Core storage โ€” type, content, summary, tags, metadata, project |
| `memory_vec_map` | Bridge: maps UUID `memory_id` to integer `rowid` for vec0 |
| `memory_embeddings` | vec0 virtual table โ€” 768-dim cosine distance vectors |
| `audit_log` | Tool invocation history with timing |
| `sessions` | Session tracking with project association |
| `file_changes` | File modification records linked to memories |
| `schema_version` | Migration version tracking |

### Design Decisions

- **Bridge table pattern**: sqlite-vec requires integer rowids; memories use UUIDs. The `memory_vec_map` table bridges them.
- **WAL mode**: Enables concurrent reads during writes.
- **Graceful degradation**: Memories are stored immediately; embeddings are backfilled asynchronously when Ollama becomes available.
- **JSON storage**: Tags and metadata stored as JSON strings, parsed on read.

## Project Structure

```
dali-memory-openclaw/
โ”œโ”€โ”€ README.md
โ”œโ”€โ”€ package.json
โ”œโ”€โ”€ tsconfig.json
โ”œโ”€โ”€ .mcp.json.example
โ”œโ”€โ”€ LICENSE
โ”œโ”€โ”€ src/                          # Dali MCP server
โ”‚   โ”œโ”€โ”€ index.ts                  # Entry point (stdio transport)
โ”‚   โ”œโ”€โ”€ server.ts                 # Tool + resource definitions
โ”‚   โ”œโ”€โ”€ types.ts                  # Interfaces + Zod schemas
โ”‚   โ”œโ”€โ”€ db/
โ”‚   โ”‚   โ”œโ”€โ”€ client.ts             # Database init, WAL, migrations
โ”‚   โ”‚   โ””โ”€โ”€ schema.ts             # DDL + version tracking
โ”‚   โ”œโ”€โ”€ memory/
โ”‚   โ”‚   โ”œโ”€โ”€ search.ts             # KNN vector search + text filtering
โ”‚   โ”‚   โ””โ”€โ”€ store.ts              # Insert, embed, archive, delete
โ”‚   โ”œโ”€โ”€ embeddings/
โ”‚   โ”‚   โ””โ”€โ”€ ollama.ts             # Ollama /api/embed client
โ”‚   โ””โ”€โ”€ audit/
โ”‚       โ”œโ”€โ”€ logger.ts             # Audit log insertion
โ”‚       โ””โ”€โ”€ query.ts              # Audit log query + filtering
โ”œโ”€โ”€ openclaw/                     # OpenClaw plugin (optional)
โ”‚   โ”œโ”€โ”€ README.md
โ”‚   โ”œโ”€โ”€ package.json
โ”‚   โ”œโ”€โ”€ openclaw.plugin.json
โ”‚   โ”œโ”€โ”€ api.ts
โ”‚   โ”œโ”€โ”€ index.ts
โ”‚   โ”œโ”€โ”€ src/
โ”‚   โ”‚   โ”œโ”€โ”€ db.ts
โ”‚   โ”‚   โ”œโ”€โ”€ embedder.ts
โ”‚   โ”‚   โ”œโ”€โ”€ search-tool.ts
โ”‚   โ”‚   โ”œโ”€โ”€ store-tool.ts
โ”‚   โ”‚   โ””โ”€โ”€ context-hook.ts
โ”‚   โ””โ”€โ”€ scripts/
โ”‚       โ””โ”€โ”€ index-workspace.ts
โ”œโ”€โ”€ scripts/
โ”‚   โ””โ”€โ”€ benchmark.ts              # Token savings + latency benchmark
โ””โ”€โ”€ prompts/
    โ”œโ”€โ”€ INSTALL_DALI.md
    โ”œโ”€โ”€ INSTALL_OPENCLAW_PLUGIN.md
    โ””โ”€โ”€ VERIFY_INTEGRATION.md
```

## License

MIT
tools

Comments

Sign in to leave a comment

Loading comments...