Qiulin Fan104 downloadsExplore typed semantic relations and source references from a kgdistiller vault.
A local research knowledge base of source-backed records in your Obsidian vaults.
English · 简体中文
kgd search
fuses full-text, dense-embedding (for example BGE-M3) and name matches.This repository holds the Obsidian plugin at 3.0.2 and the Python core at
3.0.0. They are versioned and tagged separately: plugin tags are bare
x.y.z, core tags are core-x.y.z.
我们这个 research oriented 的知识库,我之所以把知识图谱作为其最根本的核心,本质上是我认为:
一篇知识密集、研究性的知识源并不是每段文字都是关键,有很多东西是规范性目的或者“向读者证明我这个研究/架构有意义”。但是,它们进入我的眼睛的时候,我早就确认了它们是有意义的,因而我们真正需要的知识仅仅只是这个文章的一些知识节点而已。
这个 philosophy 是这个图谱的关键,因而检索“到底在哪篇文章的哪个段落”是完全依赖知识图谱的,向量和 bm25 检索也仅仅针对每个知识节点。
An agent can first find a record, then inspect its original context:
kgd get research:sigma-algebra --source-lines 20
This reads the live cited range with 20 lines on either side. For more context,
the agent uses the base root from kgd base list and the record's relative
source path to read the original file. Context stays in the source; the
record's base, path, lines and evidence already provide the connection.
Open the kgdistiller community listing,
choose Add to Obsidian, then enable kgdistiller. For a manual install,
download main.js, manifest.json and styles.css from the
plugin release into
<vault>/.obsidian/plugins/kgdistiller/, reload Obsidian and enable the plugin.
Obsidian 1.13.7 or newer on desktop is required; the plugin does not load
on mobile.
Records live in the vault's hidden .knowledge/ folder, which Obsidian skips
by default. Turn on Settings → kgdistiller → Index hidden knowledge folder
so that .knowledge/ appears in the file explorer, search, Properties and
Backlinks like any other folder. With the CLI from Install,
kgd obsidian install copies the plugin bundled with the CLI into the vault
and turns this setting on in one step.
docs/obsidian.md lists what it changes.
With the path of kgd set in Settings → kgdistiller → kgd executable:
kgd accept would take it.
Accept admits a draft with the drafts it links, indexes and embeds it;
Open draft opens the file for editing; Discard deletes it after
asking. Nothing enters the knowledge base until you accept it.--[[Sigma-algebra]]-- in a md
or txt note, or \kn{Sigma-algebra} in a tex file, names the record that
passage states; capture writes one for each local draft. Markers show as
purple chips in live preview, reading view and latex-live's TeX editors;
Cmd/Ctrl+click opens the record, and Jump between knowledge and its
marker goes back and forth.kgd embedding.Edit records with the Properties panel; the keyword index follows saved record files by itself, and an edited record is re-embedded when you press Re-embed. The full description is in docs/obsidian.md.
The Obsidian plugin reads knowledge through the kgd engine you configure
and never opens the home or the database itself. It writes its own
data.json (API keys stay in Obsidian's SecretStorage; data.json holds only
their names), and, when you capture, accept or discard, drafts under
.knowledge/drafts/. With the kgd you configure it runs kgd base list,
kgd source, kgd markers, kgd mark (which writes a captured draft's
marker into its source), kgd edit, kgd accept, kgd relocate (to localize a record,
which changes where an accepted record cites and may move it into another
base), kgd index, kgd index --no-embed and kgd embedding. It collects no telemetry, needs no account and installs or updates
nothing. Lookup without the agent makes no network request. The agent sends
the selection, its context and the records it reads to the model provider you
choose; web and paper searches go to Exa (mcp.exa.ai); Find sources
also reads Wikipedia and arXiv. Hidden-folder indexing patches internal,
undocumented Obsidian file-adapter methods and uses Node's file system API to
check paths under the vault's .knowledge/ folder, which is why the plugin is
desktop only. It also exposes .knowledge/ to Obsidian search and to other
plugins in that vault. If the Hidden Folders Access plugin is enabled,
kgdistiller reports the conflict and leaves its own indexing off.
The CLI and MCP server run locally. They read the home's config.json and
types/, the records and drafts, and the bases' source files (to check
evidence, find knowledge markers and for kgd get --source-lines). They write only:
config.json through kgd base add/rm and kgd embedding, the types/ folder and
.gitignore that the first kgd base add creates, index.sqlite* and
lock;entries/ and drafts/ folders under a base's .knowledge/;kgd mark inserts a draft's marker;community-plugins.json and the plugin's data.json in
the vault's .obsidian/, through kgd obsidian install;kgd claude link and kgd codex link.The MCP server speaks stdio only and has no write tools.
The core's only network access is downloading the embedding model from the
Hugging Face Hub: kgd embedding set fetches it into the Hugging Face cache
(about 2.3 GB for BAAI/bge-m3), and later loads may still contact the Hub
unless HF_HUB_OFFLINE=1 is set; the plugin sets it for every other run. No
token is sent and no remote code runs. The model runs on your computer in one
shared process, and record text never leaves the machine for embedding.
Nothing is committed or pushed for you: keep each vault and the home in your
own Git repositories.
Original kgdistiller code is MIT, copyright 2026 Qiulin Fan. It permits commercial use, modification and redistribution with the copyright and permission notices retained. The plugin bundle includes Cytoscape.js, cytoscape-fcose, cose-base and layout-base, all MIT, and its hidden-folder indexing is adapted from Hidden Folders Access 2.1.1 (MIT). Their full notices are embedded in the bundle and listed in THIRD_PARTY_NOTICES.md.
kgdistiller is a knowledge base for academic research: papers you read, papers
you write and your own research notes. Each registered directory, usually one
Obsidian vault, is a base. A base keeps its knowledge as Markdown records
in .knowledge/entries/ and proposals awaiting your acceptance in
.knowledge/drafts/. A record is either a node (a concept, or a precisely
stated result whose roles link what it is about) or a relation whose role
keys bind at least two values. Every record
cites a source file of its base by path, line range and verbatim quotes, or,
as foreign knowledge, the web page of an outside work it quotes. A base's
sources are its .md, .tex and .txt files outside hidden folders;
kgdistiller reads them as numbered lines and reads no syntax in them but the
knowledge markers that name the records a passage states.
The global home, $KGDISTILLER_HOME (default ~/.knowledge), registers the
bases with the document types you define for them, and keeps the derived
database index.sqlite:
~/.knowledge/ # $KGDISTILLER_HOME
├── config.json # bases, their document types, embedding model
├── types/<name>.md # one document type per file
├── .gitignore # "index.sqlite*" and "lock"
├── index.sqlite # derived; rebuilt by `kgd index`
└── lock
~/research/ # a base, usually an Obsidian vault
├── notes/ # sources: every .md, .tex and .txt file
└── .knowledge/
├── entries/<id>.md # accepted records
└── drafts/<id>.md # proposed records, same format
The database holds FTS5 full-text rows and float32 vectors, searched by an
exact NumPy scan. The embedding model runs with int8 weights in one shared
process per user, about 1 GB for BAAI/bge-m3, which exits after 15 idle
minutes. kgd search fuses three lanes (lexical, dense and name
matches on labels and aliases) by reciprocal rank. Every read reports lag
when record files changed after the last kgd index. The record files are the
knowledge; the database can always be rebuilt from them.
Building the package needs Node 22 and npm, because the bundled plugin's
main.js is built from source and is not tracked. A direct
uv tool install git+https://… therefore fails; install from a checkout:
git clone https://github.com/qiulinfan/kgdistiller.git
cd kgdistiller
npm run build
uv tool install '.[retrieval]'
uv tool update-shell
This creates the kgd and kgdistiller commands (the same program) on
Windows, macOS and Linux; restart the shell if kgd is not yet on PATH. The
retrieval extra adds PyTorch, transformers, sentencepiece and NumPy for the
dense lane. Without it (uv tool install .), keep "embedding": null in the
home config and search uses only the lexical and name lanes.
Register a base. The folder must already exist; mkdir -p ~/research/notes
creates it. The commands below also need notes/measure.md, whose lines 3-4
must contain the text quoted in the sigma-algebra example under
Record format. The first base add creates the home:
kgd base add ~/research --name research
Define a document type in ~/.knowledge/types/research-notes.md. Its
frontmatter maps the node kinds and the relation kinds to their ordered
roles (a node kind may have none); its body is the guidance an agent follows when extracting records from
documents of this type. No types are activated automatically; you can write
one or adapt a starter template.
---
node_kinds:
definition: []
theorem: [about]
example: [uses, setting]
relation_kinds:
implies: [premise, conclusion]
epistemic: [proved, stated]
---
Extract each definition and each precisely stated result as a node; a result
links every record it is about under about. Record a relation only when the
text states a connection between records, such as one result implying
another.
Give the base that type in ~/.knowledge/config.json (with the type file in
place, kgd base add ~/research --name research --type research-notes writes
it too). Every .md, .tex and .txt file of the base outside hidden
folders is a source; nothing registers them one by one:
{
"bases": {
"research": {
"path": "~/research",
"types": ["research-notes"]
}
},
"embedding": null
}
Then choose the embedding model. kgd embedding set downloads it and checks
that kgdistiller can run it; it must be an XLM-RoBERTa sentence encoder that
ships sentencepiece.bpe.model, such as BAAI/bge-m3. Skip it to search by
keywords and names only:
kgd embedding set BAAI/bge-m3
Then add records. Ask an agent with the Skills installed to capture a
definition or compile a whole note; every result is a draft you review and
accept. To add one by hand, print the profiles of the source's base with
kgd source, write a draft in
~/research/.knowledge/drafts/ (see Record format), then
check, accept and index it:
cd ~/research
kgd source notes/measure.md
kgd check
kgd accept .knowledge/drafts/sigma-algebra.md
kgd search "sigma algebra"
kgd source prints the profile of each document type of the source's base,
its knowledge markers, and the records and drafts it already has. kgd check validates the home, records and drafts, and reports evidence
that moved or no longer matches its source. kgd accept moves drafts into
entries/, all or nothing, then indexes them and embeds them; a draft with an
accepted record's id replaces that record.
Every
command prints JSON and exits 0 on success, 1 on findings or a refusal, and 2
on a usage error.
我之前有另一个重要的设计:agent 并不懂你要什么样的知识节点,因而我认为一个知识源文章属于某个类型(比如 math notes、ai research),用户自己为这个类型去制定知识节点类型以供 agent 去提取。
我作为仓库创始人自己需要的类型(比如 math notes、ai research、cs notes),直接作为默认 templates 就可以了。
A document type declares node kinds and relation kinds with their roles,
optional epistemic labels, and prose guidance for extraction. A base lists
its types in config.json; each record names the one it follows in type:
(optional when the base has one), and the agent drafting it chooses the type
that fits the document.
Capture and compilation read that policy through kgd source SOURCE
before proposing records. kgd check and acceptance validate kinds and roles
against it. You can change the policy or add types without changing the engine.
Templates:
| Template | Knowledge to retain |
|---|---|
| math-notes | Definitions, axioms and precise theorems, with derivations and examples. |
| ai-research | Defined concepts, algorithms, architectures, objectives, precise results and findings, with comparisons and implications. |
| cs-notes | Definitions, algorithms, data structures, architectures, results such as complexity bounds and invariants, with implementation relations. |
Copy a chosen file into $KGDISTILLER_HOME/types/, edit its vocabulary and
guidance, then add its file stem to the types of the bases that use it. These are
starting templates; installation and kgd base add leave the active type
catalog for you to define. The templates are also bundled under
kgdistiller/product/templates/document-types/ in the Python package.
A record is one file whose stem is its id: a readable slug of at most 80
characters, CJK allowed. Its global uid is <base>:<id>. A node:
---
label: Sigma-algebra
kind: definition
aliases:
- σ-algebra
source: notes/measure.md
lines: 3-4
---
A sigma-algebra on a set X is a collection of subsets of X closed under complements and countable unions.
## Evidence
> A sigma-algebra on a set X is a collection of subsets of X that contains X
> and is closed under complements and countable unions.
A relation of the kind implies, whose roles come from the document type
and whose quote states the connection:
---
label: Hahn decomposition implies Jordan decomposition
kind: implies
premise:
- "[[hahn-decomposition-theorem]]"
conclusion:
- "[[jordan-decomposition-theorem]]"
epistemic: stated
source: notes/measure.md
lines: 41
---
The Hahn decomposition theorem implies the Jordan decomposition theorem.
## Evidence
> The Jordan decomposition theorem follows from the Hahn decomposition theorem.
label, kind, source (path relative to the base root) and lines
(a or a-b) are required. A label names one concept across every base:
a concept of another meaning whose name is taken adds its source's file
name, as in Autoencoder (Autoencoder&VAE). A foreign record's source is the web address
of the outside work it quotes, and it has no lines. aliases,
understanding (yes or no, default yes), epistemic and requires
are optional; tags and cssclasses are allowed and ignored. type
names the record's document type and is required when its base has
several.about, links at least one record."[[id]]", "[[base:id]]" or
"[[.knowledge/entries/id]]". A concept nothing records yet is captured on
its own first, from a local source or as foreign knowledge.## Search terms section, then a final
## Evidence section of verbatim quotes from the cited lines (or page).example: [uses, setting]; "the sum of two subspaces is a
subspace" is a theorem about two records, not a relation.Agents only write drafts; you accept them. Edit accepted records by hand in
place, then run kgd check and kgd index --no-embed
(the plugin refreshes the keyword index by itself); an edited record whose
text changed loses its vector and is missing from the dense lane until you
re-embed with kgd index. When a
source edit shifts the cited lines, kgd check --fix-lines rewrites the
lines: of each record whose quotes it finds exactly once elsewhere in the
source. When a file is renamed or moved, kgd check follows each record's
knowledge markers (its own file, then its base, then every other base) and
reports where they lead under follow; --fix-lines applies the follows
within a base and kgd relocate UID any of them. docs/model.md has the full grammar and validation
rules.
| Command | Purpose |
|---|---|
kgd base add PATH [--name N] [--type T]..., base rm NAME, base list |
Register (with the document types its records may use), unregister and list bases with their types and record, draft and index counts. |
kgd embedding, embedding set MODEL, embedding off |
Show the home's embedding model and its vectors, download and check a model and use it, or turn the dense lane off. |
kgd check [--base B] [--fix-lines] |
Validate the home, records and drafts; report moved or stale evidence and where knowledge markers lead (follow). |
kgd source SOURCE |
Print the document-type profiles of a source's base, its markers and the records and drafts citing it. |
kgd markers [SOURCE...] [--uid UID] [--base B] [--orphans] |
List knowledge markers with the records they name. |
kgd mark DRAFT [--name NAME] [--dry-run] |
Write a marker naming a local draft into its source, on the line of its first quote, keeping the line count. |
kgd find TEXT [--base B] [--source PREFIX] |
Find a passage or a name in the sources, whatever its line breaks and hidden markup. |
kgd relocate TARGET [TEXT] [--url URL] [--base B] [--source PREFIX] |
Move a record's source, lines and evidence to the only passage of the sources that holds the text, or without TEXT to where its markers lead, into that passage's base, with every link to it rewritten, when it lies in another; with --url and the page's text, make it foreign. |
kgd drafts [--base B] [--source PREFIX] [--name NAME] |
List the drafts with their links and what kgd accept would refuse; writes nothing. |
kgd edit DRAFT FIELD [VALUE...] |
Set one field of a draft: label, kind, epistemic, understanding, aliases, requires, a role or its statement. |
kgd accept [--dry-run] DRAFT... |
Admit drafts as new records or replacements of the records with their ids, all or nothing, then index and embed them. |
kgd index [--rebuild] [--no-embed] |
Bring the database up to date with the record files; --no-embed refreshes only the keyword index. |
kgd search QUERY [--limit N] [--no-dense] |
Rank records by the lexical, dense and name lanes. |
kgd resolve TERM... |
List the senses and mentions of terms. |
kgd get UID... [--source-lines N] |
Read complete records with their links and, optionally, the live cited source lines. |
kgd neighbors UID... [--role R] [--dir out|in|both] [--depth N] |
Follow links from records: dependency closures, and with --dir in the statement nodes and relations that link a record. |
kgd browse [HANDLE] |
List bases, a base's source directories, a source's records by kind, or every record of a --kind. |
kgd pack UID... [--budget BYTES] [--requires-depth N] |
Pack whole records within a byte budget, with the records linking several of them and the gaps left open. |
kgd obsidian install [--base NAME] |
Install or update the plugin in a base's vault and enable it with hidden-folder indexing. |
kgd claude link|doctor, kgd codex link|doctor |
Install or verify the Skills, agent presets and workflow files for Claude Code or Codex. |
kgd mcp |
Serve the read tools over stdio for every base. |
search, resolve, neighbors, browse and pack take the filters
--base, --kind, --class {node,relation}, --source PREFIX and
--understanding, each repeatable. A bare id works where it is unique across
bases. Run kgd <command> --help for details and
docs/retrieval.md for the output shapes.
Every capture and compile ends in drafts. Review them in the plugin's Capture
view, which lists them by source and shows each one's links and what
kgd accept would refuse, or open them like any file and run:
kgd drafts --source notes/measure.md
kgd accept .knowledge/drafts/measure-space.md
Edit a draft's fields and links on its Capture view card or with
kgd edit. kgd accept admits exactly the drafts given, all or nothing, and
indexes and embeds them. If a draft links a draft you did not give, it refuses
and changes nothing, with a message such as select [[sigma-algebra]] too:
give that draft as well (the Capture view passes a draft's linked drafts
together). To reject a draft, delete its file.
Five Skills cover the write and read workflows:
| Skill | What it does |
|---|---|
capture-kgdistiller |
Drafts one record while you read: a concept, a result the source states, or a relation between records, with its quote, or a borrowed concept as foreign knowledge from the page of its work, and marks a local draft in its source. The kgdistiller-capture-writer agent preset runs it in the background. |
compile-kgdistiller |
Drafts records from part or all of a source, following the document type that fits it, and marks them in the source. Knowledge already recorded is ignored, or drafted as a replacement, by the conflict rules in docs/model.md. |
relocate-kgdistiller |
Finds where records went after a source was edited, renamed or moved, by their knowledge markers in their own file, their base and then every other base, and moves them there; judges a reworded passage by its meaning; moves a record to a passage you paste; and makes unmarked knowledge that is found nowhere foreign, citing the page that states it. |
query-kgdistiller |
Answers from the base with search, resolve, get, neighbors, browse and pack, citing source:lines. Read-only, with the kgdistiller-query-reviewer agent preset. |
deploy-kgdistiller |
Installs, registers bases with their document types and the model, then checks, indexes, installs the plugin and links the runtimes. |
The Skills write drafts only; accepting them indexes and embeds them, and re-embedding a record you edited by hand is left to you. Install them for your runtime:
kgd claude link
kgd claude doctor
kgd codex link
kgd codex doctor
link installs the Skills, the kgdistiller-query-reviewer and
kgdistiller-capture-writer presets and the
workflow manifest under ~/.claude or ~/.codex (honoring CLAUDE_CONFIG_DIR
and CODEX_HOME) and never edits CLAUDE.md, settings.json, AGENTS.md or
config.toml. OMP and dsh (DeepSeek Harness) get the Skills only, from the checkout:
./scripts/link-skills.sh omp or ./scripts/link-skills.sh dsh
(PowerShell 7: ./scripts/link-skills.ps1 -Runtime dsh).
The MCP server exposes kg_search, kg_resolve, kg_get, kg_neighbors,
kg_browse, kg_pack, kg_drafts and kg_find, with the same JSON as the
CLI. It
loads no model: the dense lane asks the shared embedding process, so only the
first dense search after 15 idle minutes waits for the model.
Register it as the command kgd mcp:
claude mcp add kgdistiller -s user -e HF_HUB_OFFLINE=1 -- kgd mcp
codex mcp add kgdistiller --env HF_HUB_OFFLINE=1 -- kgd mcp
OMP loads stdio MCP servers natively from .mcp.json, .omp/mcp.json or
~/.omp/agent/mcp.json; /mcp add kgdistiller -- kgd mcp inside OMP writes
the entry. For omp -p, set OMP_MCP_REQUIRE_READY=1 so the first turn waits
for the server. docs/deployment.md has the
details.
When asked to install kgdistiller from this repository, an agent should:
npm run build, then uv tool install '.[retrieval]' and
uv tool update-shell, and confirm kgd --help runs.kgd claude link then kgd claude doctor, or
kgd codex link then kgd codex doctor; for OMP or dsh,
./scripts/link-skills.sh omp|dsh. Start a new session afterwards.deploy-kgdistiller Skill: kgd base add for each vault, write
the document types into ~/.knowledge/types/ and each base's types in
~/.knowledge/config.json, set the model with kgd embedding set BAAI/bge-m3,
then run kgd check,
kgd index and, for a vault opened in Obsidian, kgd obsidian install.kgd base list and kgd search "KNOWN NAME" --base NAME.After that, requests such as "capture this definition into my kgd knowledge base" or "search my knowledge base for measure spaces" reach the matching Skill.
Commit each base's sources together with .knowledge/entries/ and
drafts/. Keep the home's config.json, types/ and .gitignore in a
separate private repository; index.sqlite* and lock are ignored. On a new
machine, restore those files, fix each base's path, and rebuild:
kgd check
kgd index
kgd index recreates a missing or damaged database from the record files and
re-embeds every record. Deleting the database first
(rm -f ~/.knowledge/index.sqlite*) is optional. The embedding process
encodes about 14 records a second with BAAI/bge-m3 on Apple silicon.
kgd index --rebuild re-derives every row without re-embedding.
npm run build
uv run --locked python -m unittest discover -s tests -v
uv run --locked ruff check src tests scripts
uv build --out-dir build/release/3.0.0
uv run --locked python scripts/check_distribution.py --dist-root build/release/3.0.0
npm test
(cd integrations/obsidian && npm ci && npm run check)
Root npm run build comes first: every uv run and uv build in a fresh
checkout needs the built plugin. Tests use a temporary KGDISTILLER_HOME and a
fake encoder. docs/release.md lists the release gates,
including the opt-in real-model test.
Further reading: docs/model.md (records and the write path), docs/retrieval.md (database, search and MCP tools), docs/obsidian.md (the plugin), docs/deployment.md (install, configuration, restore) and docs/product-workflows.md (Skills and workflows).