A local knowledge base based on SQLite + FTS5, helping users save, organize, and retrieve knowledge snippets. Data is fully localized.
Use Cases
- The user says "help me remember this" or "save this knowledge point"
- The user says "have I saved anything about XX before" or "search my knowledge base"
- The user says "organize the Python knowledge I've saved"
- The user wants to accumulate knowledge cards during research/learning
Execution Method
Database Structure
The knowledge base is stored in ~/Documents/xiaodazi/knowledge.db:
CREATE TABLE knowledge (
id INTEGER PRIMARY KEY AUTOINCREMENT,
title TEXT NOT NULL,
content TEXT NOT NULL,
tags TEXT DEFAULT '', -- 逗号分隔的标签
source TEXT DEFAULT '', -- 来源 URL 或文件
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
CREATE VIRTUAL TABLE knowledge_fts USING fts5(
title, content, tags,
content='knowledge',
content_rowid='id'
);
Core Operations
Save Knowledge:
import sqlite3
db = sqlite3.connect("~/Documents/xiaodazi/knowledge.db")
db.execute(
"INSERT INTO knowledge (title, content, tags, source) VALUES (?, ?, ?, ?)",
["Python 装饰器原理", "装饰器是一个接受函数并返回函数的高阶函数...", "python,编程", ""]
)
db.execute(
"INSERT INTO knowledge_fts (rowid, title, content, tags) VALUES (last_insert_rowid(), ?, ?, ?)",
["Python 装饰器原理", "装饰器是一个接受函数并返回函数的高阶函数...", "python,编程"]
)
db.commit()
Search Knowledge:
results = db.execute("""
SELECT k.id, k.title, snippet(knowledge_fts, 1, '**', '**', '...', 30) as excerpt,
k.tags, k.created_at
FROM knowledge_fts
JOIN knowledge k ON knowledge_fts.rowid = k.id
WHERE knowledge_fts MATCH ?
ORDER BY rank
LIMIT 10
""", ["Python 装饰器"]).fetchall()
Browse by Tag:
results = db.execute("""
SELECT title, substr(content, 1, 100) as preview, created_at
FROM knowledge
WHERE tags LIKE '%python%'
ORDER BY updated_at DESC
""").fetchall()
Interaction Flow
用户:帮我记住——Python 的 GIL 是全局解释器锁,同一时刻只有一个线程执行字节码
→ 保存到知识库,自动提取标签 [python, 并发]
→ 回复:已保存 ✅「Python GIL」— 标签:python, 并发
用户:我之前存过什么关于 Python 的知识?
→ 搜索知识库
→ 找到 3 条记录:
1. Python 装饰器原理(2/20)
2. Python GIL(2/26)
3. Python 异步编程(2/22)
Output Specifications
- When saving, confirm the title and tags so the user knows how to find it again
- Search results are sorted by relevance and show a summary preview
- Tags are automatically extracted, and users can also specify them manually
- Supports saving directly from the output of other Skills (such as the conclusions of in-depth research)