Work sample · Architecture

How the second brain works

A plain-Markdown wiki that an agent maintains, a graph that connects facts across pages, and a thin harness where the model writes the words and code checks the facts.

I built an employer knowledge base from policies, help documentation and Q&A. An agent maintains a linked Markdown wiki. The answer system retrieves relevant sections and relationships, then checks answers against their cited sources.

Built the LLM Wiki way

It runs locally and follows Andrej Karpathy's "LLM Wiki" pattern: plain Markdown in ordinary folders, raw sources in one and the agent-written wiki in the other. Obsidian is the reader, for browsing pages and following links. The knowledge graph makes relationships between source documents explicit.

Why a graph: chunks lose the chain

A question about which procedure applies to a request may need a policy, an exception and a separate procedure. A knowledge graph connects those facts across documents.

The graph fills that gap. Each page declares typed links in its frontmatter, and every link carries an evidence quote that must appear word for word on the page it cites. graph.py walks those links and shows the evidence for each hop. For questions that span several documents, the system retrieves the linked evidence too.

The diagram shows the design with representative sources.

1. Sources
Approved material

Policies, help documentation and Q&A.

Ingestion

An agent turns source material into topic pages.

2. Knowledge base
Linked wiki

Markdown pages record facts, sources and review dates.

Knowledge graph

Evidence-backed links connect related facts across pages.

3. Answer path
Retrieve and draft

Code selects relevant sections and graph links. The model drafts a response.

Verify and cite

Code checks citations and quotations. Unverified answers are withheld.

4. Review
Human review

A person can inspect the evidence and correct the source page.

Quality checks

Automated checks track broken links, stale material and conflicting claims.

Review findings go back to the source page.

Figure 1 Second Brain architecture: sources, knowledge base, answer path, users and checks.

Five components

  1. Raw and wiki. Source files are read-only. The agent writes one reconciled page per topic, so retrieval returns settled facts, not fragments.
  2. Knowledge graph. Typed links between pages, each carrying a quote that must appear word for word on the page. It answers multi-hop questions that chunked retrieval misses.
  3. Answer harness. Retrieve with code, compose with one model call, verify with code. A failed check withholds the answer and returns the sources.
  4. Trust and freshness. Every page has a trust tier (human-reviewed, machine-confirmed, unverified) and a stale-after date. Key counts come from a sealed query, never a typed value.
  5. Distribution. An MCP server with two tools, shipped as a checksummed package built daily. The build stops on a failed lint, a failed probe, or a scan hit for credentials, prices or personal data.

Five lessons from shipping it

Each one comes from something that broke, or nearly broke, during the build.

  1. Start with the verifier, not the prompt. A better prompt still produces confident, wrong answers. A code check that every quote appears in the cited page, and that every link and page really exists, catches them. If the check fails, withhold the answer and hand back the sources.
  2. Partial beats a guess. Most real questions have several parts. Answer the parts the sources prove and leave the rest blank. An unsupported "probably" is worse than no answer, because people repeat it.
  3. Chunking cuts facts apart. Put the chain in a graph. A question may depend on facts kept on several pages. Evidence-backed links connect them.
  4. Never type a number you can compute. A count copied into a page goes stale silently. Store the query, seal it with a hash, and let lint fail if someone types the value or changes the query without review.
  5. Test what you ship, in the place it runs. The answer server worked on my machine and crashed at start in the installed package, because its isolated environment lacked a library I had installed globally. Release cleanup sorted versions as text and would have deleted the wrong builds. Each fix was small. Each was found only by running the real package in a clean environment.

Python · SQLite FTS5 + sqlite-vec · MCP · Claude Code (claude -p) · Obsidian · PowerShell and bash installers · Windows and Mac

← Back to richsadowski.comSee it in the 3D officeNotes