- Início
- Plugins
- Ferramentas e funções
- local-kb-mcp (dsh-ai-kb)
local-kb-mcp (dsh-ai-kb)
ye-light/local-kb-mcp/packages/dsh-ai-kb
Local-first document knowledge base for DeepSeek Harness: search, overview, note deposit, sync and remove tools backed by a bundled Python/SQLite engine.
Instalar
dsh plugin --profile web add github:ye-light/local-kb-mcpEste plugin está no subdiretório packages/dsh-ai-kb do repositório.
README
🗂️ local-kb-mcp
A local-first document knowledge base for AI agents
Python CLI · MCP Server · DeepSeek Harness Host Plugin
English · 简体中文
Index Markdown, text, JSON, source code, and logs in SQLite, then retrieve only the relevant chunks with keyword, semantic, or hybrid search. It is designed for local project documentation and notes that are too large to fit into an agent's context.
The core CLI and MCP server use only the Python standard library. Your documents and database stay on your machine.
Open-source tool, private data. This repository contains no knowledge-base data. You choose what to import and where the database is stored.
Why local-kb-mcp?
- Local-first: no hosted database, API key, or external retrieval service is required.
- Agent-ready: use the CLI directly, connect any MCP-compatible host, or install the self-contained DeepSeek Harness plugin.
- Retrieval that fits technical notes: adaptive hybrid ranking, exact-identifier protection, project filters, and an optional local BGE embedding model.
- Maintainable data: incremental imports, partition overviews, note ingestion and removal, verified backups, and built-in health checks.
Features
- Project partitions: assign every document to a
projectand filter searches by partition. - Structure-aware chunking: split by Markdown headings and paragraphs, with bounded chunk sizes and configurable overlap.
- Incremental imports: skip unchanged files using content SHA1; retry interrupted batches without re-importing everything.
- Four retrieval modes: hybrid (default), keyword, semantic, and semantic with a minimum score.
- Exact identifier protection: function names, node names, and other single ASCII identifiers automatically use literal keyword search.
- Optional local embeddings: use a BGE Chinese ONNX model; missing models or dependencies fall back to keyword search.
- Partition overview: inspect file/chunk counts, common subdirectories, and topic terms before searching.
- Knowledge inbox: write reusable notes under
inbox/<project>/, ingest them withsync, or create them directly throughdeposit. - Verifiable backups: gzip compression, rotation, optional mirrored copies, SHA256 checks, and restore path-traversal protection.
- Health diagnostics:
doctorchecks Python, SQLite, database integrity, backups, locks, and host configuration.
Requirements
| Component | Requirement |
|---|---|
| Core CLI / MCP server | Python 3.8+ and SQLite 3.24+; no third-party Python packages required |
| DSH Host plugin | Python 3.10+; python or py -3 available, or configure pythonPath |
| Semantic search (optional) | onnxruntime, tokenizers, numpy, and a BGE Chinese ONNX model |
Quick start
# 1) Initialize the database (stored beside kb.py by default)
python kb.py init
# 2) Import documents into project partitions
python kb.py add notes ./my-notes/
python kb.py add papers ./pdfs-text/
# 3) Search
python kb.py search "keyword another-term" -k 5
python kb.py search "keyword" --project notes
python kb.py search "keyword" --full
# 4) Optional: build local embeddings
python kb.py embed
python kb.py search "a paraphrased query" --semantic
# 5) Inspect, back up, and restore
python kb.py overview
python kb.py doctor
python kb.py backup
python kb.py backups
python kb.py restore kb-20260101-120000.db.gz
# 6) Ingest or remove reusable notes
python kb.py sync
python kb.py rm "inbox/notes/example.md"
Retrieval modes
| Mode | Command | Best for |
|---|---|---|
| Hybrid (default) | search "query" | Everyday retrieval across natural language and technical terms |
| Keyword | --keyword | Exact terms, identifiers, or running without an embedding model |
| Semantic | --semantic | Paraphrases and concept-level similarity |
| Semantic + threshold | --semantic --min-score 0.45 | Reducing weak matches when the corpus may not contain an answer |
Hybrid search fuses keyword and semantic candidates with reciprocal-rank scoring. Semantic weight is fixed at 1.0; keyword weight adapts to the query:
- Rare ASCII terms (document frequency < 1000): 1.0
- Frequent ASCII terms (document frequency ≥ 1000): 0.2
- Chinese-only queries: 0.3
- Chunks containing the complete query string receive a keyword-score boost.
- A single ASCII identifier automatically bypasses hybrid ranking and uses literal keyword search.
Benchmark
A 50-query evaluation set, balanced between natural-language and terminology queries:
| Mode | Recall@5 | MRR | nDCG@10 |
|---|---|---|---|
| keyword | 0.304 | 0.361 | 0.307 |
| semantic | 0.560 | 0.723 | 0.558 |
| hybrid (adaptive) | 0.656 | 0.876 | 0.655 |
Relevance is weakly labeled by whether a chunk contains specified topic terms, which favors literal keyword matching. These measurements describe this evaluation set, not a universal performance guarantee.
Optional semantic search
Install the optional dependencies:
pip install onnxruntime tokenizers numpy
Place a BGE Chinese embedding model in <AI_KB_HOME>/models/bge-small-zh-v1.5/:
model.onnx
tokenizer.json
Alternatively, point AI_KB_EMBED_MODEL to another model directory, then run:
python kb.py embed
Embeddings are bound to the model SHA256, vector dimensions, and chunking parameters. Changing any of them blocks semantic queries until the index is rebuilt; the original documents are not modified. The default chunk size of 480 characters stays within the model's truncation limit.
Without a score threshold, semantic search still returns the nearest chunks when no good answer exists. Treat its output as leads and verify important claims against the source.
Use as an MCP server
kb_mcp.py is a zero-dependency stdio MCP server with six tools:
| Tool | Purpose |
|---|---|
search | Return source paths and matching chunks; supports hybrid, keyword, and semantic modes |
overview | Show partition maps, file/chunk counts, path groups, and topic terms |
add | Import files or directories |
stats | Show per-project statistics |
list | List indexed files |
deposit | Write a reusable note to inbox/<project>/ and index it immediately |
On Windows, register the launcher instead of hard-coding a Python executable:
command: 'cmd'
args: ['/c', '<AI_KB_HOME>\launch.cmd']
On Linux/macOS, run python3 <AI_KB_HOME>/kb_mcp.py. The launcher checks AI_KB_PYTHON, common Python installation directories, and the system PATH.
Install the DeepSeek Harness Host plugin
The self-contained Host plugin lives in packages/dsh-ai-kb and bundles its Python backend. It does not require a separately configured MCP server.
- Install from npm:
dsh plugin add dsh-local-kb-host— the package is published asdsh-local-kb-host. For development, addpackages/dsh-ai-kbas a local plugin directory instead. - Start a new DSH session. The plugin registers
aikb_search,aikb_overview,aikb_stats,aikb_deposit,aikb_sync, andaikb_rm. - Optional: configure
dataDirandpythonPath. The default data directory is%LOCALAPPDATA%\ai-kbon Windows and~/.ai-kbon Linux/macOS.
Do not enable the Host plugin and the legacy MCP wrapper at the same time, or their instructions will be duplicated. See the plugin guide for details.
Configuration
| Variable | Default | Purpose |
|---|---|---|
AI_KB_HOME | Directory containing kb.py | Database, inbox, models, and backups |
AI_KB_MIRROR | Empty (disabled) | Optional mirrored backup directory |
AI_KB_KEEP | 4 | Number of rotated backups to retain |
AI_KB_CHUNK | 480 | Chunk size; must not exceed the embedding truncation limit |
AI_KB_OVERLAP | 80 | Overlap between adjacent chunks |
AI_KB_EMBED_MODEL | <AI_KB_HOME>/models/bge-small-zh-v1.5 | Embedding model directory |
AI_KB_PYTHON | Auto-detected | Python executable used by the launcher |
AI_KB_PLUGIN_CFG | Empty | Optional host-plugin configuration checked by doctor |
On Windows, local overrides can be placed in env.cmd beside launch.cmd; keep that file out of version control.
Supported files and limits
Supported extensions: .md, .txt, .markdown, .json, .py, .yaml, .yml, .csv, .log, .html, and .htm, up to 8 MB per file. Convert PDFs, images, and Office documents to text before importing.
- Keyword matching is literal and space-separated; split Chinese queries into meaningful terms.
- Semantic search uses a general Chinese BGE model and may under-rank specialized terminology.
- Search results include local absolute paths; sanitize them before sharing publicly.
- WAL and
busy_timeoutallow concurrent readers/writers to queue safely, but very high write concurrency is not the target use case.
Documentation
- 简体中文说明
- Changelog
- Compatibility and upgrade guide
- Knowledge-distillation specification
- DeepSeek Harness plugin guide
License
MIT — see LICENSE.
Plugins relacionados
archify (deepseek-harness)
tt-a1i/archify
WeKnora (dsh-weknora)
tencent/weknora
next-ai-draw-io (dsh-plugin)
dayuanjiang/next-ai-draw-io
AiToEarn (dsh-plugin-aitoearn)
yikart/aitoearn