VaultKG (vaultkg.module)¶
vaultkg.module
¶
module.py -- VaultKG, the KGModule for Obsidian-style Markdown vaults.
VaultKG(repo_root, db_path=None, vectors_path=None, *, exclude=None, **kwargs)
¶
Bases: KGModule
Knowledge graph over one Markdown vault.
Artefacts live in <vault>/.vaultkg/; Obsidian ignores dot-folders, so
they never show up as notes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
repo_root
|
str | Path
|
Vault root. |
required |
exclude
|
list[str] | tuple[str, ...] | None
|
Directory names or glob patterns to skip when building,
added to those in |
None
|
kwargs
|
Any
|
Passed to :class: |
{}
|
Source code in src/vaultkg/module.py
97 98 99 100 101 102 103 104 105 106 107 108 109 | |
analyze()
¶
Markdown graph-health report. Never raises.
Source code in src/vaultkg/module.py
290 291 292 293 294 295 | |
health()
¶
Graph-health figures (hubs, orphans, bridges, wanted pages...).
Source code in src/vaultkg/module.py
286 287 288 | |
links(node_id, *, direction='out', rel='', limit=50)
¶
Links at a node: what it links to, or what links to it (backlinks).
A note's backlinks include links to any of its sections
([[Note#Heading]]), as Obsidian counts them.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node_id
|
str
|
Node id or vault path, as for :meth: |
required |
direction
|
str
|
|
'out'
|
rel
|
str
|
One relation ( |
''
|
limit
|
int
|
Links returned, 1-500. |
50
|
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
On a bad id, direction or limit. |
Source code in src/vaultkg/module.py
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 | |
neighbors(node_id, *, rels=None, direction='both', limit=50)
¶
A node's one-hop neighborhood, by id or by the note's vault path.
:meth:kg_utils.pipeline.KGModule.neighbors, with the id normalized
as :meth:node does.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node_id
|
str
|
Node id, or a bare vault path such as |
required |
rels
|
tuple[str, ...] | list[str] | None
|
Relation types to follow, or |
None
|
direction
|
str
|
|
'both'
|
limit
|
int
|
Most edges, 1-500. |
50
|
Returns:
| Type | Description |
|---|---|
dict[str, Any] | None
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
On an empty or over-long id, or a bad argument. |
Source code in src/vaultkg/module.py
203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 | |
node(node_id)
¶
One node, by id or by the note's vault path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node_id
|
str
|
|
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any] | None
|
The node, or |
Raises:
| Type | Description |
|---|---|
ValueError
|
On an empty or over-long id. |
Source code in src/vaultkg/module.py
193 194 195 196 197 198 199 200 201 | |
pack(q, *, k=8, hop=1, rels=None, **kw)
¶
Like :meth:query, with each note or section's source text attached.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
q
|
str
|
Natural-language query. |
required |
k
|
int
|
Seed hits. |
8
|
hop
|
int
|
Expansion hops. |
1
|
rels
|
tuple[str, ...] | None
|
Relations to expand along; default every relation present. |
None
|
Returns:
| Type | Description |
|---|---|
SnippetPack
|
The pack. |
Source code in src/vaultkg/module.py
162 163 164 165 166 167 168 169 170 171 172 173 | |
query(q, *, k=8, hop=1, rels=None, **kw)
¶
Semantic seeding plus link expansion.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
q
|
str
|
Natural-language query. |
required |
k
|
int
|
Seed hits. |
8
|
hop
|
int
|
Expansion hops along links, embeds, tags and headings. |
1
|
rels
|
tuple[str, ...] | None
|
Relations to expand along; default every relation present. |
None
|
Returns:
| Type | Description |
|---|---|
QueryResult
|
Ranked nodes and the edges among them. |
Source code in src/vaultkg/module.py
149 150 151 152 153 154 155 156 157 158 159 160 | |
relations()
¶
Every relation in the built graph, structural ones first.
Typed links are whatever keys a vault uses (SUPPORTS, UP...),
so query expansion follows the relations actually present rather than
a fixed list.
Source code in src/vaultkg/module.py
137 138 139 140 141 142 143 144 145 146 147 | |
stats()
¶
Store counts, plus note/link figures a vault owner cares about.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
The fleet stats shape ( |
Source code in src/vaultkg/module.py
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 | |
load_config(repo_root)
¶
Read <vault>/.vaultkg/config.yaml.
The file is optional. exclude is a list of folder names or glob
patterns, the same values vaultkg build --exclude takes. raw_dir
is the vault-relative folder vaultkg add writes sources into
(default :data:DEFAULT_RAW_DIR).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
repo_root
|
str | Path
|
Vault root. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
The file is not a mapping, has an unknown key,
|
Source code in src/vaultkg/module.py
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 | |
normalize_node_id(raw)
¶
Normalise a node id supplied from outside (a CLI argument, an MCP call).
Agents echo ids back with backticks or quotes, and people type a note's
path rather than its id, so wiki/X, wiki/X.md and note:wiki/X.md
all name the same note.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
raw
|
str
|
The id as given. |
required |
Returns:
| Type | Description |
|---|---|
str
|
A node id with one of the extractor's prefixes. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If empty after stripping, or longer than 500 characters. |
Source code in src/vaultkg/module.py
298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 | |