Most LLM wiki setups I see pick up a vector database on day two.
I understand why. Karpathy's LLM Wiki pattern — raw sources stay untouched, the model maintains linked Markdown pages, answers come back with citations — sounds like a retrieval problem, and retrieval has meant embeddings for a few years now. So people chunk the wiki, embed the chunks, and ask an index to find "similar" passages.
This week's feed was doing something older, and it worked well enough that I wanted a version I could unit-test.
- An Obsidian plugin for Karpathy's LLM Wiki was being passed around that uses lexical search plus PageRank over
[[wiki-links]]instead of chunking notes into a vector database. Source notes stay untouched; answers cite their pages. - A widely circulated post described a loop that scores every note in a vault before the model ever loads it, built on the same gist and a plain Zettelkasten folder.
- People have been describing the gist itself as a local memory layer on plain Markdown, with review-gated writes and no LLM in the storage layer, meant to work across several coding tools — Claude Code, Codex, Cursor, Zed.
- Notion also announced a "shared brain" for teams and AI agents. Shared context is the useful part. The risk is that context living only inside one product's agent layer.
Same idea, four times: the wiki is already a graph. Rank the links, search the text, cite the page. You do not need a second database to do that at the scale Karpathy was talking about — roughly a hundred sources and a few hundred pages.
So this post builds the boring local version: a ~380-line, stdlib-only Python script called wiki_rank.py. It reads a Markdown wiki, builds a link graph, ranks pages with PageRank, scores a query with BM25, and combines the two. It also lints the graph: dangling links, orphans, stale pages, dead ends, and compiled pages with no sources: in the frontmatter. It never writes to the wiki. A human still owns what gets fixed.
Why a vector database is the wrong default
A vector index is the right tool for a large, changing corpus you do not control — tickets, PDFs, chat logs. An LLM wiki is the opposite of that. The pages are already short, already interlinked, already written so a model can follow them. Chunking them throws the links away and then tries to recover the structure with cosine similarity.
Karpathy noted that an index.md catalog alone works at moderate scale. A link graph is that catalog, just computable. PageRank tells you which pages the wiki itself treats as important. Lexical search tells you which pages actually use the words in the question. Combined, they answer the only question that matters: which page should the agent read first, and what raw source does that page cite?
The number I care about is not recall@10 on a benchmark. It is this: when I ask "how do we rotate SSO certificates," does the agent open the SSO certificate rotation page, or the TLS certificate page, or the on-call rotation page?
The sample wiki
The fixture in this post is made up: 23 wiki pages and 16 raw sources for a fictional team at a fictional company I called Trestle. I seeded it with the messy stuff real wikis have.
- A well-linked identity cluster:
sso.md,sso-certificates.md,sso-outage.md,scim.md. - A popular but off-topic hub.
on-call.mdhas the highest PageRank in the graph. Several incident pages point at it. It should not win a question about certificates. - A close lexical distractor.
certificates.mdis about TLS certificates for trestle.app, which also rotate. It talks about certificates and rotation, but not about SSO. - Three pages that link to
[[Refund Policy]], a page nobody ever wrote. - An orphan,
old-zoom-setup.md, that nobody has linked to since the team moved off Zoom. - A stale roster (
on-call-schedule.md, last updated August 2). - A vendor list with no outbound links.
- A data-retention page that states legal-sounding retention periods and cites no source.
Raw sources live in sources/ and are never ranked. Wiki pages may cite them in frontmatter. That is the Karpathy split: the model (or a person) compiles the wiki; the sources stay read-only.
How ranking works
Two scores, then a weighted sum.
PageRank over the [[wiki-link]] graph, damping 0.85, 40 iterations. Dangling nodes (pages with no outbound links) distribute their mass evenly, same as the original paper. I resolve links against both the filename stem and a slug of the page title, so [[SSO certificate rotation]] hits wiki/sso-certificates.md.
BM25 over the page title (boosted 3x) and the visible body text. Wiki-link aliases are what get tokenized, not the hidden target, so a "see also" link does not smuggle terms into a page that never discusses them. There is a coordination factor: a page that only matches two of the three query terms cannot beat a page that matches all three just because it is short.
Combined score:
score = alpha * PageRank_norm + (1 - alpha) * BM25_norm
Default alpha is 0.30. Lexical overlap leads; the graph breaks ties and lifts a well-linked page over a close lexical miss. Set alpha to 1.0 and you get pure popularity, which, as we will see, is how you hand the agent the on-call roster.
Core of wiki_rank.py (PageRank, BM25 coordination, combined score)
def pagerank(ids, edges, damping=0.85, iters=40):
n = len(ids)
idx = {p: i for i, p in enumerate(ids)}
outbound = [[] for _ in range(n)]
for src, dst in edges:
if src in idx and dst in idx and src != dst:
outbound[idx[src]].append(idx[dst])
outbound = [list(dict.fromkeys(row)) for row in outbound]
pr = [1.0 / n] * n
teleport = (1.0 - damping) / n
for _ in range(iters):
nxt = [teleport] * n
dangling = 0.0
for i in range(n):
if not outbound[i]:
dangling += pr[i]
else:
share = damping * pr[i] / len(outbound[i])
for j in outbound[i]:
nxt[j] += share
add = damping * dangling / n
for i in range(n):
nxt[i] += add
pr = nxt
return {ids[i]: pr[i] for i in range(n)}
def bm25(query, docs, k1=1.5, b=0.75):
N, avgdl = len(docs), sum(len(t) for t in docs.values()) / max(len(docs), 1)
df = Counter()
for toks in docs.values():
for w in set(toks):
df[w] += 1
qset = list(dict.fromkeys(query))
scores = {doc: 0.0 for doc in docs}
present = {doc: 0 for doc in docs}
for w in qset:
idf = math.log((N - df.get(w, 0) + 0.5) / (df.get(w, 0) + 0.5) + 1.0)
for doc, toks in docs.items():
tf = toks.count(w)
if not tf:
continue
present[doc] += 1
dl = len(toks) or 1
denom = tf + k1 * (1 - b + b * dl / (avgdl or 1))
scores[doc] += idf * (tf * (k1 + 1)) / denom
nq = max(len(qset), 1)
for doc in scores:
scores[doc] *= present[doc] / nq # coordination
peak = max(scores.values()) or 1.0
return {d: s / peak for d, s in scores.items()}
def combine(pr, lex, alpha):
prn, lexn = normalize(pr), normalize(lex)
keys = set(prn) | set(lexn)
return {k: alpha * prn.get(k, 0) + (1 - alpha) * lexn.get(k, 0) for k in keys}
The write path is easy to describe: there isn't one. The script opens wiki pages and sources for reading only. A unit test hashes every Markdown file before and after a query-plus-lint run and checks the bytes. That is the "no LLM in the storage layer" idea, applied to the ranker too.
$ python3 -m unittest test_wiki_rank
............
----------------------------------------------------------------------
Ran 12 tests in 0.015s
OK
Running it on the sample fixture
$ python3 wiki_rank.py fixture --query "how do we rotate SSO certificates" --lint --today 2026-11-23
wiki_rank: 23 pages, 78 links, 3 dangling today=2026-11-23 alpha=0.30
QUERY "how do we rotate SSO certificates"
1. 0.84 wiki/sso-certificates.md lex=1.00 pr=0.45 "SSO certificate rotation"
cites: sources/okta-rotation-runbook.md, sources/cert-calendar.md
2. 0.65 wiki/certificates.md lex=0.88 pr=0.13 "Certificates"
cites: sources/tls-runbook.md
3. 0.46 wiki/sso-outage.md lex=0.40 pr=0.61 "SSO outage"
cites: sources/okta-status-notes.md
4. 0.42 wiki/sso.md lex=0.39 pr=0.50 "SSO at Trestle"
cites: sources/okta-tenant-notes.md
5. 0.38 wiki/on-call.md lex=0.12 pr=1.00 "On-call"
cites: sources/pager-rules.md
LINT
DANGLING wiki/billing.md [[refund-policy]] is missing
DANGLING wiki/customer-faq.md [[refund-policy]] is missing
DANGLING wiki/incident-billing.md [[refund-policy]] is missing
ORPHAN wiki/old-zoom-setup.md 0 inbound links
STALE wiki/old-zoom-setup.md updated 2026-03-12 (256 days ago)
STALE wiki/on-call-schedule.md updated 2026-08-02 (113 days ago)
DEADEND wiki/old-zoom-setup.md 0 outbound links
DEADEND wiki/vendor-list.md 0 outbound links
UNCITED wiki/data-retention.md no sources: in frontmatter
What a reviewer should take from that:
-
sso-certificates.mdwins, score 0.84, lexical 1.00, PageRank 0.45. It citessources/okta-rotation-runbook.mdandsources/cert-calendar.md. That is the page I would want an agent to open, and the two raw files I would want a human to be able to click through to. -
certificates.mdis a close second on wording (lex 0.88) and a distant second overall (0.65). It is the TLS page. A vector store would also find this one; the difference is that the link graph already knows the SSO cert page is the one the rest of the identity cluster points at (PageRank 0.45 vs 0.13). -
on-call.mdhas the highest PageRank in the whole wiki (1.00) and still lands fifth, because it barely matches the query (lex 0.12). Popularity is not relevance. -
Three pages dangle
[[Refund Policy]]. Finance apparently owns a page that does not exist. A retriever cannot fix that. The lint can. -
old-zoom-setup.mdis an orphan, a dead end, and stale (last updated March 12, 256 days ago). The graph cannot reach it, so neither can an agent that starts from the index. That is fine if the page is retired; it is a problem if someone still thinks it is current. -
on-call-schedule.mdis stale (August 2, 113 days). It is linked, so an agent can find it. That might be worse than an orphan. -
vendor-list.mdhas no outbound links. A list of vendors that does not point at the runbooks is a dead end in the graph. -
data-retention.mdis uncited. It claims "18 months" and "seven years" with nosources:in the frontmatter. A compiled page that makes a legal claim and cites nothing is the kind of thing you do not want an agent quoting.
Pure PageRank is worse than it looks
Same wiki, same query, alpha set to 1.0:
$ python3 wiki_rank.py fixture --query "how do we rotate SSO certificates" --alpha 1 --today 2026-11-23
wiki_rank: 23 pages, 78 links, 3 dangling today=2026-11-23 alpha=1.00
QUERY "how do we rotate SSO certificates"
1. 1.00 wiki/on-call.md lex=0.12 pr=1.00 "On-call"
cites: sources/pager-rules.md
2. 0.87 wiki/incident-response.md lex=0.05 pr=0.87 "Incident response"
cites: sources/incident-severity.md
3. 0.61 wiki/sso-outage.md lex=0.40 pr=0.61 "SSO outage"
cites: sources/okta-status-notes.md
4. 0.54 wiki/on-call-schedule.md lex=0.00 pr=0.54 "On-call schedule"
cites: sources/pager-rules.md
5. 0.53 wiki/billing.md lex=0.00 pr=0.53 "Billing"
cites: sources/stripe-runbook.md
The agent would open on-call.md. Then incident-response.md. The SSO certificate page does not even make the top five. The graph is useful; the graph alone is not a retriever.
Pure BM25 (alpha 0) does pick sso-certificates.md first, with certificates.md close behind at 0.88. That is why the default is 0.30, not 0. The link graph is a tie-breaker and a popularity prior, not the answer.
One store, several tools
The reason I wanted this as a folder of Markdown, not as an API, is the same reason people keep mentioning Claude Code, Cursor, Codex, and Zed in the same sentence as the gist. Those tools already know how to read files. A ranker that prints paths and citations can sit in front of any of them. Each agent does not get its own memory format.
A human still browses the same pages. That is the answer I would give the person who asked this week how to keep an LLM wiki (for agents) distinct from a Zettelkasten (for humans): one store, two ways in. People follow links and edit. Agents ask a question, get a ranked list with sources, and stay out of the write path until a review gate says otherwise.
Notion's "shared brain" announcement is aimed at the same problem — teams tired of re-explaining context to a new agent. I want that shared context to be a directory I can grep, diff, and host, not a feature that disappears if I change vendors.
Where this lives in a team knowledge base
A wiki/ folder in a repo works for one developer. For a team, I would put the compiled pages in the same workspace as the docs and the decisions they cite, with sources, updated, and type as page properties, and with backlinks so "what points at the refund policy that does not exist?" is one query.
In AFFiNE, this is how I would set it up. The wiki pages are ordinary docs, the raw sources are a separate collection, and wiki_rank.py runs against a Markdown export. The lint report lands in a review collection; a person decides whether to write the missing refund page, retire the Zoom setup, or attach a source to the retention policy.
If you're choosing knowledge base software for a setup like this, look for backlinks and queryable properties, because the graph only exists if the links are real. The retrieval shape is close to what we described for an LLM wiki for teams: a self-hosted workspace as the source of truth, agents reading it, a compiled wiki layer for synthesized topics. And if the reason you want that split is control over the files, a self-hosted AI workspace is the deployment version of the same idea — the ranker is just a script, but the pages still have to live somewhere you can export.
I'd also keep this layer somewhere you control. A "shared brain" that only exists inside one vendor's agent is a shared brain you cannot take with you. That's an argument for an open source Notion alternative you can self-host, and for treating this as AI knowledge base software rather than as a plugin of whichever coding agent you used this month. If you are comparing more traditional wiki options alongside a compiled LLM layer, this rundown of self-hosted wiki software is a useful map of the boring, durable half.
What it does badly (on purpose)
It will not scale to tens of thousands of pages. BM25 over a folder is fine at wiki scale. Past that, you probably do want an index, and maybe embeddings for the long tail of PDFs you never compiled. I would still compile the important topics into pages with links, and rank those first.
Stemming is naive. rotate and rotation are special-cased because that was the query I cared about. A real stemmer would be better. I did not want a dependency.
PageRank uses equal edges. A link from the index and a link from a passing "see also" count the same. You could weight them. I have not needed to at 23 pages, and I am not convinced I would trust the weights I invented.
Staleness is a date, not a fact check. updated: 2026-08-02 tells you the page was not touched. It does not tell you the roster is wrong. The lint is a prompt for a human, not a verdict.
It does not answer the question. It ranks pages. The agent still has to read them. If the winning page is wrong, you get a well-cited wrong answer. That is a writing problem, which is why the uncited and stale flags exist.
Try it: point wiki_rank.py at a Markdown export of your own wiki, ask it a question you already know the answer to, and run --lint before you trust --query. In my sample fixture, the flags were as useful as the ranking.



Top comments (0)