MCP Hub
Back to servers

@cablate/memory-lancedb-mcp

MCP server for LanceDB-backed long-term memory with hybrid retrieval (Vector + BM25), cross-encoder rerank, multi-scope isolation, and memory lifecycle management

npm1.5k/wk
Updated
Mar 21, 2026

Quick Install

npx -y @cablate/memory-lancedb-mcp
memory-lancedb-mcp

Built on CortexReach/memory-lancedb-pro — original work by win4r and contributors. Refactored from OpenClaw plugin into a standalone MCP server.

npm version LanceDB License: MIT

English | 繁體中文


Why memory-lancedb-mcp?

Most AI agents forget everything the moment you start a new session. This MCP server gives any MCP-compatible client persistent, intelligent long-term memory — without manual management.

What you get
Hybrid RetrievalVector + BM25 full-text search, fused with cross-encoder reranking
Smart ExtractionLLM-powered 6-category memory extraction
Memory LifecycleWeibull decay + 3-tier promotion — important memories surface, stale ones fade
Multi-Scope IsolationPer-agent, per-user, per-project memory boundaries
Any Embedding ProviderOpenAI, Jina, Gemini, DeepInfra, Ollama, or any OpenAI-compatible API
Self-Improvement ToolsStructured learning/error logging with skill extraction

Quick Start

1. Install

npm install -g @cablate/memory-lancedb-mcp

2. Configure your MCP client

Add to your MCP client settings (e.g. Claude Desktop claude_desktop_config.json):

{
  "mcpServers": {
    "memory": {
      "command": "npx",
      "args": ["-y", "@cablate/memory-lancedb-mcp"],
      "env": {
        "EMBEDDING_API_KEY": "your-api-key",
        "EMBEDDING_MODEL": "text-embedding-3-small"
      }
    }
  }
}

3. Advanced configuration (optional)

For full control, create a config file and point to it:

{
  "mcpServers": {
    "memory": {
      "command": "npx",
      "args": ["-y", "@cablate/memory-lancedb-mcp"],
      "env": {
        "MEMORY_LANCEDB_CONFIG": "/path/to/config.json"
      }
    }
  }
}

See config.example.json for a full example.


MCP Tools

This server exposes the following tools to MCP clients:

Core Tools

ToolDescription
memory_recallSearch memories using hybrid retrieval (vector + keyword). Supports scope/category/time filters (since).
memory_storeSave information to long-term memory with importance scoring and noise filtering. Shows similar existing memories.
memory_forgetDelete memories by ID or search query.
memory_updateUpdate existing memories. Temporal categories auto-supersede to preserve history.
memory_mergeMerge two related memories into one. Invalidates both originals and creates a unified entry.
memory_historyTrace version history of a memory through its supersede/merge chain.

Management Tools (opt-in)

ToolDescription
memory_statsGet memory usage statistics by scope and category.
memory_listList recent memories with optional filtering.

Enable with "enableManagementTools": true in config.

Self-Improvement Tools (opt-in, disabled by default)

ToolDescription
self_improvement_logLog structured learning/error entries for governance.
self_improvement_extract_skillCreate skill scaffolds from learning entries.
self_improvement_reviewSummarize governance backlog.

Enable with "enableSelfImprovementTools": true in config or MEMORY_ENABLE_SELF_IMPROVEMENT=true env var.


Architecture

┌─────────────────────────────────────────────────────────┐
│                  server.ts (MCP Server)                  │
│    Tool Registration · Config Loading · Request Routing  │
└────────┬──────────┬──────────┬──────────┬───────────────┘
         │          │          │          │
    ┌────▼───┐ ┌────▼───┐ ┌───▼────┐ ┌──▼──────────┐
    │ store  │ │embedder│ │retriever│ │   scopes    │
    │ .ts    │ │ .ts    │ │ .ts    │ │    .ts      │
    └────────┘ └────────┘ └────────┘ └─────────────┘
         │                     │
    ┌────▼────────┐      ┌────▼──────────┐
    │smart-       │      │noise-filter.ts│
    │metadata.ts  │      │decay-engine.ts│
    └─────────────┘      └───────────────┘

Multi-Stage Scoring Pipeline

Query → embedQuery() ─┐
                       ├─→ RRF Fusion → Rerank → Lifecycle Decay → Length Norm → Filter
Query → BM25 FTS ─────┘
StageEffect
RRF FusionCombines semantic and exact-match recall
Cross-Encoder RerankPromotes semantically precise hits
Lifecycle DecayWeibull freshness + access frequency + importance × confidence
Length NormalizationPrevents long entries from dominating (anchor: 500 chars)
Hard Min ScoreRemoves irrelevant results (default: 0.35)
MMR DiversityCosine similarity > 0.85 → demoted

Configuration

Environment Variables

VariableRequiredDescription
EMBEDDING_API_KEYYesAPI key for embedding provider
EMBEDDING_MODELNoModel name (default: text-embedding-3-small)
EMBEDDING_BASE_URLNoCustom base URL for non-OpenAI providers
MEMORY_DB_PATHNoLanceDB storage directory
MEMORY_LANCEDB_CONFIGNoPath to JSON config file

Config File

Full configuration example
{
  "embedding": {
    "apiKey": "${EMBEDDING_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": "./memory-data",
  "retrieval": {
    "mode": "hybrid",
    "vectorWeight": 0.7,
    "bm25Weight": 0.3,
    "minScore": 0.3,
    "rerank": "cross-encoder",
    "rerankApiKey": "${JINA_API_KEY}",
    "rerankModel": "jina-reranker-v3",
    "rerankEndpoint": "https://api.jina.ai/v1/rerank",
    "rerankProvider": "jina",
    "candidatePoolSize": 20,
    "hardMinScore": 0.35,
    "filterNoise": true
  },
  "enableManagementTools": true,
  "enableSelfImprovementTools": false,
  "scopes": {
    "default": "global",
    "definitions": {
      "global": { "description": "Shared knowledge" },
      "agent:my-bot": { "description": "Private to my-bot" }
    },
    "agentAccess": {
      "my-bot": ["global", "agent:my-bot"]
    }
  },
  "decay": {
    "recencyHalfLifeDays": 30,
    "frequencyWeight": 0.3,
    "intrinsicWeight": 0.3
  }
}
Embedding providers

Works with any OpenAI-compatible embedding API:

ProviderModelBase URLDimensions
OpenAItext-embedding-3-smallhttps://api.openai.com/v11536
Jinajina-embeddings-v5-text-smallhttps://api.jina.ai/v11024
DeepInfraQwen/Qwen3-Embedding-8Bhttps://api.deepinfra.com/v1/openai1024
Google Geminigemini-embedding-001https://generativelanguage.googleapis.com/v1beta/openai/3072
Ollama (local)nomic-embed-texthttp://localhost:11434/v1varies
Rerank providers
ProviderrerankProviderEndpointExample Model
Jinajinahttps://api.jina.ai/v1/rerankjina-reranker-v3
Hugging Face TEIteihttp://host:8081/rerankBAAI/bge-reranker-v2-m3
SiliconFlowsiliconflowhttps://api.siliconflow.com/v1/rerankBAAI/bge-reranker-v2-m3
Voyage AIvoyagehttps://api.voyageai.com/v1/rerankrerank-2.5
Pineconepineconehttps://api.pinecone.io/rerankbge-reranker-v2-m3
DashScopedashscopehttps://dashscope.aliyuncs.com/api/v1/services/rerankgte-rerank

Core Features

Hybrid Retrieval

  • Vector Search — semantic similarity via LanceDB ANN (cosine distance)
  • BM25 Full-Text Search — exact keyword matching via LanceDB FTS index
  • Fusion — vector score as base, BM25 hits get a 15% boost

Cross-Encoder Reranking

  • Supports Jina, TEI, SiliconFlow, Voyage AI, Pinecone, DashScope
  • Hybrid scoring: 60% cross-encoder + 40% original fused score
  • Graceful degradation on API failure

Multi-Scope Isolation

  • Built-in scopes: global, agent:<id>, custom:<name>, project:<id>, user:<id>
  • Agent-level access control via scopes.agentAccess

Noise Filtering

  • Filters agent refusals, meta-questions, greetings, low-quality content
  • CJK-aware thresholds (Chinese: 6 chars vs English: 15 chars)

Memory Lifecycle (Decay + Tiers)

  • Weibull Decay: composite score = recency + frequency + intrinsic value
  • Three-Tier Promotion: Peripheral ↔ Working ↔ Core
  • Access Reinforcement: frequently recalled memories decay slower

Smart Metadata

  • L0/L1/L2 layered storage for progressive detail retrieval
  • Temporal versioning with supersede chains
  • Fact key deduplication

Database Schema

LanceDB table memories:

FieldTypeDescription
idstring (UUID)Primary key
textstringMemory text (FTS indexed)
vectorfloat[]Embedding vector
categorystringpreference / fact / decision / entity / skill / lesson / other
scopestringScope identifier
importancefloatImportance score 0–1
timestampint64Creation timestamp (ms)
metadatastring (JSON)Extended metadata (L0/L1/L2, tier, access_count, etc.)

Development

git clone https://github.com/cablate/memory-lancedb-mcp.git
cd memory-lancedb-mcp
npm install
npm test

Run the server locally:

EMBEDDING_API_KEY=your-key npx tsx server.ts

License

MIT — see LICENSE for details.

Reviews

No reviews yet

Sign in to write a review