๐Ÿง  memory-lancedb-pro ยท OpenClaw Plugin

Enhanced Long-Term Memory Plugin for OpenClaw

Hybrid Retrieval (Vector + BM25) ยท Cross-Encoder Rerank ยท Multi-Scope Isolation ยท Management CLI

OpenClaw Plugin LanceDB License: MIT

English | ็ฎ€ไฝ“ไธญๆ–‡


๐Ÿ“บ Video Tutorial

Watch the full walkthrough โ€” covers installation, configuration, and how hybrid retrieval works under the hood.

YouTube Video ๐Ÿ”— https://youtu.be/MtukF1C8epQ

Bilibili Video ๐Ÿ”— https://www.bilibili.com/video/BV1zUf2BGEgn/


Why This Plugin?

The built-in memory-lancedb plugin in OpenClaw provides basic vector search. memory-lancedb-pro takes it much further:

Feature Built-in memory-lancedb memory-lancedb-pro
Vector search โœ… โœ…
BM25 full-text search โŒ โœ…
Hybrid fusion (Vector + BM25) โŒ โœ…
Cross-encoder rerank (Jina / custom endpoint) โŒ โœ…
Recency boost โŒ โœ…
Time decay โŒ โœ…
Length normalization โŒ โœ…
MMR diversity โŒ โœ…
Multi-scope isolation โŒ โœ…
Noise filtering โŒ โœ…
Adaptive retrieval โŒ โœ…
Management CLI โŒ โœ…
Session memory โŒ โœ…
Task-aware embeddings โŒ โœ…
Any OpenAI-compatible embedding Limited โœ… (OpenAI, Gemini, Jina, Ollama, etc.)

Architecture

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                   index.ts (Entry Point)                โ”‚
โ”‚  Plugin Registration ยท Config Parsing ยท Lifecycle Hooks โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
         โ”‚          โ”‚          โ”‚          โ”‚
    โ”Œโ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
    โ”‚ store  โ”‚ โ”‚embedderโ”‚ โ”‚retrieverโ”‚ โ”‚   scopes    โ”‚
    โ”‚ .ts    โ”‚ โ”‚ .ts    โ”‚ โ”‚ .ts    โ”‚ โ”‚    .ts      โ”‚
    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
         โ”‚                     โ”‚
    โ”Œโ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”           โ”Œโ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
    โ”‚migrate โ”‚           โ”‚noise-filter.ts โ”‚
    โ”‚ .ts    โ”‚           โ”‚adaptive-       โ”‚
    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜           โ”‚retrieval.ts    โ”‚
                         โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
    โ”‚  tools.ts   โ”‚   โ”‚  cli.ts  โ”‚
    โ”‚ (Agent API) โ”‚   โ”‚ (CLI)    โ”‚
    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

File Reference

File Purpose
index.ts Plugin entry point. Registers with OpenClaw Plugin API, parses config, mounts before_agent_start (auto-recall), agent_end (auto-capture), and command:new (session memory) hooks
openclaw.plugin.json Plugin metadata + full JSON Schema config declaration (with uiHints)
package.json NPM package info. Depends on @lancedb/lancedb, openai, @sinclair/typebox
cli.ts CLI commands: memory list/search/stats/delete/delete-bulk/export/import/reembed/migrate
src/store.ts LanceDB storage layer. Table creation / FTS indexing / Vector search / BM25 search / CRUD / bulk delete / stats
src/embedder.ts Embedding abstraction. Compatible with any OpenAI-API provider (OpenAI, Gemini, Jina, Ollama, etc.). Supports task-aware embedding (taskQuery/taskPassage)
src/retriever.ts Hybrid retrieval engine. Vector + BM25 โ†’ RRF fusion โ†’ Jina Cross-Encoder Rerank โ†’ Recency Boost โ†’ Importance Weight โ†’ Length Norm โ†’ Time Decay โ†’ Hard Min Score โ†’ Noise Filter โ†’ MMR Diversity
src/scopes.ts Multi-scope access control. Supports global, agent:<id>, custom:<name>, project:<id>, user:<id>
src/tools.ts Agent tool definitions: memory_recall, memory_store, memory_forget (core) + memory_stats, memory_list (management)
src/noise-filter.ts Noise filter. Filters out agent refusals, meta-questions, greetings, and low-quality content
src/adaptive-retrieval.ts Adaptive retrieval. Determines whether a query needs memory retrieval (skips greetings, slash commands, simple confirmations, emoji)
src/migrate.ts Migration tool. Migrates data from the built-in memory-lancedb plugin to Pro

Core Features

1. Hybrid Retrieval

Query โ†’ embedQuery() โ”€โ”
                       โ”œโ”€โ†’ RRF Fusion โ†’ Rerank โ†’ Recency Boost โ†’ Importance Weight โ†’ Filter
Query โ†’ BM25 FTS โ”€โ”€โ”€โ”€โ”€โ”˜

2. Cross-Encoder Reranking

3. Multi-Stage Scoring Pipeline

Stage Formula Effect
Recency Boost exp(-ageDays / halfLife) * weight Newer memories score higher (default: 14-day half-life, 0.10 weight)
Importance Weight score *= (0.7 + 0.3 * importance) importance=1.0 โ†’ ร—1.0, importance=0.5 โ†’ ร—0.85
Length Normalization score *= 1 / (1 + 0.5 * log2(len/anchor)) Prevents long entries from dominating (anchor: 500 chars)
Time Decay score *= 0.5 + 0.5 * exp(-ageDays / halfLife) Old entries gradually lose weight, floor at 0.5ร— (60-day half-life)
Hard Min Score Discard if score < threshold Removes irrelevant results (default: 0.35)
MMR Diversity Cosine similarity > 0.85 โ†’ demoted Prevents near-duplicate results

4. Multi-Scope Isolation

5. Adaptive Retrieval

6. Noise Filtering

Filters out low-quality content at both auto-capture and tool-store stages:

7. Session Memory

8. Auto-Capture & Auto-Recall


Installation

What is the โ€œOpenClaw workspaceโ€?

In OpenClaw, the agent workspace is the agentโ€™s working directory (default: ~/.openclaw/workspace). According to the docs, the workspace is the default cwd, and relative paths are resolved against the workspace (unless you use an absolute path).

Note: OpenClaw configuration typically lives under ~/.openclaw/openclaw.json (separate from the workspace).

Common mistake: cloning the plugin somewhere else, while keeping plugins.load.paths: ["plugins/memory-lancedb-pro"] (a relative path). In that case OpenClaw will look for plugins/memory-lancedb-pro under your workspace and fail to load it.

Option A (recommended): clone into plugins/ under your workspace

# 1) Go to your OpenClaw workspace (default: ~/.openclaw/workspace)
#    (You can override it via agents.defaults.workspace.)
cd /path/to/your/openclaw/workspace

# 2) Clone the plugin into workspace/plugins/
git clone https://github.com/win4r/memory-lancedb-pro.git plugins/memory-lancedb-pro

# 3) Install dependencies
cd plugins/memory-lancedb-pro
npm install

Then reference it with a relative path in your OpenClaw config:

{
  "plugins": {
    "load": {
      "paths": ["plugins/memory-lancedb-pro"]
    },
    "entries": {
      "memory-lancedb-pro": {
        "enabled": true,
        "config": {
          "embedding": {
            "apiKey": "${JINA_API_KEY}",
            "model": "jina-embeddings-v5-text-small",
            "baseURL": "https://api.jina.ai/v1",
            "dimensions": 1024,
            "taskQuery": "retrieval.query",
            "taskPassage": "retrieval.passage",
            "normalized": true
          }
        }
      }
    },
    "slots": {
      "memory": "memory-lancedb-pro"
    }
  }
}

Option B: clone anywhere, but use an absolute path

{
  "plugins": {
    "load": {
      "paths": ["/absolute/path/to/memory-lancedb-pro"]
    }
  }
}

Restart

openclaw gateway restart

Note: If you previously used the built-in memory-lancedb, disable it when enabling this plugin. Only one memory plugin can be active at a time.

Verify installation (recommended)

  1. Confirm the plugin is discoverable/loaded:
openclaw plugins list
openclaw plugins info memory-lancedb-pro
  1. If anything looks wrong, run the built-in diagnostics:
openclaw plugins doctor
  1. Confirm the memory slot points to this plugin:
# Look for: plugins.slots.memory = "memory-lancedb-pro"
openclaw config get plugins.slots.memory

Configuration

Full Configuration Example (click to expand)
{
  "embedding": {
    "apiKey": "${JINA_API_KEY}",
    "model": "jina-embeddings-v5-text-small",
    "baseURL": "https://api.jina.ai/v1",
    "dimensions": 1024,
    "taskQuery": "retrieval.query",
    "taskPassage": "retrieval.passage",
    "normalized": true
  },
  "dbPath": "~/.openclaw/memory/lancedb-pro",
  "autoCapture": true,
  "autoRecall": true,
  "retrieval": {
    "mode": "hybrid",
    "vectorWeight": 0.7,
    "bm25Weight": 0.3,
    "minScore": 0.3,
    "rerank": "cross-encoder",
    "rerankApiKey": "jina_xxx",
    "rerankModel": "jina-reranker-v2-base-multilingual",
    "rerankEndpoint": "https://api.jina.ai/v1/rerank",
    "rerankProvider": "jina",
    "candidatePoolSize": 20,
    "recencyHalfLifeDays": 14,
    "recencyWeight": 0.1,
    "filterNoise": true,
    "lengthNormAnchor": 500,
    "hardMinScore": 0.35,
    "timeDecayHalfLifeDays": 60
  },
  "enableManagementTools": false,
  "scopes": {
    "default": "global",
    "definitions": {
      "global": { "description": "Shared knowledge" },
      "agent:discord-bot": { "description": "Discord bot private" }
    },
    "agentAccess": {
      "discord-bot": ["global", "agent:discord-bot"]
    }
  },
  "sessionMemory": {
    "enabled": false,
    "messageCount": 15
  }
}

Embedding Providers

This plugin works with any OpenAI-compatible embedding API:

Provider Model Base URL Dimensions
Jina (recommended) jina-embeddings-v5-text-small https://api.jina.ai/v1 1024
OpenAI text-embedding-3-small https://api.openai.com/v1 1536
Google Gemini gemini-embedding-001 https://generativelanguage.googleapis.com/v1beta/openai/ 3072
Ollama (local) nomic-embed-text http://localhost:11434/v1 768

Rerank Providers

Cross-encoder reranking supports multiple providers via rerankProvider:

Provider rerankProvider Endpoint Example Model
Jina (default) jina https://api.jina.ai/v1/rerank jina-reranker-v2-base-multilingual
SiliconFlow (free tier available) siliconflow https://api.siliconflow.com/v1/rerank BAAI/bge-reranker-v2-m3, Qwen/Qwen3-Reranker-8B
Pinecone pinecone https://api.pinecone.io/rerank bge-reranker-v2-m3
SiliconFlow Example
{
  "retrieval": {
    "rerank": "cross-encoder",
    "rerankProvider": "siliconflow",
    "rerankEndpoint": "https://api.siliconflow.com/v1/rerank",
    "rerankApiKey": "sk-xxx",
    "rerankModel": "BAAI/bge-reranker-v2-m3"
  }
}
Pinecone Example
{
  "retrieval": {
    "rerank": "cross-encoder",
    "rerankProvider": "pinecone",
    "rerankEndpoint": "https://api.pinecone.io/rerank",
    "rerankApiKey": "pcsk_xxx",
    "rerankModel": "bge-reranker-v2-m3"
  }
}

CLI Commands

# List memories
openclaw memory-pro list [--scope global] [--category fact] [--limit 20] [--json]

# Search memories
openclaw memory-pro search "query" [--scope global] [--limit 10] [--json]

# View statistics
openclaw memory-pro stats [--scope global] [--json]

# Delete a memory by ID (supports 8+ char prefix)
openclaw memory-pro delete <id>

# Bulk delete with filters
openclaw memory-pro delete-bulk --scope global [--before 2025-01-01] [--dry-run]

# Export / Import
openclaw memory-pro export [--scope global] [--output memories.json]
openclaw memory-pro import memories.json [--scope global] [--dry-run]

# Re-embed all entries with a new model
openclaw memory-pro reembed --source-db /path/to/old-db [--batch-size 32] [--skip-existing]

# Migrate from built-in memory-lancedb
openclaw memory-pro migrate check [--source /path]
openclaw memory-pro migrate run [--source /path] [--dry-run] [--skip-existing]
openclaw memory-pro migrate verify [--source /path]

Custom Commands (e.g. /lesson)

This plugin provides the core memory tools (memory_store, memory_recall, memory_forget, memory_update). You can define custom slash commands in your Agent's system prompt to create convenient shortcuts.

Example: /lesson command

Add this to your CLAUDE.md, AGENTS.md, or system prompt:

## /lesson command
When the user sends `/lesson <content>`:
1. Use memory_store to save as category=fact (the raw knowledge)
2. Use memory_store to save as category=decision (actionable takeaway)
3. Confirm what was saved

Example: /remember command

## /remember command
When the user sends `/remember <content>`:
1. Use memory_store to save with appropriate category and importance
2. Confirm with the stored memory ID

Built-in Tools Reference

Tool Description
memory_store Store a memory (supports category, importance, scope)
memory_recall Search memories (hybrid vector + BM25 retrieval)
memory_forget Delete a memory by ID or search query
memory_update Update an existing memory in-place

Note: These tools are registered automatically when the plugin loads. Custom commands like /lesson are not built into the plugin โ€” they are defined at the Agent/system-prompt level and simply call these tools.


Database Schema

LanceDB table memories:

Field Type Description
id string (UUID) Primary key
text string Memory text (FTS indexed)
vector float[] Embedding vector
category string preference / fact / decision / entity / other
scope string Scope identifier (e.g., global, agent:main)
importance float Importance score 0โ€“1
timestamp int64 Creation timestamp (ms)
metadata string (JSON) Extended metadata

Dependencies

Package Purpose
@lancedb/lancedb โ‰ฅ0.26.2 Vector database (ANN + FTS)
openai โ‰ฅ6.21.0 OpenAI-compatible Embedding API client
@sinclair/typebox 0.34.48 JSON Schema type definitions (tool parameters)

License

MIT


Buy Me a Coffee

"Buy Me A Coffee"

My WeChat Group and My WeChat QR Code