@jerryjiao/knowflow 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,110 @@
1
+ # LLM Wiki 方法论
2
+
3
+ > 基于 Andrej Karpathy 的 [LLM Wiki Gist](https://karpathy.github.io/llm-wiki/),KnowFlow 将这一理念工程化实现。
4
+
5
+ ## 核心问题
6
+
7
+ 传统知识管理方式存在根本性缺陷:
8
+
9
+ | 方式 | 问题 |
10
+ |------|------|
11
+ | **收藏/书签** | "存了 = 学了" 的错觉(Collector's Fallacy) |
12
+ | **笔记软件** | 只解决"存",不解决"整理"和"连接" |
13
+ | **RAG** | 每次从零搜索,无记忆、无积累、无上下文 |
14
+
15
+ ## LLM Wiki 的核心洞察
16
+
17
+ > **别每次都去原始文档里翻,先把知识编译好,放在那,用的时候直接拿。**
18
+
19
+ 类比:
20
+
21
+ - **RAG = 临时工** — 每次慌慌张张翻文件柜,找到几张纸拼答案,下次再来一脸懵
22
+ - **LLM Wiki = 全职图书管理员** — 平时就在整理材料:提取信息、发现关联、建立索引、维护知识图谱。你来问时直接调取
23
+
24
+ ## 三层架构
25
+
26
+ ### 1. Raw Layer(原材料)
27
+
28
+ 你喂进去的一切原始内容:
29
+ - 网页 URL(文章、博客、文档)
30
+ - Twitter/X 书签和推文
31
+ - PDF 论文和白皮书
32
+ - 微信公众号文章
33
+ - YouTube 字幕
34
+ - 飞书/Notion 文档
35
+
36
+ **原则**:Raw 层只存储,不修改。它是不可变的源数据。
37
+
38
+ ### 2. Wiki Layer(编译后的知识)— 核心
39
+
40
+ AI 读取 Raw 内容后,自动生成三类结构化页面:
41
+
42
+ #### 实体页(Entity Pages)
43
+ 具体的"东西":
44
+ - 人物:Andrej Karpathy、Jerry
45
+ - 公司/组织:OpenAI、智谱 AI
46
+ - 项目/产品:MCP 协议、KnowFlow、Claude Code
47
+ - 概念的具体实例
48
+
49
+ #### 概念页(Concept Pages)
50
+ 抽象的"想法"和方法论:
51
+ - RAG(检索增强生成)
52
+ - Embedding(向量嵌入)
53
+ - 向量检索
54
+ - 自回归 vs 扩散模型
55
+ - Collector's Fallacy
56
+
57
+ #### 对比页(Comparison Pages)
58
+ 两个事物之间的系统对比:
59
+ - MCP vs A2A(Agent 通信协议)
60
+ - RAG vs LLM Wiki
61
+ - KnowFlow vs Notion AI
62
+ - CogView vs DALL-E
63
+
64
+ #### 来源页(Source Pages)
65
+ 原始内容的结构化摘要:
66
+ - 原文链接 + 元数据
67
+ - 提取的关键实体列表
68
+ - 自动生成的摘要
69
+
70
+ **关键特性**:页面之间**自动互相链接**
71
+ - 提到 OpenAI → 自动链到 OpenAI 实体页
72
+ - 提到 RAG → 自动链到 RAG 概念页
73
+ - 时间一长 → 形成一张**活的知识网络**
74
+
75
+ ### 3. Schema Layer(结构规则)
76
+
77
+ 告诉 AI 怎么编 Wiki 的"工作手册":
78
+ - 什么该提取,什么该忽略
79
+ - 页面格式规范
80
+ - 实体识别规则
81
+ - 链接策略
82
+
83
+ ## 为什么这比 RAG 更好?
84
+
85
+ ```
86
+ RAG 的流程:
87
+ 用户提问 → 搜索原始文档 → 拼凑答案 → 忘记一切
88
+
89
+ LLM Wiki 的流程:
90
+ 新内容进入 → 编译为 Wiki 页面 → 建立关联 → 更新知识图谱
91
+
92
+ 用户提问 → 从已编译的知识库调取 → 基于完整上下文回答 → 知识库持续增长
93
+ ```
94
+
95
+ 优势:
96
+ 1. **有记忆** — 知识是累积的,不是每次从零开始
97
+ 2. **有结构** — 实体、概念、对比,不是扁平的文档片段
98
+ 3. **可探索** — 知识图谱让你发现隐藏的关联
99
+ 4. **可验证** — 每条知识都有来源追溯
100
+
101
+ ## KnowFlow 的定位
102
+
103
+ KnowFlow 是 LLM Wiki 方法论的**开源实现**:
104
+
105
+ - 用 Node.js 构建 CLI 工具
106
+ - 用智谱 AI(或其他 LLM)做内容提取
107
+ - 用 Python 构建知识图谱和向量索引
108
+ - 全部本地运行,数据自主可控
109
+
110
+ **核心理念**:最有意思的不是最终工具,而是看着零散的信息一点点变成结构化知识的过程。
@@ -0,0 +1,200 @@
1
+ # KnowFlow 数据模型
2
+
3
+ ## Wiki 页面类型
4
+
5
+ ### 实体页 (Entity)
6
+
7
+ ```markdown
8
+ # {name}
9
+
10
+ **类型**: {person | organization | project | product | location}
11
+ **来源**: [{source_url}]
12
+ **首次提及**: {date}
13
+
14
+ ## 简介
15
+ {description 一段话}
16
+
17
+ ## 关键信息
18
+ - {field}: {value}
19
+ - {field}: {value}
20
+
21
+ ## 相关概念
22
+ - [[Concept1]]
23
+ - [[Concept2]]
24
+
25
+ ## 相关实体
26
+ - [[EntityA]] — {关系描述}
27
+ - [[EntityB]] — {关系描述}
28
+
29
+ ---
30
+ *最后更新: {date} | 来源: {url}*
31
+ ```
32
+
33
+ ### 概念页 (Concept)
34
+
35
+ ```markdown
36
+ # {name}
37
+
38
+ **分类**: {methodology | technology | framework | pattern}
39
+
40
+ ## 定义
41
+ {清晰的技术定义,1-3 句话}
42
+
43
+ ## 核心要点
44
+ 1. **Point 1** — 解释
45
+ 2. **Point 2** — 解释
46
+ 3. **Point 3** — 解释
47
+
48
+ ## 与其他概念的关系
49
+ - **父概念**: [[ParentConcept]]
50
+ - **子概念**: [[ChildConcept]]
51
+ - **对比**: [[SimilarConcept]] (差异在于...)
52
+
53
+ ## 实际应用
54
+ - 在 {context} 中,{how it's used}
55
+ - {example from real world}
56
+
57
+ ## 参考
58
+ - [{source_title}]({url})
59
+ ```
60
+
61
+ ### 对比页 (Comparison)
62
+
63
+ ```markdown
64
+ # {A} vs {B}
65
+
66
+ ## 概述
67
+ {一句话说明两者定位差异}
68
+
69
+ ## 对比维度
70
+
71
+ | 维度 | {A} | {B} |
72
+ |------|-----|-----|
73
+ | 定位 | ... | ... |
74
+ | 适用场景 | ... | ... |
75
+ | 优势 | ... | ... |
76
+ | 劣势 | ... | ... |
77
+ | 学习成本 | ... | ... |
78
+ | 生态 | ... | ... |
79
+
80
+ ## 结论
81
+ {什么场景选 A,什么场景选 B}
82
+
83
+ ## 相关
84
+ - [[RelatedEntity1]]
85
+ - [[RelatedConcept1]]
86
+ ```
87
+
88
+ ### 来源页 (Source)
89
+
90
+ ```markdown
91
+ # {title}
92
+
93
+ **原始链接**: {url}
94
+ **作者**: {author}
95
+ **发布日期**: {date}
96
+ **摄取时间**: {ingest_date}
97
+
98
+ ## 摘要
99
+ {AI 生成的 2-3 句摘要}
100
+
101
+ ## 提取的实体
102
+ - [[Entity1]] ({type})
103
+ - [[Entity2]] ({type})
104
+
105
+ ## 涉及的概念
106
+ - [[Concept1]]
107
+ - [[Concept2]]
108
+
109
+ ## 关键观点
110
+ 1. "{quote or key point}"
111
+ 2. "{quote or key point}"
112
+ ```
113
+
114
+ ## 内部数据格式
115
+
116
+ ### .ingest-state.json
117
+
118
+ ```json
119
+ {
120
+ "files": {
121
+ "raw/article-001.md": {
122
+ "mtime": "1740000000",
123
+ "hash": "abc123def456"
124
+ }
125
+ },
126
+ "lastIngestAt": "2026-04-28T10:00:00"
127
+ }
128
+ ```
129
+
130
+ 用途:追踪哪些 raw 文件已被处理,支持增量 ingest。
131
+
132
+ ### graph.json
133
+
134
+ ```json
135
+ {
136
+ "nodes": [
137
+ {"id": "knowflow", "label": "KnowFlow", "type": "project", "size": 15},
138
+ {"id": "rag", "label": "RAG", "type": "concept", "size": 10},
139
+ {"id": "llm-wiki", "label": "LLM Wiki", "type": "concept", "size": 10},
140
+ {"id": "jerry", "label": "Jerry", "type": "person", "size": 5}
141
+ ],
142
+ "edges": [
143
+ {"source": "jerry", "target": "knowflow", "label": "created_by"},
144
+ {"source": "knowflow", "target": "rag", "label": "alternative_to"},
145
+ {"source": "knowflow", "target": "llm-wiki", "label": "implements"},
146
+ {"source": "knowflow", "target": "glm-flash", "label": "uses"}
147
+ ]
148
+ }
149
+ ```
150
+
151
+ ### .bookmark-state.json
152
+
153
+ ```json
154
+ {
155
+ "lastSyncAt": "2026-04-28T10:00:00",
156
+ "lastProcessedId": "18923456789012",
157
+ "stats": {
158
+ "totalBookmarks": 150,
159
+ "processedCount": 130,
160
+ "newThisRun": 5,
161
+ "skippedCount": 15
162
+ }
163
+ }
164
+ ```
165
+
166
+ ## Wiki Link 语法
167
+
168
+ KnowFlow 使用 `[[Name]]` 语法表示内部链接:
169
+
170
+ ```markdown
171
+ // 标准链接
172
+ [[RAG]]
173
+
174
+ // 带显示文本
175
+ [[检索增强生成|RAG]]
176
+
177
+ // 链接自动解析规则:
178
+ // 1. 精确匹配已有页面标题 → 直接链接
179
+ // 2. 模糊匹配(编辑距离 < 3)→ 警告但创建
180
+ // 3. 无匹配 → 创建新页面占位(标记为 stub)
181
+ ```
182
+
183
+ ## 配置文件 (.knowflowrc)
184
+
185
+ ```json
186
+ {
187
+ "wiki": {
188
+ "root": "./wiki",
189
+ "rawDir": "./raw"
190
+ },
191
+ "graph": {
192
+ "output": "./graph/graph.html"
193
+ },
194
+ "health": {
195
+ "minFileSize": 100
196
+ }
197
+ }
198
+ ```
199
+
200
+ 配置必须是有效 JSON,相对路径以 `.knowflowrc` 所在目录为基准。向量索引和查询使用项目根目录 `.env` 中的 `ZHIPUAI_API_KEY`,或同名环境变量。
@@ -0,0 +1,60 @@
1
+ # KnowFlow text-to-graph quickstart
2
+
3
+ This walkthrough is deterministic and does not fetch a URL or require an API key. It demonstrates the real boundary between raw capture and Wiki organization.
4
+
5
+ ## 1. Create a project and capture a note
6
+
7
+ ```bash
8
+ npx knowflow@latest init knowflow-demo
9
+ cd knowflow-demo
10
+ npx knowflow ingest "Linked notes become more useful when concepts point to sources." --source text
11
+ ```
12
+
13
+ If you installed KnowFlow from a source checkout with `npm link`, replace `npx knowflow` with `knowflow` in every command.
14
+
15
+ The note now exists under `raw/web/`. It has **not** been converted into a structured Wiki page.
16
+
17
+ ## 2. Organize one Wiki page
18
+
19
+ Create `wiki/concepts/linked-knowledge.md` with this content:
20
+
21
+ ```markdown
22
+ # Linked knowledge
23
+
24
+ Linked knowledge connects durable concepts to the sources that support them.
25
+
26
+ ## Connections
27
+
28
+ - [[index]]
29
+ - [[sources/capture-example]]
30
+ ```
31
+
32
+ Then create `wiki/sources/capture-example.md`:
33
+
34
+ ```markdown
35
+ # Capture example
36
+
37
+ This source page records the note captured during the KnowFlow quickstart.
38
+
39
+ ## Connections
40
+
41
+ - [[concepts/linked-knowledge]]
42
+ ```
43
+
44
+ This manual step is exactly where an AI agent or custom workflow can read `raw/`, draft pages from the included templates, and ask for review.
45
+
46
+ ## 3. Validate and build the graph
47
+
48
+ ```bash
49
+ npx knowflow health
50
+ npx knowflow status
51
+ npx knowflow graph --no-open
52
+ ```
53
+
54
+ Expected outputs:
55
+
56
+ - `graph/graph.html` — interactive graph viewer
57
+ - `graph/graph.json` — graph data for other tools
58
+ - `graph/.graph-state.json` — graph build state
59
+
60
+ Open `graph/graph.html` in a browser. The viewer loads vis-network from a CDN, so the first view requires a network connection.
package/package.json ADDED
@@ -0,0 +1,57 @@
1
+ {
2
+ "name": "@jerryjiao/knowflow",
3
+ "version": "0.3.0",
4
+ "description": "Agent-native Markdown workspace for raw capture, linked wikis, knowledge graphs, and semantic search",
5
+ "type": "module",
6
+ "bin": {
7
+ "knowflow": "./bin/knowflow.js"
8
+ },
9
+ "files": [
10
+ "bin/",
11
+ "scripts/",
12
+ "templates/",
13
+ "docs/",
14
+ "!docs/launch",
15
+ "examples/",
16
+ "README.md",
17
+ "README.zh-CN.md",
18
+ "CONTRIBUTING.md",
19
+ "SECURITY.md",
20
+ "CHANGELOG.md",
21
+ "LICENSE"
22
+ ],
23
+ "scripts": {
24
+ "knowflow": "node bin/knowflow.js",
25
+ "test": "node --test",
26
+ "check": "node --check bin/knowflow.js && node --check scripts/batch-ingest.cjs && node --check scripts/enrich-wiki.js && node --check scripts/vector-store.mjs"
27
+ },
28
+ "repository": {
29
+ "type": "git",
30
+ "url": "git+https://github.com/jerryjiao/knowflow.git"
31
+ },
32
+ "homepage": "https://github.com/jerryjiao/knowflow#readme",
33
+ "bugs": {
34
+ "url": "https://github.com/jerryjiao/knowflow/issues"
35
+ },
36
+ "dependencies": {
37
+ "chalk": "^5.3.0",
38
+ "commander": "^12.1.0"
39
+ },
40
+ "engines": {
41
+ "node": ">=18"
42
+ },
43
+ "keywords": [
44
+ "ai",
45
+ "knowledge-base",
46
+ "knowledge-graph",
47
+ "knowledge-management",
48
+ "personal-knowledge-management",
49
+ "markdown",
50
+ "ai-agent",
51
+ "wiki",
52
+ "llm",
53
+ "rag",
54
+ "cli"
55
+ ],
56
+ "license": "MIT"
57
+ }