zettelkasten.backfill¶
zettelkasten.backfill ¶
Retroactive quote capture for already-extracted sources.
The extraction protocol now asks the agent to mint verbatim quote notes from
the user's Zotero highlights (see get_extraction_protocol /
_EVIDENCE_PROTOCOL in :mod:zettelkasten.server). Sources extracted before
that change carry paraphrased claim/finding notes but no quote evidence, even
though the user's highlights still live in Zotero. This module walks those
sources, pulls their saved highlights, and materializes them as quote notes
linked supports to the claim/finding each one best matches.
Design (deterministic, no LLM — mirrors the engine/agent split):
- Highlights are retrieved, never generated: the body of every quote note is
the verbatim annotation text and source.page comes from the Zotero
pageLabel. We never fabricate a quote.
- Matching a highlight to the note it backs is a cosine-similarity lookup against
the source's own embedding index (the same index that powers semantic_search).
A highlight links supports -> the best claim/finding above link_floor;
below the floor it is still preserved as an unlinked quote note (the source
folder is itself the provenance) rather than mis-attributed.
- Idempotent: a highlight whose verbatim text already exists as a quote note in
the source is skipped, so re-running never duplicates.
- Dry-run by default (apply=False): reports exactly what it would write.
backfill_quotes ¶
backfill_quotes(get_graph: Callable[[str], 'ZettelGraph'], *, source: str = '', apply: bool = False, link_floor: float = 0.45, link_types: tuple[str, ...] = DEFAULT_LINK_TYPES, graphs_dir: Path | None = None) -> dict[str, Any]
Mint verbatim quote notes from Zotero highlights for existing sources.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
get_graph
|
Callable[[str], 'ZettelGraph']
|
Callable returning a live |
required |
source
|
str
|
A single source folder to backfill; empty = every source that has
a |
''
|
apply
|
bool
|
When False (default) this is a dry run that reports the plan; when
True it writes the quote notes (with their |
False
|
link_floor
|
float
|
Minimum cosine similarity to link a highlight to a claim; below it the quote is created unlinked. |
0.45
|
link_types
|
tuple[str, ...]
|
Note types a highlight may be linked to. |
DEFAULT_LINK_TYPES
|
graphs_dir
|
Path | None
|
Override the graphs root (tests / federation). |
None
|
Returns a summary dict (per-source plans + totals).
Source code in zettelkasten/backfill.py
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 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 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 | |
backfill_project_cross ¶
backfill_project_cross(get_graph: Callable[[str], 'ZettelGraph'], *, project: str = '', apply: bool = False, expand_closure: bool = True, graphs_dir: Path | None = None) -> dict[str, Any]
Write explicit cross: membership for projects from the old inference.
For every project (or the single project given): compute the cross ids
the old read-path would have shown, union them with any ids already on the
manifest, drop a literal _cross entry from sources (the legacy hack),
and persist. apply=False (default) reports the plan without writing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
get_graph
|
Callable[[str], 'ZettelGraph']
|
Server |
required |
project
|
str
|
A single project to migrate; empty = every project. |
''
|
apply
|
bool
|
When False (default) dry-run; when True rewrite the manifests. |
False
|
expand_closure
|
bool
|
Pull in synthesis spines wired only with intra- |
True
|
graphs_dir
|
Path | None
|
Override the graphs root (tests). |
None
|
Returns a summary dict (per-project plans + totals).
Source code in zettelkasten/backfill.py
377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 | |