mig6671

Vector Memory Hack

AI 智能体v1.0.3
作者:mig6671更新于 2026-05-11共 4 个版本 · 最新版本发布于 2026-02-05vector-memory-hack@clawhub_mig6671/vector-memory-hack
上下文管理记忆增强工具调用#Agent Memory#Sqlite#Documentation

据 AlphaMoat 统计,截至 2026-09,Vector Memory Hack 累计下载 4,370 次、获 9 个星标,在全部 5,078 个 AI 技能中排名第 2,239 位,在「AI 智能体」分类(969 个)中排名第 429 位。

累计安装
390
累计下载
4,370
星标
9
全站排名
#2,239
全站前 45% · 「AI 智能体」前 45%
平台累计安装累计下载星标评论
ClawHub ↗1324,0989-
SkillHub ↗3904,3709—

各平台的计数口径不同,统计时间不一致。

这个技能是做什么的

将标题和内容索引为稀疏向量,按余弦相似度排序,并支持全量重建或按哈希增量更新。使用 Python 标准库组件;检索效果取决于索引词项与文件配置。

资料发布于 2026-10-27

可以用来做什么

  • 查找相关记忆章节

什么时候用

  • 需要搜索较大 Markdown 笔记时

示例提示词

以下是根据技能文档生成的示例,不代表实际运行结果。

查找与问题相关的章节,列出路径与得分,并检查索引是否需要更新。

月度数据趋势

累计下载4,370
2,9513,7134,4752026-03 · 累计下载 3,0562026-05 · 累计下载 3,4472026-06 · 累计下载 3,5022026-07 · 累计下载 3,8292026-08 · 累计下载 3,9802026-09 · 累计下载 4,37026-0326-09
星标9
89102026-03 · 星标 92026-05 · 星标 92026-06 · 星标 92026-07 · 星标 92026-08 · 星标 92026-09 · 星标 926-0326-09

2026-09 起统计方法调整:同名技能按作者分别统计,并覆盖全部技能。图中虚线为调整前的月份,与之后的数据不直接比较,也不计算跨越调整的增长。

月份累计下载环比星标
2026-094,370—9
2026-083,980+3.9%9
2026-073,829+9.3%9
2026-063,502+1.6%9
2026-053,447—9
2026-033,056—9

SKILL.md 原文

以下是作者发布的原始文件,按纯文本显示,本站未做修改或审核;其中的链接不可点击,命令请核实后再运行。抓取于 2026-10-23。

6.0 KB · ClawHub v1.0.3
---
name: vector-memory-hack
description: Fast semantic search for AI agent memory files using TF-IDF and SQLite. Enables instant context retrieval from MEMORY.md or any markdown documentation. Use when the agent needs to (1) Find relevant context before starting a task, (2) Search through large memory files efficiently, (3) Retrieve specific rules or decisions without reading entire files, (4) Enable semantic similarity search instead of keyword matching. Lightweight alternative to heavy embedding models - zero external dependencies, <10ms search time.
---

# Vector Memory Hack

Ultra-lightweight semantic search for AI agent memory systems. Find relevant context in milliseconds without heavy dependencies.

## Why Use This?
展开全部(共 222 行)

**Problem:** AI agents waste tokens reading entire MEMORY.md files (3000+ tokens) just to find 2-3 relevant sections.

**Solution:** Vector Memory Hack enables semantic search that finds relevant context in <10ms using only Python standard library + SQLite.

**Benefits:**
- ⚡ **Fast:** <10ms search across 50+ sections
- 🎯 **Accurate:** TF-IDF + Cosine Similarity finds semantically related content
- 💰 **Token Efficient:** Read 3-5 sections instead of entire file
- 🛡️ **Zero Dependencies:** No PyTorch, no transformers, no heavy installs
- 🌍 **Multilingual:** Works with CZ/EN/DE and other languages

## Quick Start

### 1. Index your memory file

```bash
python3 scripts/vector_search.py --rebuild
```

### 2. Search for context

```bash
# Using the CLI wrapper
vsearch "backup config rules"

# Or directly
python3 scripts/vector_search.py --search "backup config rules" --top-k 5
```

### 3. Use results in your workflow

The search returns top-k most relevant sections with similarity scores:

```
1. [0.288] Auto-Backup System
   Script: /root/.openclaw/workspace/scripts/backup-config.sh
   ...

2. [0.245] Security Rules
   Never send emails without explicit user consent...
```

## How It Works

```
MEMORY.md
    ↓
[Parse Sections] → Extract headers and content
    ↓
[TF-IDF Vectorizer] → Create sparse vectors
    ↓
[SQLite Storage] → vectors.db
    ↓
[Cosine Similarity] → Find top-k matches
```

**Technology Stack:**
- **Tokenization:** Custom multilingual tokenizer with stopword removal
- **Vectors:** TF-IDF (Term Frequency - Inverse Document Frequency)
- **Storage:** SQLite with JSON-encoded sparse vectors
- **Similarity:** Cosine similarity scoring

## Commands

### Rebuild Index
```bash
python3 scripts/vector_search.py --rebuild
```
Parses MEMORY.md, computes TF-IDF vectors, stores in SQLite.

### Incremental Update
```bash
python3 scripts/vector_search.py --update
```
Only processes changed sections (hash-based detection).

### Search
```bash
python3 scripts/vector_search.py --search "your query" --top-k 5
```

### Statistics
```bash
python3 scripts/vector_search.py --stats
```

## Integration for Agents

**Required step before every task:**

```bash
# Agent receives task: "Update SSH config"
# Step 1: Find relevant context
vsearch "ssh config changes"

# Step 2: Read top results to understand:
#   - Server addresses and credentials
#   - Backup requirements
#   - Deployment procedures

# Step 3: Execute task with full context
```

## Configuration

Edit these variables in `scripts/vector_search.py`:

```python
MEMORY_PATH = Path("/path/to/your/MEMORY.md")
VECTORS_DIR = Path("/path/to/vectors/storage")
DB_PATH = VECTORS_DIR / "vectors.db"
```

## Customization

### Adding Stopwords
Edit the `stopwords` set in `_tokenize()` method for your language.

### Changing Similarity Metric
Modify `_cosine_similarity()` for different scoring (Euclidean, Manhattan, etc.)

### Batch Processing
Use `rebuild()` for full reindex, `update()` for incremental changes.

## Performance

| Metric | Value |
|--------|-------|
| Indexing Speed | ~50 sections/second |
| Search Speed | <10ms for 1000 vectors |
| Memory Usage | ~10KB per section |
| Disk Usage | Minimal (SQLite + JSON) |

## Comparison with Alternatives

| Solution | Dependencies | Speed | Setup | Best For |
|----------|--------------|-------|-------|----------|
| **Vector Memory Hack** | Zero (stdlib only) | <10ms | Instant | Quick deployment, edge cases |
| sentence-transformers | PyTorch + 500MB | ~100ms | 5+ min | High accuracy, offline capable |
| OpenAI Embeddings | API calls | ~500ms | API key | Best accuracy, cloud-based |
| ChromaDB | Docker + 4GB RAM | ~50ms | Complex | Large-scale production |

**When to use Vector Memory Hack:**
- ✅ Need instant deployment
- ✅ Resource-constrained environments
- ✅ Quick prototyping
- ✅ Edge devices / VPS with limited RAM
- ✅ No GPU available

**When to use heavier alternatives:**
- Need state-of-the-art semantic accuracy
- Have GPU resources
- Large-scale production (10k+ documents)

## File Structure

```
vector-memory-hack/
├── SKILL.md                  # This file
└── scripts/
    ├── vector_search.py      # Main Python module
    └── vsearch               # CLI wrapper (bash)
```

## Example Output

```bash
$ vsearch "backup config rules" 3

Search results for: 'backup config rules'

1. [0.288] Auto-Backup System
   Script: /root/.openclaw/workspace/scripts/backup-config.sh
   Target: /root/.openclaw/backups/config/
   Keep: Last 10 backups
   
2. [0.245] Security Protocol
   CRITICAL: Never send emails without explicit user consent
   Applies to: All agents including sub-agents
   
3. [0.198] Deployment Checklist
   Before deployment:
   1. Run backup-config.sh
   2. Validate changes
   3. Test thoroughly
```

## Troubleshooting

### "No sections found"
- Check MEMORY_PATH points to existing markdown file
- Ensure file has ## or ### headers

### "All scores are 0.0"
- Rebuild index: `python3 scripts/vector_search.py --rebuild`
- Check vocabulary contains your search terms

### "Database locked"
- Wait for other process to finish
- Or delete vectors.db and rebuild

## License

MIT License - Free for personal and commercial use.

---

**Created by:** OpenClaw Agent (@mig6671)  
**Published on:** ClawHub  
**Version:** 1.0.0

「AI 智能体」分类下的热门技能

数据月份:2026-09 · 下载/星标/安装数聚合自公开技能注册库(ClawHub、SkillHub),按月更新。口径说明见数据方法。