Adding sources (vaultkg.add)¶
vaultkg.add
¶
add.py -- place source documents into a vault as derived notes.
vaultkg add converts each source file with the SDK's converters
(:mod:kg_utils.ingest: PDF via pymupdf4llm, office formats via
anydoc, LaTeX and HTML via pandoc, Markdown and text as they are) and
writes it to <vault>/<raw_dir>/<kind>/<slug>.md with provenance
frontmatter (:func:kg_utils.ingest.write_derived). The original is copied
to <raw_dir>/<kind>/files/ unless copy=False.
Nothing here reads or writes the graph, and nothing calls a model: placing a source is deterministic, and turning it into wiki pages is the agent's job.
Collisions are decided by content, not by name. If the slug is taken by a
note whose source_sha256 matches the new file, the file is skipped as
already added; any other occupant is an error, resolved with prefix.
AddResult(source, status, note='', reason='')
dataclass
¶
What happened to one source file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
Path
|
The source file. |
required |
status
|
Status
|
|
required |
note
|
str
|
Vault-relative path of the derived note (empty when none). |
''
|
reason
|
str
|
Why it was skipped or failed (empty when added). |
''
|
add_sources(vault, paths, *, kind, raw_dir='RAW', prefix='', copy=True)
¶
Convert and place each source under <vault>/<raw_dir>/<kind>/.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vault
|
Path
|
Vault root. |
required |
paths
|
list[Path]
|
Files and/or folders (folders are walked recursively). |
required |
kind
|
str
|
Sub-folder of raw_dir, a lowercase hyphenated slug. |
required |
raw_dir
|
str
|
Vault-relative folder for sources (from config). |
'RAW'
|
prefix
|
str
|
Prepended to every slug, to separate same-named files. |
''
|
copy
|
bool
|
Copy each original to |
True
|
Returns:
| Type | Description |
|---|---|
list[AddResult]
|
One :class: |
Raises:
| Type | Description |
|---|---|
ValueError
|
If kind is not a slug. |
FileNotFoundError
|
If a named path does not exist. |
Source code in src/vaultkg/add.py
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 | |
slugify(name)
¶
Lowercase, hyphen-joined ASCII form of name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
A file stem, possibly with spaces, accents or punctuation. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The slug; |
Source code in src/vaultkg/add.py
62 63 64 65 66 67 68 69 | |