Skip to content

Instantly share code, notes, and snippets.

@karpathy
Created April 4, 2026 16:25
Show Gist options
  • Select an option

  • Save karpathy/442a6bf555914893e9891c11519de94f to your computer and use it in GitHub Desktop.

Select an option

Save karpathy/442a6bf555914893e9891c11519de94f to your computer and use it in GitHub Desktop.
llm-wiki

LLM Wiki

A pattern for building personal knowledge bases using LLMs.

This is an idea file, it is designed to be copy pasted to your own LLM Agent (e.g. OpenAI Codex, Claude Code, OpenCode / Pi, or etc.). Its goal is to communicate the high level idea, but your agent will build out the specifics in collaboration with you.

The core idea

Most people's experience with LLMs and documents looks like RAG: you upload a collection of files, the LLM retrieves relevant chunks at query time, and generates an answer. This works, but the LLM is rediscovering knowledge from scratch on every question. There's no accumulation. Ask a subtle question that requires synthesizing five documents, and the LLM has to find and piece together the relevant fragments every time. Nothing is built up. NotebookLM, ChatGPT file uploads, and most RAG systems work this way.

The idea here is different. Instead of just retrieving from raw documents at query time, the LLM incrementally builds and maintains a persistent wiki — a structured, interlinked collection of markdown files that sits between you and the raw sources. When you add a new source, the LLM doesn't just index it for later retrieval. It reads it, extracts the key information, and integrates it into the existing wiki — updating entity pages, revising topic summaries, noting where new data contradicts old claims, strengthening or challenging the evolving synthesis. The knowledge is compiled once and then kept current, not re-derived on every query.

This is the key difference: the wiki is a persistent, compounding artifact. The cross-references are already there. The contradictions have already been flagged. The synthesis already reflects everything you've read. The wiki keeps getting richer with every source you add and every question you ask.

You never (or rarely) write the wiki yourself — the LLM writes and maintains all of it. You're in charge of sourcing, exploration, and asking the right questions. The LLM does all the grunt work — the summarizing, cross-referencing, filing, and bookkeeping that makes a knowledge base actually useful over time. In practice, I have the LLM agent open on one side and Obsidian open on the other. The LLM makes edits based on our conversation, and I browse the results in real time — following links, checking the graph view, reading the updated pages. Obsidian is the IDE; the LLM is the programmer; the wiki is the codebase.

This can apply to a lot of different contexts. A few examples:

  • Personal: tracking your own goals, health, psychology, self-improvement — filing journal entries, articles, podcast notes, and building up a structured picture of yourself over time.
  • Research: going deep on a topic over weeks or months — reading papers, articles, reports, and incrementally building a comprehensive wiki with an evolving thesis.
  • Reading a book: filing each chapter as you go, building out pages for characters, themes, plot threads, and how they connect. By the end you have a rich companion wiki. Think of fan wikis like Tolkien Gateway — thousands of interlinked pages covering characters, places, events, languages, built by a community of volunteers over years. You could build something like that personally as you read, with the LLM doing all the cross-referencing and maintenance.
  • Business/team: an internal wiki maintained by LLMs, fed by Slack threads, meeting transcripts, project documents, customer calls. Possibly with humans in the loop reviewing updates. The wiki stays current because the LLM does the maintenance that no one on the team wants to do.
  • Competitive analysis, due diligence, trip planning, course notes, hobby deep-dives — anything where you're accumulating knowledge over time and want it organized rather than scattered.

Architecture

There are three layers:

Raw sources — your curated collection of source documents. Articles, papers, images, data files. These are immutable — the LLM reads from them but never modifies them. This is your source of truth.

The wiki — a directory of LLM-generated markdown files. Summaries, entity pages, concept pages, comparisons, an overview, a synthesis. The LLM owns this layer entirely. It creates pages, updates them when new sources arrive, maintains cross-references, and keeps everything consistent. You read it; the LLM writes it.

The schema — a document (e.g. CLAUDE.md for Claude Code or AGENTS.md for Codex) that tells the LLM how the wiki is structured, what the conventions are, and what workflows to follow when ingesting sources, answering questions, or maintaining the wiki. This is the key configuration file — it's what makes the LLM a disciplined wiki maintainer rather than a generic chatbot. You and the LLM co-evolve this over time as you figure out what works for your domain.

Operations

Ingest. You drop a new source into the raw collection and tell the LLM to process it. An example flow: the LLM reads the source, discusses key takeaways with you, writes a summary page in the wiki, updates the index, updates relevant entity and concept pages across the wiki, and appends an entry to the log. A single source might touch 10-15 wiki pages. Personally I prefer to ingest sources one at a time and stay involved — I read the summaries, check the updates, and guide the LLM on what to emphasize. But you could also batch-ingest many sources at once with less supervision. It's up to you to develop the workflow that fits your style and document it in the schema for future sessions.

Query. You ask questions against the wiki. The LLM searches for relevant pages, reads them, and synthesizes an answer with citations. Answers can take different forms depending on the question — a markdown page, a comparison table, a slide deck (Marp), a chart (matplotlib), a canvas. The important insight: good answers can be filed back into the wiki as new pages. A comparison you asked for, an analysis, a connection you discovered — these are valuable and shouldn't disappear into chat history. This way your explorations compound in the knowledge base just like ingested sources do.

Lint. Periodically, ask the LLM to health-check the wiki. Look for: contradictions between pages, stale claims that newer sources have superseded, orphan pages with no inbound links, important concepts mentioned but lacking their own page, missing cross-references, data gaps that could be filled with a web search. The LLM is good at suggesting new questions to investigate and new sources to look for. This keeps the wiki healthy as it grows.

Indexing and logging

Two special files help the LLM (and you) navigate the wiki as it grows. They serve different purposes:

index.md is content-oriented. It's a catalog of everything in the wiki — each page listed with a link, a one-line summary, and optionally metadata like date or source count. Organized by category (entities, concepts, sources, etc.). The LLM updates it on every ingest. When answering a query, the LLM reads the index first to find relevant pages, then drills into them. This works surprisingly well at moderate scale (~100 sources, ~hundreds of pages) and avoids the need for embedding-based RAG infrastructure.

log.md is chronological. It's an append-only record of what happened and when — ingests, queries, lint passes. A useful tip: if each entry starts with a consistent prefix (e.g. ## [2026-04-02] ingest | Article Title), the log becomes parseable with simple unix tools — grep "^## \[" log.md | tail -5 gives you the last 5 entries. The log gives you a timeline of the wiki's evolution and helps the LLM understand what's been done recently.

Optional: CLI tools

At some point you may want to build small tools that help the LLM operate on the wiki more efficiently. A search engine over the wiki pages is the most obvious one — at small scale the index file is enough, but as the wiki grows you want proper search. qmd is a good option: it's a local search engine for markdown files with hybrid BM25/vector search and LLM re-ranking, all on-device. It has both a CLI (so the LLM can shell out to it) and an MCP server (so the LLM can use it as a native tool). You could also build something simpler yourself — the LLM can help you vibe-code a naive search script as the need arises.

Tips and tricks

  • Obsidian Web Clipper is a browser extension that converts web articles to markdown. Very useful for quickly getting sources into your raw collection.
  • Download images locally. In Obsidian Settings → Files and links, set "Attachment folder path" to a fixed directory (e.g. raw/assets/). Then in Settings → Hotkeys, search for "Download" to find "Download attachments for current file" and bind it to a hotkey (e.g. Ctrl+Shift+D). After clipping an article, hit the hotkey and all images get downloaded to local disk. This is optional but useful — it lets the LLM view and reference images directly instead of relying on URLs that may break. Note that LLMs can't natively read markdown with inline images in one pass — the workaround is to have the LLM read the text first, then view some or all of the referenced images separately to gain additional context. It's a bit clunky but works well enough.
  • Obsidian's graph view is the best way to see the shape of your wiki — what's connected to what, which pages are hubs, which are orphans.
  • Marp is a markdown-based slide deck format. Obsidian has a plugin for it. Useful for generating presentations directly from wiki content.
  • Dataview is an Obsidian plugin that runs queries over page frontmatter. If your LLM adds YAML frontmatter to wiki pages (tags, dates, source counts), Dataview can generate dynamic tables and lists.
  • The wiki is just a git repo of markdown files. You get version history, branching, and collaboration for free.

Why this works

The tedious part of maintaining a knowledge base is not the reading or the thinking — it's the bookkeeping. Updating cross-references, keeping summaries current, noting when new data contradicts old claims, maintaining consistency across dozens of pages. Humans abandon wikis because the maintenance burden grows faster than the value. LLMs don't get bored, don't forget to update a cross-reference, and can touch 15 files in one pass. The wiki stays maintained because the cost of maintenance is near zero.

The human's job is to curate sources, direct the analysis, ask good questions, and think about what it all means. The LLM's job is everything else.

The idea is related in spirit to Vannevar Bush's Memex (1945) — a personal, curated knowledge store with associative trails between documents. Bush's vision was closer to this than to what the web became: private, actively curated, with the connections between documents as valuable as the documents themselves. The part he couldn't solve was who does the maintenance. The LLM handles that.

Note

This document is intentionally abstract. It describes the idea, not a specific implementation. The exact directory structure, the schema conventions, the page formats, the tooling — all of that will depend on your domain, your preferences, and your LLM of choice. Everything mentioned above is optional and modular — pick what's useful, ignore what isn't. For example: your sources might be text-only, so you don't need image handling at all. Your wiki might be small enough that the index file is all you need, no search engine required. You might not care about slide decks and just want markdown pages. You might want a completely different set of output formats. The right way to use this is to share it with your LLM agent and work together to instantiate a version that fits your needs. The document's only job is to communicate the pattern. Your LLM can figure out the rest.

@Shilren
Copy link
Copy Markdown

Shilren commented Jun 1, 2026

Karpathy说的「别每次都去翻原始资料,而是让 LLM 一点点维护一个长期的 wiki」这句话,真的点醒了我一个一直没想通的问题。

说说我照着这个思路做的东西。我遇到的问题:我的工作经历到处都是 —— 项目复盘、周报、聊天记录、还有一些只在脑子里。每次写简历或者准备面试,都得重新翻一遍、再喂给 AI,又费钱又慢还容易漏东西。最烦的是,同一个数字在简历里写"22"、在面试稿里却记成"23",因为两份是分开写的。我后来想明白:大多数人只是把 AI 当成"帮我改一次"的工具,但其实更值钱的是有一个能反复用、数据只有一个出处的知识库 —— 这就是你说的 LLM Wiki。

我做的东西 —— interview-doc-agent (https://github.com/Shilren/interview-doc-agent),一个开源,%E4%B8%80%E4%B8%AA%E5%BC%80%E6%BA%90) skill(MIT),几乎一对一对应你的三层:

materials/ → 原始素材,什么格式都行,粘进来就好
经历库/ → wiki 层,AI 把每个项目整理成一份面试能直接用的档案(一句话 → 背景/问题/做法 → 所有数据都留住 → 可迁移的亮点)
index.md → 索引,先读它找到相关的 1-2 篇,而不是全部加载
SKILL.md → schema,行为说明(什么时候用、按什么步骤、有哪些硬规则,比如"绝不编数字")
我最想补充的一点 —— 到底用上下文还是 RAG,本质上是个量级问题。 很多"知识库 + AI"的项目张口就上 RAG,但我觉得这往往是过度设计了。我自己理出来的判断标准是:

小于约 5万–10万 token(大概 150–200 页):上下文(LLM Wiki)完胜 —— 检索可靠性 100%(不会漏匹配、也不会因为分块把语义切断)、几乎不需要任何基建(一个结构清晰的 Markdown 就够,不用向量库、不用嵌入、不用分块)、而且能对全局直接推理,而不是把几个零散片段拼起来
几百万 token 以上:只能用 RAG —— 塞不进上下文,检索是唯一能扩展的办法
介于两者之间 / 生产系统:混合 —— 把最核心稳定的知识放进上下文,把海量、动态的数据交给 RAG
一份个人经历库整理完也就几千到两万 token,远在这条线以下,所以上 RAG 纯属增加负担、还把可靠性变差了。再澄清一点:我那个 index.md 也不是 RAG —— 它不做向量匹配、不分块,只是在经历变多以后让 AI 少读几个完整文件而已;就算全读进去也放得下,索引只是个优化,不是检索系统。现在主流模型上下文都到 200k 甚至 100 万+ token 了,纯上下文这条路的上限只会越来越高。

只要在这个量级以下,LLM Wiki 比 RAG 又简单又可靠。

@skyllwt
Copy link
Copy Markdown

skyllwt commented Jun 2, 2026

Love this LLM-Wiki idea? We built a full open-source system on it → AutoSci

Come and enjoy: https://github.com/skyllwt/AutoSci

autosci_fig1_v1-第 15 页 drawio png

Karpathy's pattern (immutable raw/ → an LLM-compiled wiki/ → a CLAUDE.md schema) is the exact foundation of AutoSci — an agent that turns the wiki into a research memory and then does autonomous science on top of it. All on Claude Code:

  • 📚 Ingest papers into a cross-linked wiki of concept/method/idea pages ([[wikilinks]], contradiction edges — the LLM-Wiki, fully realized)
  • 💡 Ideate → experiment → write: it reads its own memory to generate ideas, design + run experiments, draft the paper, and handle rebuttals
  • 🧬 Self-evolving memory: between projects it consolidates, re-weights, and re-links the wiki (a "sleep" phase)
  • 🕸️ Multi-agent DAGs for the hard reasoning steps

We've already used it to write 3 papers end-to-end. Fully open (MIT).

⭐ If this is where you want LLM-Wikis to go, a star genuinely helps us! and we welcome issues/PRs/Contributors
👉 https://github.com/skyllwt/AutoSci
📄 Paper: https://arxiv.org/abs/2605.31468

Demo: 【北大做了一个会自我进化的科研 Agent:AutoSci】 https://www.bilibili.com/video/BV19gVg6pEk6/?share_source=copy_web&vd_source=338de971cb27f42aaaf5d8bfdeed04b3

截图 2026-06-02 09-03-07

RED: 北大做了一个“越做科研越聪明”的AI科学家 北大团队... http://xhslink.com/o/2clEkgugEPw
复制后打开【小红书】查看笔记!

@Z-M-Huang
Copy link
Copy Markdown

Dense-Mem: memory beyond RAG

dense-mem-memory-beyond-rag

I built an open-source MCP memory server called Dense-Mem:

https://github.com/markhuangai/dense-mem

I built an open-source MCP memory server called Dense-Mem:

https://github.com/markhuangai/dense-mem

The idea I am trying to explore is that RAG is very useful for retrieval, but durable AI memory may need more than vector search alone.

In daily LLM workflows, the hard problems are often not just "find a similar chunk." They are questions like:

  • What did the user actually say?
  • Is this evidence, a proposed claim, or an accepted fact?
  • Is there a newer fact that supersedes the old one?
  • Are two memories in conflict?
  • What source supports this answer?
  • Can the same memory be reused across different AI tools?

So Dense-Mem separates the host LLM from the memory layer:

  • the host LLM handles conversation and judgment
  • Dense-Mem stores evidence, typed claims, accepted facts, provenance, conflicts, embeddings, and graph recall
  • MCP clients can recall the same durable memory instead of rebuilding context from scratch every session

I wrote more about the motivation here:

https://markhuang.ai/blog/ai-memory-beyond-rag

And I made a hosted demo so people can try it without self-hosting:

https://markhuang.ai/blog/dense-mem-hosted-demo-test-instance

I do not want to overclaim that this "solves memory." I am mostly curious whether this architecture feels useful, overbuilt, or missing something important.

If anyone has thoughts, I would especially appreciate critique on:

  1. Does the memory-server / host-LLM boundary make sense?
  2. Is graph-backed memory a useful abstraction here, or should this remain simpler?
  3. What evaluation would best show whether this improves accuracy in real daily LLM workflows?
  4. What failure modes should I test before claiming this direction is useful?

Thanks for reading. I would genuinely value technical pushback.

@mikhashev
Copy link
Copy Markdown

Follow-up on our knowledge-as-weights post. Last time we asked: what if a personal model could learn and grow with you -- encoding confirmed knowledge directly in weights, adding new facts as you learn them, no RAG needed? Two weeks and 52 experiments later, we have a partial answer: below ~10M parameters, we could not make knowledge-in-weights work via any mechanism we tested -- LoRA injection, test-time training, or architecture changes. Here's the journey.

The vision: We're building DPC Messenger -- peer-to-peer infrastructure for human-AI co-evolution. A space where people and AI grow together. The target (knowledge-in-weights) architecture (designed, not yet implemented) uses continual LoRA adapters per knowledge cluster, with a perceptron router for O(1) adapter selection at inference. Three knowledge types are planned: static facts, dynamic state, and predictive hypotheses -- each with their own lifecycle in weights. The model would learn and grow as the person confirms new knowledge -- not one-shot injection, but continual learning. What's built today: the knowledge graph, the training pipeline, and the diagnostic tooling. What's not built yet: the adapter routing, the knowledge-type lifecycle, and the continual learning loop itself. But first we needed to know: how small can the knowledge model be? This post maps the lower bound.

Phase 1: "Can a small model learn our domain?" (11 experiments)
We adapted the autoresearch framework (based on karpathy/nanoGPT) with a custom training pipeline and experiment workflow for domain-specific knowledge encoding. All 52 experiments are logged with full reproducibility metadata (hyperparameters, timings, per-epoch metrics). We trained on a personal knowledge corpus -- 278K documents (~7.5M tokens) of domain-specific triples from a knowledge graph plus natural text. Question: can a tiny model reach reasonable perplexity on structured knowledge?

TinyStories baseline: val_bpb 1.221. Our corpus: 1.682. The domain gap is real -- structured triples are harder than simple narratives. We tried dropout (no effect), smaller models (worse at same compute budget), larger models (overfit). The floor on our corpus is ~0.98 val_bpb, regardless of architecture (confirmed across two independent architectures: 4L/256d at 3.7M params and 8L/128d at 2.0M params). Width matters more than depth at fixed compute -- 4L x 256d beats 8L x 128d consistently. Seed variance dominated architectural differences in our measurements. The model learns the domain, but the data ceiling is immutable at this corpus size.

Phase 2: "Does architecture matter?" (21 experiments)
Systematic sweep of 5 architectural knobs: MLP ratio, GQA, value embeddings, RMSNorm, weight tying. Answer: mostly noise at this scale. One exception -- weight tying saves 50% of parameters with zero quality loss, giving us our final 3.7M param model. BERT-style encoder tested at matched scale (~30M params) -- decoder beats encoder by +1.24 bpb. Value embeddings are load-bearing (removing them costs +0.116 bpb at matched parameter count). The take-away: at sub-10M scale, architecture is second-order. The first-order constraints are data and compute.

Phase 3: "Can we inject knowledge via gradients?" (600 combinations)
Test-time training (TTT) sweep: 600 combinations of learning rate, steps, and fact count on a 37M param model. Result: 0/600 newly recalled facts. The model overfits on injection token patterns while loss drops to 0.01. It memorizes the surface form of injection text but cannot extract semantic subject-predicate-object associations. Via teacher forcing, entity accuracy is 19.4% -- facts are weakly present in weights, but free recall fails completely.

Phase 4: "Can LoRA inject knowledge?" (4 experiments + diagnostics)
This is where we expected success. Schulman et al. (2025) show LoRA injection works reliably when per-token probability exceeds p=0.5 on 7B+ models. We tried it at 3.7M.

Config LoRA target Rank Params injected LR top-1 recall top-10 collapse
MLP-only c_fc, c_proj 16 164K (4.5% of model) 1e-4 0.49% -> 0% by epoch 3 epoch 6
MLP-only c_fc, c_proj 16 164K 1e-3 0.49% -> 0% by epoch 1 epoch 2
Attn-only c_q, c_v 16 65K (1.8% of model) 1e-4 0.49% -> 0% by epoch 4 by epoch 9

Loss decreased monotonically in every run while recall died. The model learned to minimize loss on injection text via existing non-factual patterns -- not by encoding new facts.

The diagnostic that explained everything:
We built a 5-metric diagnostic pipeline (D1-D5) and measured per-token probability p(fact) -- the model's confidence on correct factual completions. Result: zero tokens above p=0.5 even BEFORE LoRA training. Out of 1,214 injected facts: max p(fact) = 0.29, mean = 0.008. Post-LoRA training: max dropped to 0.02, mean to 0.002.

Schulman et al. (2025) show LoRA injection works reliably above the p=0.5 threshold. Our model's ceiling is ~60x below that. This rules out "LoRA optimization problem" and confirms "structural capacity problem" -- the model cannot encode facts at sufficient probability for stable recall. No amount of adapter tuning fixes this.

Additional diagnostic: base model gradients are 600-5000x larger than LoRA gradients (ratio grows as training progresses). The adapter barely influences the model despite measurable loss reduction.

Why existing literature didn't predict this:
Three recent LoRA knowledge-injection papers (Schulman 2025, "Understanding LoRA as Knowledge Memory" ICML 2026, "LoRA Rank Trade-offs" Dec 2025) all test on 7B+ parameters -- three orders of magnitude larger than our model. At 4 layers, MLP-only LoRA perturbs 50% of the model; attention-only perturbs 18%. At 24+ layers those numbers drop to ~4% and ~1.5% respectively. LoRA assumes deep enough models that adapters are small perturbations -- that assumption breaks below ~10M parameters.

What's next:
Scaling up to 10-50M parameters (12-16 layers) where LoRA perturbation drops below 5%. Running the same D1-D5 diagnostic pipeline on each checkpoint to find where p(fact) crosses the 0.5 threshold. If it does, we have the minimum viable model size for personal LoRA knowledge injection. If it doesn't, the knowledge-as-weights hypothesis needs a fundamentally different injection mechanism at this scale.

Hardware: All experiments on a single RTX 3060 12GB (Xeon E3-1240 V2). Full scaling-laws grid (~9 configs) runs in ~1.5 hours. LoRA experiments + diagnostics: ~2 hours. This is entirely reproducible on consumer hardware.

@MuhammadSaqlainAslam
Copy link
Copy Markdown

MuhammadSaqlainAslam commented Jun 3, 2026

Hi Andrej — your gist inspired this project at the AI Research Center, Hon Hai Research Institute (Foxconn).
🌐 Live demo: https://muhammadsaqlainaslam.github.io/my-llm-wiki
📦 Repo: https://github.com/MuhammadSaqlainAslam/my-llm-wiki
🏛️ Institute: https://hhri.foxconn.com/en
What we built on top of your pattern:
🤖 Agentic ingestion — one command searches arXiv, GitHub, blogs, and YouTube transcripts, generates structured notes, and deploys automatically:
python3 agent.py topic "Mamba 2 SSM improvements"
📚 Citation intelligence — every paper shows its total citations plus the top 10 most-cited papers that reference it, tracing the full intellectual thread from the 2017 Transformer through 2025 inference optimization.
🌐 Interactive web demo — browse 150+ notes, full-text search with Ctrl+F-style match navigation, side-by-side paper comparison, D3 knowledge graph where node size = citation count, and a timeline from 2017→2026. Fully mobile responsive.
🔗 Deep cross-linking — every note shows backlinks. "Attention is All You Need" has 46 backlinks — the most referenced paper in the wiki, as expected.
Coverage: Transformer → FlashAttention → S4 → Mamba → Mamba-2 → Mamba-3 → xLSTM → RWKV → RetNet → Griffin → Speculative Decoding → KV Cache → DeepSeek-V4 · 50+ concept glossary stubs
Stack: Claude API (Vertex AI) · PyMuPDF · D3.js · KaTeX · GitHub Pages · Obsidian + Dataview

@kytmanov
Copy link
Copy Markdown

kytmanov commented Jun 3, 2026

Synto v0.5.0 is out.

https://github.com/kytmanov/synto

  • Main addition: per-role providers. Run each model where it makes sense - small fast model on local Ollama, heavy writing model on a cloud endpoint. Each role gets its own provider, connection, and key. synto setup walks you through the split.

Also new in v0.5:

  • rename a concept everywhere: synto concept rename OLD NEW moves the article, repoints every inbound link, and migrates the state DB.
  • per-model knobs: context size, temperature, thinking on/off. Thinking models (Qwen 3.5, DeepSeek-R1) no longer time out on ingest.
  • Anthropic-compatible API support, on top of OpenAI-compatible - point any role at Kimi and similar endpoints.

Same shape as before:

  • works with local LLMs
  • great with Ollama and LM Studio
  • plain Markdown
  • Obsidian-friendly
  • no vector DB
  • no cloud required
  • multi-language

Star it if you want to support local-first AI tools. Fork it if you want to build on it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment