Tools
Dali Memory Openclaw
Local vector memory system with MCP server and OpenClaw plugin
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