Skip to content

About

An AI knowledge layer (vault ingest, auto-linking, offline graph view) built on the Personal LLM core.

Topics

Resources

Contributing

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

Second Brain: A vault that links itself, built on the personal-llm kernel. 116 tests; auto-linking on ingest; offline graph viewer. Core strip: 40 commits over 18 weeks, Jul 2026 to Oct 2026.

Second Brain++

CI Tests Python License: MIT

Your Mind. Expanded. An AI knowledge layer built on top of the Personal LLM core.

Personal LLM already gives us memory, RAG, and a knowledge graph. Second Brain++ adds the vault-level workflows the core does not:

  • Vault ingestion - point it at a folder of notes and it ingests every changed file, skipping unchanged ones via a content-hash manifest (ingest-vault).
  • Quick note - drop a single note straight in from the command line, no file needed (add-note "...").
  • Auto-linking - given a note, surface the most related other notes, aggregated at the document level rather than as raw chunks (related).
  • Knowledge-graph view - export the graph to a single self-contained, offline HTML visualization with an inline force layout, no CDN (graph).
  • Semantic search over everything ingested (search).
  • Code graphs via Graphify (optional) - build a code/repo knowledge graph with Graphify and render it in the same offline viewer, optionally merged with your notes graph (code-graph).
  • Link prediction - rank note pairs that share many neighbors but aren't directly linked yet, a common-neighbors baseline over the knowledge graph (predict-links).
  • Graph node search - filter the knowledge graph's nodes by a name substring and/or type, ranked by how connected each node is, for finding a node in a graph too large to eyeball in the graph viewer (search-graph).
  • Merge-proposal generator - cluster near-duplicate notes and write one human-readable markdown proposal per cluster for you to review; it never merges or deletes anything itself (merge-proposals).
  • Idea-collision engine - pair topically unrelated notes (low similarity, different sources) as candidate sparks for a new project or startup idea, the mirror image of the merge-proposal generator's near-duplicate bar; it never writes the idea itself, only the candidate pairing for you (or a later LLM step) to riff on (idea-collisions).

Under the hood, near_dup.py and contradictions.py also flag near-duplicate and possibly-contradictory note pairs for review (not yet wired to their own CLI commands); link_predict.py, merge_proposals.py, and idea_collisions.py above are the PROJECT-GENESIS Tier 4 analyzers built on top of them so far - all strictly detect-and-propose, never write to the graph or delete a note themselves.

This is project #2 in a larger local-first AI ecosystem. It reuses the Personal LLM package instead of reimplementing retrieval or routing.

Setup (under 5 minutes)

Clone this repo and the core side by side, then install both:

git clone https://github.com/zaidwhy/personal-llm
git clone https://github.com/zaidwhy/second-brain
cd second-brain
py -3.12 -m venv venv
& "venv\Scripts\python" -m pip install -r requirements.txt

# Install the Personal LLM core (the sibling package this project builds on).
# Its runtime deps (chromadb, sentence-transformers, etc.) live in its requirements.txt,
# not its pyproject, so install both: the deps, then the editable package.
& "venv\Scripts\python" -m pip install -r ..\personal-llm\requirements.txt
& "venv\Scripts\python" -m pip install -e ..\personal-llm
& "venv\Scripts\python" -m pip install -e .

Use

# Ingest the bundled sample vault (or pass your own folder)
& "venv\Scripts\python" -m second_brain.interfaces.cli ingest-vault sample-vault

# Or drop in a single note without a file:
& "venv\Scripts\python" -m second_brain.interfaces.cli add-note "Remember: qwen2.5:3b-instruct is the best local model for the graph" --label idea

# Search, find related notes, and export the graph
& "venv\Scripts\python" -m second_brain.interfaces.cli search "how does retrieval work"
& "venv\Scripts\python" -m second_brain.interfaces.cli related sample-vault\recall.md
& "venv\Scripts\python" -m second_brain.interfaces.cli graph --out data\graph.html

# Optional: a code graph of any repo via Graphify (pip install graphifyy first)
& "venv\Scripts\python" -m second_brain.interfaces.cli code-graph . --merge-notes

# Suggest missing links, and propose merges for near-duplicate notes (never auto-merges)
& "venv\Scripts\python" -m second_brain.interfaces.cli predict-links

# Find a node in a large graph by name and/or type
& "venv\Scripts\python" -m second_brain.interfaces.cli search-graph --query dreamos --type note
& "venv\Scripts\python" -m second_brain.interfaces.cli merge-proposals --out data\merge-proposals

# Pair unrelated notes as idea sparks (never creates anything itself)
& "venv\Scripts\python" -m second_brain.interfaces.cli idea-collisions --out data\idea-collisions

Ingest and search reuse Personal LLM's local embeddings, so they work with no API key.

The knowledge graph needs a chat model to extract relationships. Second Brain defaults to the local qwen2.5:3b-instruct Ollama model, so graph populates out of the box once you have it: ollama pull qwen2.5:3b-instruct. Override with OLLAMA_MODEL (or SECOND_BRAIN_OLLAMA_MODEL) to use a different local model, or add a Gemini key to use Gemini.

Graphify integration (optional)

code-graph shells out to the Graphify CLI (MIT) to turn a codebase into a knowledge graph, then renders Graphify's graph.json with our own offline viewer - and can merge it with the notes graph via --merge-notes.

  • By default it runs Graphify's tree-sitter extraction (graphify update --no-cluster), which needs no LLM or API key. Pass --full for Graphify's LLM community clustering (that path needs a provider key).
  • Graphify writes its own graphify-out/ cache into the directory it analyzes; that folder is gitignored here.
  • Graphify is never vendored or required; install it separately with pip install graphifyy (the CLI stays graphify).

The adapter in src/second_brain/graphify_adapter.py parses Graphify's JSON defensively (node id/label/file_type, links under links with source/target/relation) and is verified against a real Graphify run, so it tolerates key-name changes across versions.

Demo

Knowledge graph demo - a real graph export being explored

A real recorded session: second-brain graph --out data\graph.html exports a fully offline, single-file force-graph of everything you ingested; the GIF above is that file being explored (hover, drag, zoom) - captured from a real run, as is everything here.

CLI demo - ingest the sample vault, related notes, semantic search

The CLI half, recorded 2026-09-27 from a real run against sample-vault/ in a clean data directory: ingest-vault, then related and search. The output is the programs' own; only the typing speed is rendered (zaid-os/scripts/term_gif.py runs each command and captures what it prints).

Tests

& "venv\Scripts\python" -m pytest tests/ -q

75 tests. The core logic (vault, links, graphview, near-dup and contradiction detection, link prediction, merge proposals) has no Personal LLM import - dependencies are injected - so the whole suite runs fully mocked, with no API key, network, or heavy model (CI runs it keyless on every push). Only the CLI touches the real core, and it imports it lazily.

Architecture

CLI (thin, lazy-imports the core)
        |
   second_brain: vault (incremental ingest) | links (doc-level auto-linking) | graphview (offline HTML)
                 near_dup / contradictions (candidate detection) | link_predict | merge_proposals
        |
   Personal LLM core: ingest_file | semantic_search | knowledge graph (store.all_nodes/all_edges)

Design docs for the full vision live in plan.md.

Contributing

Small, focused PRs welcome - see CONTRIBUTING.md for the ground rules (the short version: tests stay offline and keyless, inject fakes, no personal_llm imports at module top level outside the CLI). Bug and feature issue templates are under .github/ISSUE_TEMPLATE/.

License

MIT.


One plate from the survey at github.com/zaidwhy. The strip on the plate above is this repository's own commit history, one band per week.

About

An AI knowledge layer (vault ingest, auto-linking, offline graph view) built on the Personal LLM core.

Topics

Resources

Contributing

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages