zettelkasten.synapse.overlay¶
zettelkasten.synapse.overlay ¶
The synapse link overlay: persisted, bipartite, typed cross-store edges.
The overlay is synapse's ONLY writable artifact — and it writes only to its own
.synapse/links/ tree, never to .memory/ or .zettelkasten/. Every edge
is bipartite (one memory endpoint, one ZK endpoint) and typed
(memory --relation--> zk). It is committed (durable knowledge, expensive to
recompute because typing costs LLM calls) with a manifest recording the store
signatures it was built against, so :func:is_stale can detect drift and
:func:build_connections can refresh.
Public surface:
- :func:
build_connections— full pipeline (candidates -> gate -> LLM type -> threshold -> persist). Accepts an injectedtyperso it runs without an LLM. - :func:
get_connections— typed edges touching a node (either store). - :func:
high_conf_neighbors— 1-hop high-confidence cross-store neighbours, for retrieval expansion. - :func:
is_stale/ :func:refresh_if_stale— cache lifecycle.
zk_signature ¶
zk_signature(zk_get_graph: GetGraph, projects: list[str] | None = None, graphs_dir: 'Path | None' = None) -> str
A freshness token over the in-scope ZK source dirs (newest *.md mtimes).
Each source dir is resolved through :func:resolve_source_dir so a federated
<repo_id>:<graph> source scans the PEER repo's notes (not a same-named
local box), and an edit to a peer note advances the token → is_stale fires.
Source code in zettelkasten/synapse/overlay.py
load_overlay ¶
Load the overlay of kind, returning an empty skeleton when absent/malformed.
Source code in zettelkasten/synapse/overlay.py
load_overlay_from ¶
Load an overlay from an EXPLICIT links.json path (no env mutation).
A path-parametrized twin of :func:load_overlay for callers that must read a
SPECIFIC overlay file rather than the workspace default (e.g. the Iceberg
hosted broker, which resolves the owner's source overlay path itself and must
not depend on / mutate os.environ or the process-global synapse dir).
Returns the SAME empty skeleton ({"version", "manifest", "edges"}) as
:func:load_overlay when the file is absent, unreadable, malformed, or not a
JSON object, so a caller always receives a well-formed overlay dict.
Source code in zettelkasten/synapse/overlay.py
save_overlay ¶
Persist the overlay of kind atomically to .synapse/links/.
Source code in zettelkasten/synapse/overlay.py
is_stale ¶
is_stale(zk_get_graph: GetGraph, projects: list[str] | None = None, graphs_dir: 'Path | None' = None, kind: str = 'generic') -> bool
Whether the overlay was built against a now-changed view of the stores.
Source code in zettelkasten/synapse/overlay.py
build_connections ¶
build_connections(zk_get_graph: GetGraph, projects: list[str] | None = None, graphs_dir: 'Path | None' = None, typer: Typer | None = None, per_node_k: int = 5, sim_threshold: float = 0.45, min_confidence: float = 0.55, max_pairs: int = 200, limit: int | None = None, kind: str = 'generic', canon_types: 'tuple[str, ...] | None' = None, practice_types: 'tuple[str, ...] | None' = None, overfetch: int = 1, enrich_edges: 'Callable[[list[dict[str, Any]], GetGraph, list[str] | None], None] | None' = None) -> dict[str, Any]
Run the full connection pipeline and persist the overlay of kind.
Candidates (semantic NN + shared provenance) are gated to the top
max_pairs by score, each is typed (LLM by default; inject typer to
avoid the LLM), and edges surviving min_confidence with a real relation
are written. Returns the persisted overlay dict.
kind selects the persisted file (generic → links.json, claim →
claim_links.json) so the claim-aligned overlay is SEPARATE from the
generic note-note one; offline-peer preservation and drift are per-kind.
canon_types/practice_types/overfetch are forwarded to
:func:candidates.generate_candidates (the claim path restricts registers and
overfetches to offset the type filter). enrich_edges is an optional hook
invoked ONCE on the surviving edge list (before peer-merge/persist) so a caller
can annotate edges — e.g. the claim path attaches claim_strength and a
blended synthesis priority — WITHOUT changing the confidence gate; it must
never drop edges.
Source code in zettelkasten/synapse/overlay.py
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 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 | |
refresh_if_stale ¶
refresh_if_stale(zk_get_graph: GetGraph, projects: list[str] | None = None, graphs_dir: 'Path | None' = None, kind: str = 'generic', **build_kwargs: Any) -> dict[str, Any]
Rebuild the overlay of kind only when the stores have drifted; else load it.
Source code in zettelkasten/synapse/overlay.py
get_connections ¶
get_connections(node_id: str, overlay: dict[str, Any] | None = None, kind: str = 'generic') -> list[dict[str, Any]]
Typed edges touching node_id on either endpoint (in the kind overlay).
Source code in zettelkasten/synapse/overlay.py
high_conf_neighbors ¶
high_conf_neighbors(node_id: str, min_conf: float = 0.6, overlay: dict[str, Any] | None = None, kind: str = 'generic') -> list[dict[str, Any]]
1-hop high-confidence cross-store neighbours of node_id.
Returns [{neighbor_id, store, relation, confidence}] — the OTHER endpoint
of each qualifying edge. Used to expand retrieval with strongly-linked nodes
from the opposite store.