← Back to Plugins
Tools

Memory Spark

kleinpanic By kleinpanic 👁 140 views ▲ 0 votes

OpenClaw memory plugin: LanceDB + NVIDIA Spark GPU embeddings for autonomous AI agents

GitHub

Install

npm install @lancedb/lancedb`

Configuration Example

{
  "plugins": {
    "slots": { "memory": "memory-spark" },
    "allow": ["memory-spark"],
    "entries": { "memory-spark": { "enabled": true } },
    "load": { "paths": ["~/.openclaw/extensions/memory-spark"] }
  }
}

README

# memory-spark

An OpenClaw memory plugin with LanceDB vector storage and NVIDIA Spark GPU-accelerated embeddings. Drop-in replacement for `memory-core` with autonomous recall, capture, file ingestion, and hybrid search.

## Features

- **Auto-recall** โ€” injects relevant memories before every agent turn (`before_prompt_build` hook)
- **Auto-capture** โ€” extracts and stores facts/preferences from conversations (`agent_end` hook)
- **File watcher** โ€” auto-indexes your workspace memory dirs, sessions, and watched paths on boot and on change
- **PDF / DOCX / audio ingest** โ€” parse and embed documents via `pdftotext`, `mammoth`, and STT
- **Hybrid search + rerank** โ€” vector search + BM25 full-text, reranked by Cohere-compatible cross-encoder
- **NVIDIA Spark GPU embeddings** โ€” `nvidia/llama-embed-nemotron-8b` (4096d), 0.25s/call on Blackwell GPU
- **Serialized embed queue** โ€” retry with exponential backoff, health monitoring, auto-cooldown
- **Dimension lock** โ€” refuses to start if provider/dims mismatch, preventing silent vector corruption
- **Zero-touch** โ€” configure once, everything else is automatic

## Architecture

```
memory-spark/
โ”œโ”€โ”€ index.ts                 # Plugin entry: register(), tool handlers, hooks
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ config.ts            # Config schema + defaults + .env loader
โ”‚   โ”œโ”€โ”€ manager.ts           # MemorySearchManager: search, store, forget
โ”‚   โ”œโ”€โ”€ auto/
โ”‚   โ”‚   โ”œโ”€โ”€ recall.ts        # before_prompt_build hook โ€” injects memories
โ”‚   โ”‚   โ””โ”€โ”€ capture.ts       # agent_end hook โ€” classifies + stores new facts
โ”‚   โ”œโ”€โ”€ embed/
โ”‚   โ”‚   โ”œโ”€โ”€ provider.ts      # EmbedProvider: Spark โ†’ OpenAI โ†’ Gemini fallback
โ”‚   โ”‚   โ”œโ”€โ”€ queue.ts         # EmbedQueue: serial requests, retry, health tracking
โ”‚   โ”‚   โ”œโ”€โ”€ chunker.ts       # Markdown-aware token-bounded chunking with overlap
โ”‚   โ”‚   โ””โ”€โ”€ dims-lock.ts     # Dimension lock: validates provider/model/dims on startup
โ”‚   โ”œโ”€โ”€ ingest/
โ”‚   โ”‚   โ”œโ”€โ”€ pipeline.ts      # extract โ†’ chunk โ†’ NER โ†’ embed โ†’ upsert
โ”‚   โ”‚   โ”œโ”€โ”€ watcher.ts       # Chokidar watcher + boot pass across all agent workspaces
โ”‚   โ”‚   โ”œโ”€โ”€ workspace.ts     # Agent workspace discovery, session scanning
โ”‚   โ”‚   โ””โ”€โ”€ parsers.ts       # PDF (pdftotext+OCR), DOCX (mammoth), audio (STT), text
โ”‚   โ”œโ”€โ”€ classify/
โ”‚   โ”‚   โ”œโ”€โ”€ ner.ts           # NER via Spark 18112 (dslim/bert-base-NER)
โ”‚   โ”‚   โ””โ”€โ”€ zero-shot.ts     # Zero-shot classifier via Spark 18113 (bart-large-mnli)
โ”‚   โ”œโ”€โ”€ rerank/
โ”‚   โ”‚   โ””โ”€โ”€ reranker.ts      # Cohere-compatible reranker via Spark 18096
โ”‚   โ””โ”€โ”€ storage/
โ”‚       โ”œโ”€โ”€ backend.ts       # StorageBackend interface
โ”‚       โ””โ”€โ”€ lancedb.ts       # LanceDB: connect, upsert (mergeInsert), vectorSearch, FTS, delete
```

## Requirements

- [OpenClaw](https://openclaw.ai) โ€” the plugin host
- [LanceDB](https://lancedb.github.io/lancedb/) โ€” `npm install @lancedb/lancedb`
- `pdftotext` (poppler-utils) โ€” for PDF parsing
- NVIDIA Spark microservices (optional but recommended):
  - **Embed** โ€” port 18091 (`nvidia/llama-embed-nemotron-8b`, 4096d)
  - **Reranker** โ€” port 18096 (`nvidia/llama-nemotron-rerank-1b-v2`)
  - **NER** โ€” port 18112 (`dslim/bert-base-NER`)
  - **Zero-shot** โ€” port 18113 (`facebook/bart-large-mnli`)
  - **OCR** โ€” port 18097
  - **STT** โ€” port 18094

Falls back to OpenAI or Gemini embeddings if Spark is unavailable.

## Setup

### 1. Install

```bash
cd ~/.openclaw/extensions
git clone https://github.com/kleinpanic/memory-spark
cd memory-spark && npm install && npm run build
```

### 2. Configure OpenClaw

In `~/.openclaw/openclaw.json`:

```json
{
  "plugins": {
    "slots": { "memory": "memory-spark" },
    "allow": ["memory-spark"],
    "entries": { "memory-spark": { "enabled": true } },
    "load": { "paths": ["~/.openclaw/extensions/memory-spark"] }
  }
}
```

### 3. Environment

Set your Spark bearer token in `~/.openclaw/.env`:

```
SPARK_BEARER_TOKEN=your_token_here
```

### 4. Config (openclaw.json)

```json
{
  "memory": {
    "backend": "lancedb",
    "lancedb": { "uri": "~/.openclaw/data/memory-spark/lancedb" },
    "embed": {
      "provider": "spark",
      "model": "nvidia/llama-embed-nemotron-8b",
      "baseUrl": "http://localhost:18091/v1"
    },
    "recall": {
      "enabled": true,
      "topK": 5,
      "minScore": 0.3,
      "maxTokens": 1500
    },
    "capture": {
      "enabled": true,
      "categories": ["fact", "preference", "decision"]
    },
    "watch": {
      "enabled": true,
      "indexOnBoot": true,
      "debounceMs": 2000,
      "paths": []
    }
  }
}
```

## Tools

Exposes four tools to agents:

| Tool | Description |
|------|-------------|
| `memory_search` | Hybrid vector + FTS search with reranking |
| `memory_get` | Retrieve a specific chunk by ID |
| `memory_store` | Store a fact/note manually |
| `memory_forget` | Delete memories by path or query |

## License

MIT

## Acknowledgments

Built on [LanceDB](https://lancedb.github.io/lancedb/), [NVIDIA Nemotron](https://developer.nvidia.com/nemotron), and [OpenClaw](https://openclaw.ai).
tools

Comments

Sign in to leave a comment

Loading comments...