local-embedding-engine

A purely local text embedding engine supporting both NN and stat pathways; provides a persistent vector store, multi-document indexing, BM25 hybrid search, and self-evolving feedback. Operates with zero external API dependencies and includes automatic degradation behavior.

Installation

Review the source and dependencies with a prompt. A package is available to download.

Install with an AI assistant

Copy the prompt so your assistant can review the pinned revision and dependencies first.

View promptHide prompt
Check whether SkillPI Skill Finder is installed for your current agent. If it is missing, install and enable it using the official instructions at https://github.com/Findskills/skillpi. Then use Skill Finder to locate and install "local-embedding-engine" from this exact SkillPI detail page: https://skillpi.com/skills/deepskill-9ce6554031e8c2c346b1046386dd5953cb743d90f043b615646a1ac85baf2768. Verify the upstream source and version against https://skillhub.cn/skills/user_287b0fec/local-embedding-engine before installing. If they do not match, stop and report the mismatch. Report the installed path and source version.

Source and setup

skillhub.cn

Setup guidance pending

See the original source for supported tools, dependencies, and permissions.

Installation test pending

A purely local text embedding engine supporting both NN and stat pathways; provides a persistent vector store, multi-document indexing, BM25 hybrid search, and self-evolving feedback. Operates with zero external API dependencies and includes automatic degradation behavior.

0 Downloads

Introduction source: third_party · user_287b0fec · 2.1.0 Reference

SkillPi interpretation

Tasks
Translation pending; see source documentation.
Audience
Not specified in the source documentation.
Inputs and outputs
Not specified in the source documentation.
Software, accounts and paid services
Translation pending; see source documentation.
Limits and differences
Not specified in the source documentation.
Testing
Not tested

Browse files

Browse files at the source ↗

Original SKILL.md

Open original ↗
Frontmatter
name: local-embedding-engine
description: 纯本地文本嵌入,支持NN/stat双路径;持久化向量库、多文档索引、BM25混合搜索、自进化反馈;零API依赖,自动降级
slug: local-embedding-engine
displayName: 本地文本嵌入引擎 v2.0
version: 2.1.0
tags:
- 工具
- embedding
- 本地部署
- 向量搜索
- RAG

本地文本嵌入引擎 (local-embedding-engine v2.0.0)

定位:为需要文本相似度 / 语义对齐 / 本地 RAG 的场景提供零 API 依赖的本地 embedding 能力 触发词:「本地embedding」「文本向量化」「相似度计算」「文风对齐」「语义搜索」「索引文件」「搜索向量库」 前置条件:Python 3.8+;nn 路径需 sentence-transformers,stat 路径零依赖


一、双路径架构

路径A:本地神经网络模型(nn,质量优先)

  • 模型:sentence-transformers/all-MiniLM-L6-v2(22MB + torch CPU ~200MB)
  • 输出:768 维稠密向量
  • 速度:AMD 5500U ~50-100 句/秒(短文本)
  • 质量:接近 OpenAI ada-002 的 85-90%
  • 安装:pip install sentence-transformers -i https://pypi.tuna.tsinghua.edu.cn/simple
  • 模型下载:首次运行自动下载;本机 Hugging Face 被封,已内置 HF_ENDPOINT=https://hf-mirror.com
  • 模型缓存:~/.cache/huggingface/hub/models--sentence-transformers--all-MiniLM-L6-v2

路径C:纯统计方法(stat,零依赖 fallback)

  • TF-IDF 关键词重叠度 + N-gram Jaccard + 编辑距离归一化
  • 零第三方依赖(纯标准库)
  • 速度:1000+ 句/秒

模式选择

  • mode="nn":强制神经网络(需 sentence-transformers)
  • mode="stat":强制统计(零依赖)
  • mode="auto":st 可用则 nn,否则降级 stat(零配置可用)

二、v2.0 新增四大能力

🗄️ P0 持久化向量库(SQLite)

  • 向量 + 元数据存储在 SQLite,重启不丢失
  • rebuild_index() 全量清空重建
  • 增量更新:hash 不变则跳过,已变则更新
  • 统计:emb._store.stats() 查看 chunks/docs/vocab_size

📚 P0 多文档索引

  • index_file(path):索引单个文件(.txt/.md,自动按 ##/### 标题分段)
  • index_directory(dir_path):批量索引目录(CLI 封装)
  • 全局 TF-IDF:跨文档归一化(IDF 基于整个语料库)
  • 支持自定义 chunk_size / overlap 参数

🔀 P1 BM25 混合搜索

  • 语义向量 + BM25 关键词双通道
  • 可调权重:α × 向量分数 + β × BM25分数(默认 α=0.7, β=0.3)
  • semantic_search(query, top_k=5) 从向量库搜索
  • semantic_search(query, corpus=[...], top_k=5) 在传入语料中搜索
  • return_confidence=True 返回置信度(high/medium/low)

🧬 P1 自进化反馈

  • learn_feedback(text_a, text_b, correct_score, label) 记录纠正
  • 累计 ≥3 条同一 label 后自动给出权重调整建议
  • get_feedback_stats() 查看统计
  • 反馈持久化到 feedback/feedback.jsonl

三、统一接口

from local_embedding_engine import LocalEmbedder

emb = LocalEmbedder(mode="auto", persistent=True)   # v2.0 开启持久化

# ---- 核心相似度(v1.2 兼容)----
emb.similarity("原文", "续写")               # 单对相似度 0-1
emb.batch_similarity(base, candidates)       # list[float]
emb.semantic_search(query, corpus, top_k=5)  # [(idx, score), ...]
emb.chunk_info(text)                         # 分段诊断信息

# ---- v2.0 新增:持久化向量库 ----
emb.index_file("D:/projects/novel.md")       # 索引单个文件
emb.rebuild_index()                          # 清空向量库
emb._store.stats()                           # 统计向量库

# ---- v2.0 新增:混合搜索 ----
emb.semantic_search("十日终焉角色关系", top_k=5, alpha=0.7, beta=0.3)
# 返回:[{"idx":3,"score":0.82,"confidence":"high","path":"hybrid","title":"...","content":"..."}]

# ---- v2.0 新增:自进化反馈 ----
emb.learn_feedback("闷油瓶独自站着", "吴邪在翻笔记", 0.25, label="correction")
emb.get_feedback_stats()                     # 查看反馈统计

四、长文本分段策略

触发条件:输入文本 > 1024 字自动启用滑动窗口分段

参数 默认值 说明
chunk_size 512 字符 每块大小
overlap 128 字符 块间重叠
long_text_threshold 1024 字符 触发分段阈值

处理流程:

  1. 输入文本字数 > threshold → 滑动窗口分块
  2. 每块独立编码 → 768 维向量
  3. 多块向量平均池化 → 最终 768 维向量

五、性能基准(AMD Ryzen 5 5500U · CPU only)

文本 模式 单条耗时 吞吐量 内存峰值
短文本(100字) nn 34 ms 55 句/秒 15 KB
短文本(100字) stat 0.07 ms 13,939 句/秒 16 KB
中文本(1000字) nn 73 ms 20 句/秒 19 KB
中文本(1000字) stat 0.86 ms 1,438 句/秒 156 KB
长文本(5000字) nn ⚠ OOM(需分段) - -

六、OpenClaw Tool 封装(embedding_tool.py)

先生对话中直接调用,无需 exec 启动子进程:

python scripts/embedding_tool.py --action semantic_search --args '{"query":"十日终焉角色关系","top_k":5}'
python scripts/embedding_tool.py --action index_file --args '{"file_path":"D:/projects/novel.md"}'
python scripts/embedding_tool.py --action stats --args '{}'
python scripts/embedding_tool.py --action feedback --args '{"stats_only":true}'

支持动作:similarity / batch_similarity / semantic_search / index_file / index_directory / rebuild_index / stats / feedback / chunk_info / cache


七、文件结构

skills/local-embedding-engine/
├── SKILL.md
├── scripts/
│   ├── local_embedding_engine.py   # 核心引擎 v2.0.0(主文件)
│   ├── embedding_tool.py           # OpenClaw Tool 封装(新增)
│   ├── embedding_server.py         # OpenAI-compatible server(v1.2 保留)
│   └── benchmark.py                # 性能基准测试 v2.0(升级)
├── vector_store/                   # SQLite 向量库(persistent=True 时生成)
│   └── vectors.db
└── feedback/                       # 自进化反馈(learn_feedback 时生成)
    └── feedback.jsonl

八、技术约束

  • 无 openai key 依赖
  • nn 路径需装 sentence-transformers;stat 路径零依赖
  • Hugging Face 访问受限,部署时需配置镜像地址(已内置)
  • persistent=True 时自动创建 vector_store/ 和 feedback/ 目录
  • SQLite 向量库单文件,支持多进程读但不支持并发写

九、版本记录

v2.0.0(2026-08-05)

  • ✅ P0 持久化向量库:SQLite 存储,重启不丢失;rebuild/update 机制
  • ✅ P0 多文档索引:index_file / index_directory,全局 TF-IDF
  • ✅ P1 混合搜索:BM25 + 向量双通道,α/β 可调权重
  • ✅ P1 自进化反馈:learn_feedback() 记录纠正,≥3条触发权重建议
  • ✅ 全部原有功能保留,接口向后兼容
  • ✅ OpenClaw Tool 封装(embedding_tool.py)
  • ✅ benchmark.py 升级含 v2.0 新功能测试

v1.2.0(历史)

  • 类型统一 / 延迟加载 / n-gram LRU 缓存

v1.1.0(历史)

  • 长文本分段(滑动窗口平均池化)

十、通用说明

本文档面向通用使用场景,不包含特定部署环境的内部路径、依赖配置与项目示例。实际部署时参照环境要求调整。

Current listing version

2.1.0

Verify the source revision ↗

Safety and assessment details

Quality assessment

Out of 100 · Assessment report from SkillPi LAB.

Scenario Value92/100

Highlights

  • 提供纯本地文本嵌入能力,支持NN/stat双路径,零API依赖
  • 新增持久化向量库、多文档索引、BM25混合搜索、自进化反馈四大核心能力
  • 解决本地RAG、语义搜索、文风对齐等高频刚需场景
Trigger Precision95/100

Highlights

  • 触发词覆盖全面:本地embedding、文本向量化、相似度计算、语义搜索等
  • 边界清晰,变体合理,不易误触或漏触
Structure and Standards94/100

Areas to improve

  • description写错位置 Reported severity: Minor

    顶层frontmatter已有description,skill_body内部重复定义

    Recommendation: 建议删除skill_body内部的重复description,保持唯一性

Highlights

  • 文档结构完整,含双路径架构、四大新增能力、统一接口、性能基准等
  • 步骤清晰,有端到端代码示例,frontmatter完整
Execution Reliability93/100

Areas to improve

  • 缺少When to Use独立章节 Reported severity: Minor

    触发词已覆盖使用场景,但无独立When to Use章节

    Recommendation: 建议增加独立When to Use章节,明确典型使用场景

Highlights

  • 工具来源明确(sentence-transformers),参数正确
  • 覆盖主要异常(自动降级stat路径),不可逆操作有明确说明
  • 反馈机制持久化,支持自进化
Evidence Verifiability (mean of the first four)94/100

The arithmetic mean of the first four original scores, rounded to a whole number.

Static text checks

100 / 100 · skillpi-20261123-no-r3-v1

No current rules matched the text.

This score reflects rule matches in the text and is provided for reference before use. It excludes attachments and runtime behavior.

Permissions and checks before use

Automatically summarized from this main document. Matches may be examples or defensive advice; they are not actual permission declarations. Attachments, external dependencies and runtime behavior are not covered.

  • Install or fetch external dependencies

    Use official sources and pin versions. Check install scripts in an isolated environment. This document check does not cover code downloaded later.

    Mentioned in main document · lines 29
Domains or addresses referenced in the document

These addresses may be documentation links or examples, not an approved network allowlist. Verify actual destinations and outgoing data before use.

  • hf-mirror.com
  • pypi.tuna.tsinghua.edu.cn

These notices grant no permissions. Your host tool must still confirm file changes, secrets, external transfers or costs as needed.

Security rating and access scope

safe · Static evidence review; not a runtime safety guarantee.

Translation pending; see source documentation.

Before use, confirm and authorize actual file access, external services and network destinations in your host. This review grants no runtime permissions.