LLM Knowledge Bases
Andrej Karpathy X Post · 共读学习笔记
左栏为原文与中文理解,右栏为本次共读对话沉淀的学习笔记。
Post(主帖)
LLM Knowledge Bases Something I'm finding very useful recently: using LLMs to build personal knowledge bases for various topics of research interest.
LLM Knowledge Bases。最近我发现一件很有用的事:用 LLM 为各种研究兴趣主题构建个人知识库。
In this way, a large fraction of my recent token throughput is going less into manipulating code, and more into manipulating knowledge (stored as markdown and images).
这样一来,我最近大量的 token 消耗,不再主要用于处理代码,而是更多用于处理知识。这些知识以 Markdown 和图片的形式存储。
The latest LLMs are quite good at it. So:
最新的 LLM 已经很擅长做这件事。所以:
Data ingest(资料摄入)
Data ingest: I index source documents (articles, papers, repos, datasets, images, etc.) into a raw/ directory, then I use an LLM to incrementally "compile" a wiki, which is just a collection of .md files in a directory structure.
资料摄入:我把源文档索引到一个 raw/ 目录里,包括文章、论文、代码仓库、数据集、图片等。然后我用 LLM 增量地“编译”一个 wiki。这个 wiki 本质上就是一个目录结构里的若干 .md 文件集合。
The wiki includes summaries of all the data in raw/, backlinks, and then it categorizes data into concepts, writes articles for them, and links them all.
这个 wiki 包含 raw/ 里所有资料的摘要、反向链接;然后它会把资料归类到不同概念下,为这些概念写文章,并把它们全部链接起来。
To convert web articles into.md files I like to use the Obsidian Web Clipper extension, and then I also use a hotkey to download all the related images to local so that my LLM can easily reference them.
为了把网页文章转换成 Markdown 文件,我喜欢使用 Obsidian Web Clipper 扩展;同时我也用一个快捷键把相关图片全部下载到本地,这样我的 LLM 就能方便地引用它们。
IDE(Obsidian 作为前端)
I use Obsidian as the IDE "frontend" where I can view the raw data, the the compiled wiki, and the derived visualizations.
我把 Obsidian 当作 IDE 的“前端”来使用,在那里查看原始数据、编译后的 wiki,以及派生出来的可视化结果。
Important to note that the LLM writes and maintains all of the data of the wiki, I rarely touch it directly.
需要注意的是,wiki 的所有数据都是由 LLM 写入和维护的,我很少直接去手动编辑它。
I've played with a few Obsidian plugins to render and view data in other ways (e.g. Marp for slides).
我也尝试过一些 Obsidian 插件,用其他方式渲染和查看数据,比如用 Marp 生成幻灯片。
Q&A(基于 wiki 提问)
Where things get interesting is that once your wiki is big enough (e.g. mine on some recent research is ~100 articles and ~400K words), you can ask your LLM agent all kinds of complex questions against the wiki, and it will go off, research the answers, etc.
真正有意思的地方在于,一旦你的 wiki 足够大,比如我最近某个研究主题的 wiki 大约有 100 篇文章、40 万词,你就可以基于这个 wiki 向 LLM agent 提各种复杂问题。它会自己去研究答案。
I thought I had to reach for fancy RAG, but the LLM has been pretty good about auto-maintaining index files and brief summaries of all the documents and it reads all the important related data fairly easily at this ~small scale.
我原本以为必须使用复杂的 RAG,但在这种小规模下,LLM 已经很擅长自动维护索引文件和所有文档的简短摘要,也能相当轻松地读取所有重要的相关数据。
Output(输出再归档)
Instead of getting answers in text/terminal, I like to have it render markdown files for me, or slide shows (Marp format), or matplotlib images, all of which I then view again in Obsidian.
我不喜欢只在文本或终端里得到答案。我更喜欢让它为我渲染 Markdown 文件、幻灯片(Marp 格式)或 matplotlib 图片,然后我再在 Obsidian 里查看这些结果。
You can imagine many other visual output formats depending on the query.
根据不同的问题,你可以想象出很多其他可视化输出格式。
Often, I end up "filing" the outputs back into the wiki to enhance it for further queries.
很多时候,我最终会把这些输出“归档”回 wiki,从而增强它,方便之后继续提问。
So my own explorations and queries always "add up" in the knowledge base.
所以,我自己的探索和提问总是会在知识库里累积起来。
Linting(健康检查与清理)
I've run some LLM "health checks" over the wiki to e.g. find inconsistent data, impute missing data (with web searchers), find interesting connections for new article candidates, etc., to incrementally clean up the wiki and enhance its overall data integrity.
我会对 wiki 运行一些 LLM “健康检查”。例如,找出不一致的数据;用网络搜索工具补全缺失数据;发现一些有意思的关联,作为新文章候选;等等。这样可以增量清理 wiki,并提升整体数据完整性。
The LLMs are quite good at suggesting further questions to ask and look into.
LLM 也很擅长建议下一步应该提出和深入研究的问题。
Extra tools(额外工具)
I find myself developing additional tools to process the data, e.g. I vibe coded a small and naive search engine over the wiki, which I both use directly (in a web ui), but more often I want to hand it off to an LLM via CLI as a tool for larger queries.
我发现自己会开发额外工具来处理这些数据。例如,我随手写了一个小而简单的 wiki 搜索引擎。我既会通过 Web UI 直接使用它,但更多时候,我想通过 CLI 把它交给 LLM,让它在处理更大的查询时作为工具使用。
Further explorations(进一步探索)
As the repo grows, the natural desire is to also think about synthetic data generation + finetuning to have your LLM "know" the data in its weights instead of just context windows.
随着这个仓库越来越大,一个自然的想法是进一步考虑合成数据生成和微调,让你的 LLM 把这些数据“知道”在它的模型权重里,而不是只依赖上下文窗口。
TLDR(总结)
raw data from a given number of sources is collected, then compiled by an LLM into a.md wiki, then operated on by various CLIs by the LLM to do Q&A and to incrementally enhance the wiki, and all of it viewable in Obsidian.
从若干来源收集原始数据,然后由 LLM 编译成 Markdown wiki;接着 LLM 通过各种 CLI 工具对这个 wiki 进行操作,用于问答和持续增强 wiki;所有这些内容都可以在 Obsidian 里查看。
You rarely ever write or edit the wiki manually, it's the domain of the LLM.
你很少手动撰写或编辑这个 wiki。它是 LLM 的工作领域。
I think there is room here for an incredible new product instead of a hacky collection of scripts.
我认为这里有机会诞生一个非常出色的新产品,而不只是一些粗糙脚本的拼凑。
延伸:如何迁移到你的工作 wiki
A work wiki is not only a place to store knowledge. It is a system that lets your agent understand what you are doing, why it matters, what has already been decided, and what should not be re-discussed from scratch.
工作 wiki 不只是存知识的地方。它是一个让 agent 理解你正在做什么、为什么做、哪些结论已经成立、哪些问题不要从零重复讨论的系统。
| Karpathy 的知识库 | 你的工作 wiki 可对应为 |
|---|---|
raw/ source documents |
会议逐字稿、聊天记录、GSC 导出、repo review、模型资料、截图、链接 |
| compiled wiki | 项目页、模型页、概念页、工作流页、决策记录、复盘页 |
| Q&A over wiki | 让 agent 基于历史事实回答“我们为什么这么判断”“下一步该做什么” |
| filing outputs back | 把每次分析、报告、策略判断、复盘重新保存回 wiki |
Minimum viable structure: current context, active projects, agent sync rules, raw evidence, sources, concepts, objects, workflows, outputs, and decisions.
最小可行结构可以是:当前上下文、活跃项目、Agent 同步规则、原始证据、来源摘要、概念、对象、工作流、输出和决策记录。