flexible-database-design
Guide agents and users to design and implement a "flexible database" on SQLite that can handle semi-structured, multi-source data. Typical scenarios: persona...
数据来源:ClawHub。 在 ClawSkills 查看
选择你使用的 Agent
方法一:命令行安装(推荐)
推荐(无需提前安装 clawhub)
npx clawhub@latest --dir ~/.claude/skills install flexible-database-design或使用 clawhub CLI(需提前安装)
clawhub --dir ~/.claude/skills install flexible-database-design⚠️ 需要 Node.js 18+,没有 Node?请使用下方方法二直接下载 ZIP。 安装 Node.js →
方法二:手动下载安装(无需 Node)
下载 ZIP,解压后将文件夹放到以下路径,重启 Agent 即可:
安装路径
~/.claude/skills/flexible-database-design/💡解压后将文件夹放到上方路径,重启 Agent 即可生效
--- name: flexible-database-design version: 1.0.0 description: | Guide agents and users to design and implement a "flexible database" on SQLite that can handle semi-structured, multi-source data. Typical scenarios: personal knowledge base, PDF/report archive, policy tracking, fragmented notes, custom form/questionnaire fields, multi-source data aggregation, event logging. When the user says things like "I want to build a knowledge base", "archive PDF reports", "search within report content", "collect policies or scattered information", this skill provides the end-to-end workflow. It includes: design principles, a three-layer model, agent workflows, schema templates, and reference Python scripts. metadata: openclaw: emoji: 🧱 requires: bins: ["python3"] install: - id: python kind: system bins: ["python3"] ---
一套可复用的「软 Schema」设计方法:主干硬、尾巴软,三层演进。用户安装后,Agent 可据此指导其真正构建出灵活数据库。
---
---
| 层级 | 作用 | 典型做法 | |------|------|----------| | 原始层 | 不丢信息、可追溯 | 整条记录原样存,加哈希去重、来源、版本号 | | 软字段层 | 灵活查询 | JSON 存结构化结果;键值对表按 key 查、聚合 | | 业务视图层 | 高频查询、报表 | 物化表/视图,按需建索引 |
---
向用户确认以下信息,并记录到对话中:
| 问题 | 用途 | |------|------| | 你的数据主要来自哪里?(微信/网页/API/手动输入/多种) | 定 source_type 枚举 | | 每条记录大概有哪些「永远会有」的信息?(如:时间、来源、类型) | 定主干字段 | | 有哪些「可能经常变、不同来源不一样」的信息? | 确认用 JSON/键值对 | | 是否有按编号/文号等唯一标识查询的需求? | 决定是否在视图中加入对应字段,并考虑快捷查询 | | 需要全文搜索吗? | 决定是否建 FTS | | 内容语言?(中文为主 / 英文为主 / 混合) | 决定是否采用中文分词、FTS 策略 | | 内容形态?(纯文本 / PDF / Excel / 网页 / 混合) | 决定归档前是否需要提取(如 pypdf) | | 预期数据量?(百 / 千 / 万 / 十万级) | 决定 LIKE 回退是否可用、是否考虑外部搜索引擎 |
根据用户描述,选择最接近的场景并适配:
| 场景 | 主干字段建议 | 软字段典型 key | |------|--------------|----------------| | 个人知识库 / 碎片收集 | id, created_at, source, content_type, raw_content | title, tags, url, project, deadline | | 政策信息收集 | id, created_at, source, source_type | title, release_date, issuing_org, policy_type, url, policy_no, industry, subsidy_amount | | 财务报表收集 | id, created_at, source, source_type | company, report_type, report_date, revenue, net_income, total_assets, roa, roe | | 表单/问卷 | id, created_at, form_id, respondent_id, raw_response | 各题目 id 或题目名 | | PDF/报告知识库 | id, created_at, source, content_type, raw_content | report_title, report_type, period_start, period_end, file_path | | 多源异构(如群消息聚合) | id, created_at, source, sender, raw_content | data_type, items[], trend, 各业务字段 |
- 调整 source_type 的 CHECK 枚举; - 如需 FTS,取消 messages_fts 相关注释; - 业务视图层参考 references/view_examples.sql 按需新增视图。业务视图应覆盖高频查询字段:政策类含 title、release_date、issuing_org、policy_type、url、policy_no;知识库类含 title、tags、url、project;财报类含 company、report_type、report_date、revenue、net_income;PDF/报告类含 report_title、report_type、period_start、period_end。
data/ 目录,指定 db 路径(如 data/flexible.db)。| 内容语言 | 推荐方案 | 说明 | |----------|----------|------| | 英文为主 | FTS5 (unicode61) | 默认即可 | | 中文为主 | FTS + LIKE 回退 | 长短语易漏检,需实现 recall() | | 中文为主(数据量 < 5000) | 同上 + 短词拆分 | 如「煤炭期货价格」→ 拆为「煤炭」「期货」「价格」分别查,取并集 | | 中文为主(数据量 > 5000) | 考虑 Meilisearch / jieba+FTS | SQLite FTS 中文能力有限 |
实现要点:查询层实现 recall(keyword):先 FTS,无结果则 LIKE;中文可加短词拆分。LIKE '%x%' 无法用索引,数据量大时需评估性能。扫描件 PDF 无法提取正文,归档时需跳过或标记。
scripts/:核心 flexible_db.py、archive_item.py、query_items.py;可选 manage_item.py、import_batch.py、quick_validate.py、extractors/。flexible_db.py 中的 db_path 指向用户的 db 路径。archive_item.py --llm-extract 或配置 FLEXIBLE_EXTRACTOR=extractors.dummy:extract;可自定义 extractors/ 下的实现。抽取器字段应与场景匹配:政策类建议 title、release_date、issuing_org、policy_type、url、policy_no;知识库类建议 title、tags、url、project;财报类建议 company、report_type、report_date、revenue、net_income(金额统一存「元」);PDF/报告类建议 report_title、report_type、period_start、period_end。pip install pypdf),扫描件无法提取时跳过。可选:将 PDF 复制到项目 data/reports/ 统一管理,file_path 存相对路径;抽取器可从文件名解析 period、source、report_type。python 或 python3 按环境选择):# 建表(首次运行脚本时会自动执行 schema)
python3 scripts/archive_item.py -c "测试第一条" -s "manual"
# 查询
python3 scripts/query_items.py --list
python3 scripts/query_items.py --field "tags" --value "工作"
python3 scripts/query_items.py --stats
recall())---
| 用户意图 | 推荐主干 | 推荐软字段 | 备注 | |----------|----------|------------|------| | 个人知识库 | id, created_at, source, content_type | title, tags, url, project | 碎片收集同此 | | PDF/报告知识库 | id, created_at, source, content_type, file_path | report_title, report_type, period_start, period_end | 需提取正文;中文检索见「全文检索策略」 | | 政策信息收集 | id, created_at, source, source_type | title, release_date, issuing_org, policy_type, url, policy_no, industry, subsidy_amount | 政府网站/新闻来源,文号常作查询键 | | 财务报表收集 | id, created_at, source, source_type | company, report_type, report_date, revenue, net_income, total_assets, roa, roe | 金额统一存「元」;report_type→category | | 表单/问卷 | id, created_at, form_id, respondent_id | 题目 id → 答案 | 可加 form_version | | 多源消息聚合 | id, created_at, source, sender | data_type, items[], trend | 参考 agri-market-info | | 埋点/事件 | id, created_at, event_name, user_id | properties JSON | 可加 event_version |
---
LIKE '%x%' 用于万级数据 → 全表扫描,应评估或改用外部搜索引擎---
flexible-database-design/
├── SKILL.md # 本文件
├── README.md
├── references/
│ ├── schema_template.sql # 通用建表模板
│ ├── view_examples.sql # 业务视图示例
│ └── fulltext_chinese.md # 可选:中文检索实现示例(短词拆分、recall 逻辑)
└── scripts/
├── flexible_db.py # 数据库核心逻辑
├── archive_item.py # 归档 CLI(支持 --llm-extract、--backup)
├── query_items.py # 查询 CLI(支持 --export)
├── manage_item.py # 管理 CLI(软删除、恢复、更新)
├── import_batch.py # 批量导入
├── quick_validate.py # 快速验证
└── extractors/ # 抽取器(可替换为 LLM 实现)
---
allowed-tools: - Bash - FileRead - FileWrite - Shell
---
作者 | Mars Yang 日期 | 2025-03-09
安装 Flexible Database Design – SQLite flexible schema & knowledge base skill 后,可以对 AI 说这些话来触发它
Help me get started with Flexible Database Design – SQLite flexible schema & knowledge base skill
Explains what Flexible Database Design – SQLite flexible schema & knowledge base skill does, walks through the setup, and runs a quick demo based on your current project
Use Flexible Database Design – SQLite flexible schema & knowledge base skill to guide agents and users to design and implement a "flexible database...
Invokes Flexible Database Design – SQLite flexible schema & knowledge base skill with the right parameters and returns the result directly in the conversation
What can I do with Flexible Database Design – SQLite flexible schema & knowledge base skill in my data & analytics workflow?
将技能文件夹放到 ~/.claude/skills/flexible-database-design/ 目录(个人级,所有项目可用),或 .claude/skills/flexible-database-design/(项目级)。重启 AI 客户端后,用 /flexible-database-design 主动调用,或让 AI 根据上下文自动发现并使用。
Flexible Database Design – SQLite flexible schema & knowledge base skill 支持 Claude、Cursor、OpenClaw,可与这些 AI 平台无缝集成,扩展其能力。
Flexible Database Design – SQLite flexible schema & knowledge base skill 可免费安装使用。请查阅仓库了解许可证信息。
Guide agents and users to design and implement a "flexible database" on SQLite that can handle semi-structured, multi-source data. Typical scenarios: persona...
Lists the top use cases for Flexible Database Design – SQLite flexible schema & knowledge base skill, with example commands for each scenario
Automate my data & analytics tasks using Flexible Database Design – SQLite flexible schema & knowledge base skill
Identifies repetitive steps in your workflow and sets up Flexible Database Design – SQLite flexible schema & knowledge base skill to handle them automatically
Flexible Database Design – SQLite flexible schema & knowledge base skill 属于「Data & Analytics」分类,该分类的技能帮助 AI 智能体在此领域执行专业任务。