zettelkasten.synapse¶
zettelkasten.synapse ¶
Synapse: a read-only layer linking the memory tree and the zettelkasten.
Synapse never writes to .memory/ or .zettelkasten/ — both stores stay
canonical, written only by their own workflows. On top of them synapse provides:
- Unified retrieval across the memory tree + intersecting ZK projects, fused in the shared 512-d model2vec space (both stores embed with the same model).
- Typed cross-store connections discovered hands-off (semantic NN + shared provenance, LLM-typed) and stored in synapse's own bipartite overlay — every edge has one memory endpoint and one ZK endpoint, never within-store.
- A matrix/apex synthesis lens projecting the overlay (deferred module).
It is application-agnostic substrate; a domain agent (e.g. a quant research assistant) is just one consumer.
Layout:
.synapse/config.yaml— committed, user-authored intersections..synapse/links/links.json— committed link overlay (typed cross-store edges). Durable because typing costs LLM calls; a manifest tracks the store signatures it was built against so it can be refreshed when either store drifts..angelo/synapse/— gitignored scratch space for any recomputable caches.
This subpackage lives inside zettelkasten (which already imports memory
utilities) so the cross-store code respects the one-way dependency direction:
zettelkasten may import memory; memory never imports zettelkasten.
IntersectSpec
dataclass
¶
One resolved intersects entry: a ZK project + optional federated repo.
repo is None is a LOCAL scope (project in this repo's .zettelkasten/);
a non-None repo names a peer id declared under federated_repos in
.zettelkasten/config.yaml.
Source code in zettelkasten/synapse/config.py
token ¶
Round-trippable scope token: project or <repo>:<project>.
The federated form mirrors :func:zettelkasten.federation.namespace_id
so a token stored in a build manifest re-parses to the same spec.
Source code in zettelkasten/synapse/config.py
MemoryNote
dataclass
¶
A memory entry adapted to the note surface project_query reads.
links/backlinks are intentionally empty: cross-store relationships live
in synapse's own overlay, and within-memory edges (related_to) aren't
part of retrieval. entry keeps the raw record so downstream (connection
typing, provenance) can read files/parent_id/timestamps.
Source code in zettelkasten/synapse/memory_source.py
MemorySourceGraph ¶
The .memory/ tree adapted to the ZK source-graph surface (read-only).
Source code in zettelkasten/synapse/memory_source.py
Candidate
dataclass
¶
A possible cross-store link (one memory node, one ZK node) + why.
Source code in zettelkasten/synapse/candidates.py
score ¶
Combined candidate strength (provenance overlap is a strong prior).
Navigator ¶
The deterministic action executor that steers the LLM to ANSWER or ABSTAIN.
Construct with the injected seams (all optional except the LLM) and call
:meth:navigate. Every source of non-determinism — the model, tether
verification, verifier grounding, neighborhood expansion, and the prune walk
— is injected, so a run is reproducible and testable with no live model or
store. The navigator NEVER decides grounding itself: the terminal ANSWER/
ABSTAIN verdict is always delegated to
:func:zettelkasten.synapse.grounding_router.route.
Source code in zettelkasten/synapse/navigation.py
483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 | |
navigate ¶
navigate(question: str, neighborhood: Neighborhood, *, groundings: Mapping[str, GroundingSpec] | None = None) -> NavResult
Run the navigation loop over neighborhood to a verdict.
question is the user's query; neighborhood is the assembled
substrate the run starts from (further expand moves may grow it).
groundings optionally seeds grounding specs (the ground action
adds more). Returns a :class:NavResult whose decision is the
router's ANSWER/ABSTAIN verdict (or a structurally-forced ABSTAIN on a
budget/parse failure).
Source code in zettelkasten/synapse/navigation.py
538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 | |
config_path ¶
intersecting_projects ¶
Return the ordered, de-duplicated list of intersecting LOCAL project names.
Backward-compatible view over :func:intersecting_scopes that keeps only
local (non-federated) entries — used where a plain local project name is
expected (e.g. legacy callers). Federated scopes are surfaced via
:func:intersecting_scopes.
Source code in zettelkasten/synapse/config.py
intersecting_scopes ¶
intersecting_scopes(config: dict[str, Any] | None = None) -> list[IntersectSpec]
Return the ordered, de-duplicated list of intersecting scopes.
Reads .synapse/config.yaml when config is not supplied. Malformed or
blank entries are dropped (best-effort, never raises) so a partial config
still yields the valid subset. De-dup is keyed on (repo, project) so the
same project can intersect from both a local and a federated source.
Source code in zettelkasten/synapse/config.py
parse_scope_token ¶
parse_scope_token(token: Any) -> IntersectSpec | None
Parse one override token (from synapse(projects=[...])) into a spec.
A <repo_id>:<project> token (the namespace separator : can never
appear in a local project name) resolves to a FEDERATED spec; any other
non-blank string is a local project. Returns None for blank/invalid input.
Source code in zettelkasten/synapse/config.py
read_config ¶
Read the synapse config, returning {} when missing or malformed.
Source code in zettelkasten/synapse/config.py
synapse_dir ¶
write_config ¶
Write the synapse config atomically (temp file + rename).
Source code in zettelkasten/synapse/config.py
get_memory_source ¶
get_memory_source(force_refresh: bool = False) -> MemorySourceGraph
Return a cached :class:MemorySourceGraph, rebuilt when .memory/ changes.
The cache is keyed on storage.source_fileset_signature() so an edit,
add, delete, or rename of any memory source file transparently rebuilds the
.notes map and drops the stale semantic index.
Source code in zettelkasten/synapse/memory_source.py
combined_grapher ¶
Wrap a ZK grapher so _memory and federated names also route.
_memory-> the read-only memory-source adapter.- a namespaced
<repo_id>:<graph>-> a read-only :class:ZettelGraphpointed at the peer repo's.zettelkasten/(structural load so its embedding index stays lazy and rebuilds locally on first.embeddingsaccess). Cached in the PROCESS-GLOBAL :data:_FED_GRAPH_CACHE(mtime-gated), not per-grapher, so the index stays warm across queries in a long-lived worker. The peer'sgraphs:allowlist is enforced fail-closed. - every other name -> the caller's local grapher, unchanged.
Resolved graphs are memoized for the LIFE OF THIS GRAPHER (one grapher is
built per query). A single query resolves _memory and each box hundreds of
times — via pruning, the keyword/semantic channels, and the reranker's
per-candidate vector fetch — and each unmemoized _memory hit recomputed
storage.source_fileset_signature() (a full glob+stat of every .memory/
file), the dominant warm-query cost at scale. Memoizing per-grapher collapses
that to one resolution per distinct source per query while preserving
freshness: the next query builds a new grapher (and the underlying
:func:get_memory_source / :data:_FED_GRAPH_CACHE still revalidate on their
own), so a within-query snapshot never masks a between-query change.
Source code in zettelkasten/synapse/retrieval.py
frame_across_stores ¶
frame_across_stores(question: str, zk_get_graph: GetGraph, projects: list[str] | None = None, graphs_dir: 'Path | None' = None, max_sources: int | None = None, **frame_kwargs: Any) -> dict[str, Any]
Frame a question across memory + intersecting ZK, tagging hits by store/tier.
Returns the same shape as :func:zettelkasten.framing.frame_question, with
each finding/claim/other entry annotated with store and tier and a
top-level scope block describing what was searched.
max_sources caps how many in-scope sources are framed against (default:
the synapse config, :func:zettelkasten.synapse.config.max_sources). The
scope is pruned to the most keyword-relevant boxes for question BEFORE
framing so the expensive per-box embedding index build is bounded — the
dominant cold-query cost and the kglite crash surface. 0/negative
disables pruning.
Source code in zettelkasten/synapse/retrieval.py
resolve_scope ¶
resolve_scope(zk_get_graph: GetGraph, projects: list[str] | None = None, graphs_dir: 'Path | None' = None, include_memory: bool = True) -> tuple[list[str], GetGraph]
Resolve (search_sources, get_graph) for the cross-store scope.
projects=None uses the intersection config; an explicit list overrides
it ([] means "no ZK, memory only"), where each entry is a local project
name or a federated <repo_id>:<project> token. ZK sources are the union
of each scope's :func:~zettelkasten.framing.frame_search_sources,
de-duplicated with order preserved; federated sources are surfaced under
<repo_id>:<graph> names (honoring the peer's allowlist). The _memory
source is appended unless include_memory is False.
Source code in zettelkasten/synapse/retrieval.py
resolve_source_dir ¶
Filesystem dir backing a (possibly namespaced) ZK source name.
A federated <repo_id>:<graph> resolves to <peer .zettelkasten/>/<graph>;
a bare name to default_base/<name>. Used for freshness/staleness scans that
must reach the peer's notes, not a same-named local box.
Source code in zettelkasten/synapse/retrieval.py
scope_tokens ¶
Round-trippable scope tokens for reporting/manifest (local + federated).
Normalizes the scope arg (config or override) to project /
<repo_id>:<project> tokens that re-parse to the same specs.
Source code in zettelkasten/synapse/retrieval.py
search_across_stores ¶
search_across_stores(query: str, zk_get_graph: GetGraph, projects: list[str] | None = None, top_k: int = 15, graphs_dir: 'Path | None' = None, expand: bool = False, expand_min_conf: float = 0.6, max_sources: int | None = None) -> dict[str, Any]
Hybrid search across memory + intersecting ZK, fused via RRF.
Delegates to :func:zettelkasten.framing.project_query (per-source keyword +
semantic channels fused with rrf_order, then merged across sources) and
resolves each hit to a result dict tagged by store/tier.
When expand is set, each hit is expanded via the synapse link overlay:
its high-confidence 1-hop cross-store neighbours are appended (tagged
expanded_from + relation) — so a canon hit pulls in the practice that
applies it, and vice versa.
max_sources caps how many in-scope sources are searched (default: the
synapse config, :func:zettelkasten.synapse.config.max_sources). The scope is
pruned to the most keyword-relevant boxes for query BEFORE the hybrid pass
so the expensive per-box embedding index build is bounded — the dominant
cold-query cost and the kglite crash surface. 0/negative disables pruning.
Source code in zettelkasten/synapse/retrieval.py
820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 | |
candidates_for ¶
candidates_for(node_id: str, zk_get_graph: GetGraph, projects: list[str] | None = None, graphs_dir: 'Path | None' = None, per_node_k: int = 8, sim_threshold: float = 0.45, canon_types: 'tuple[str, ...] | None' = None, practice_types: 'tuple[str, ...] | None' = None) -> list[Candidate]
Lazy single-node candidate generation (either a memory id or a ZK note id).
Used by the on-demand connection path: given one node, find its cross-store
neighbours in the other store via semantic NN + shared provenance.
canon_types/practice_types optionally restrict which note types are
accepted on the canon (ZK) and practice (memory) endpoints — None (the
default) accepts all, preserving the original behaviour.
Source code in zettelkasten/synapse/candidates.py
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 | |
generate_candidates ¶
generate_candidates(zk_get_graph: GetGraph, projects: list[str] | None = None, graphs_dir: 'Path | None' = None, per_node_k: int = 5, sim_threshold: float = 0.45, limit: int | None = None, canon_types: 'tuple[str, ...] | None' = None, practice_types: 'tuple[str, ...] | None' = None, overfetch: int = 1) -> list[Candidate]
Generate cross-store candidate pairs across the intersection scope.
ZK-anchored: each ZK note is used as a query into memory's vector space
(bounded by per_node_k neighbours per note, sim_threshold floor), and
the shared-provenance index is intersected. limit caps the number of
canon-endpoint (candidate) notes scanned for lazy/partial builds — with a
canon_types filter only canon-passing notes count against it, so claims
beyond the first limit non-canon notes stay reachable.
The claim-aligned build restricts the two registers with canon_types
(only these ZK note types become canon endpoints — e.g. claim/finding)
and practice_types (only these memory entry types become practice
endpoints — e.g. decision/experiment/checkpoint, which keeps a
large annotation/note-heavy tree from exploding the candidate pool). Because
that type filter is applied AFTER semantic recall, cross-register recall would
otherwise bleed — so overfetch (>=1) widens the per-note neighbour fetch
to per_node_k * overfetch and then keeps the first per_node_k that pass
the practice filter. _cross synthesis-claim endpoints get a small score
prior so they are preferred over single-source findings covering a pair. The
shared-provenance channel is register-independent and always kept.
canon_types/practice_types None (the default) preserves the
original, unfiltered note-note behaviour exactly.
Source code in zettelkasten/synapse/candidates.py
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 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 | |
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 | |
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.
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
load_overlay ¶
Load the overlay of kind, returning an empty skeleton when absent/malformed.
Source code in zettelkasten/synapse/overlay.py
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
build_matrix_lens ¶
build_matrix_lens(zk_get_graph: GetGraph, projects: list[str] | None = None, graphs_dir: 'Path | None' = None, overlay: dict[str, Any] | None = None, min_confidence: float = 0.0, max_rows: int = _MAX_AXIS, max_columns: int = _MAX_AXIS) -> dict[str, Any]
Project the connection overlay into a practice x canon matrix (read-only).
Rows = memory nodes, columns = ZK nodes, cells = typed edges. Titles are resolved best-effort via the stores. Axes are capped (busiest nodes first) with a truncation flag.
Source code in zettelkasten/synapse/matrix.py
35 36 37 38 39 40 41 42 43 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 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 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 | |
synthesize_axes ¶
Add row/column summaries and a rolled-up apex synthesis to a matrix lens.
synth(kind, header, items) returns summary text; defaults to a tool-free
LLM pass. Purely additive and read-only — the returned lens gains
row_synthesis / column_synthesis / apex fields.
Source code in zettelkasten/synapse/matrix.py
adapter_expander ¶
Build the navigator's :data:Expander seam over adapters.
The returned callable matches the navigation contract exactly — it is invoked
as expander(neighborhood, target) where target is a node token, and it
returns (neighbors, edges) for the navigator to merge. It locates the
target node in the current neighborhood, dispatches to the owning adapter by
the node's store + source, and returns that adapter's within-store
one-hop expansion. An unknown target (not in the neighborhood, or no owning
adapter) or a failing adapter yields ([], []) — a best-effort expansion
never sinks a run.
budget is the DECLARED assembly budget (default a fresh
:class:~zettelkasten.synapse.substrate.Budget): it is passed to
adapter.expand and, crucially, bounds each expand's fan-out — a single
call may reveal no more neighbors than the remaining room under
budget.max_nodes when set, truncating deterministically in adapter order.
None leaves fan-out count-uncapped; hop and navigator token bounds still
terminate the run. The navigator's _merge enforces the SAME optional
ceiling globally; this keeps the two growth paths consistent.
Source code in zettelkasten/synapse/assemble.py
adapter_grounder ¶
Build the navigator's :data:Grounder seam over adapters.
The returned callable matches the navigation contract exactly — it is invoked
as grounder(token) and returns the re-fetched :class:~zettelkasten.
synapse.substrate.Node (with its full, un-elided body) or None when the
token does not resolve. It parses the token to a MemDSL
:class:~zettelkasten.synapse.memdsl.schema.Address, dispatches to the owning
adapter by store + source, and returns adapter.get(address).
registry is accepted for API symmetry with the router's verifier registry
(so a future grounder can consult it) but is unused by the v1 seam, whose sole
job per the navigation contract is to re-fetch a node by token.
Source code in zettelkasten/synapse/assemble.py
build_adapters ¶
build_adapters(projects: 'list[str] | None' = None, *, graphs_dir: 'object | None' = None, include_code: bool = False) -> 'list[SourceAdapter]'
Compose the store adapters for a cross-store scope (read-only).
Resolves the scope with :func:zettelkasten.synapse.retrieval.resolve_scope
— the SAME entry point the synapse() read paths use — and builds one
adapter per resolved source:
- a single :class:
~zettelkasten.synapse.substrate.MemoryAdapterfor the.memory/research tree (always included; the_memorysource thatresolve_scopeappends is skipped in the loop since this adapter already covers it); - one :class:
~zettelkasten.synapse.substrate.ZettelAdapterper resolved ZK box, whose lazygraph_providerroutes through the combined grapher thatresolve_scopereturns (so a cached/rebuilt graph is picked up fresh); - optionally a :class:
~zettelkasten.synapse.substrate.CodeAdapterwheninclude_codeis set.
projects=None uses the intersection config; an explicit list overrides it
([] = memory only). graphs_dir optionally points the ZK grapher at a
non-default store base (tests). A federated <repo_id>:<box> source IS
included: its identity is encoded into an address-safe source segment
(:func:_federated_source) so it is representable by the store:source:id
address scheme, while its graph_provider still resolves the REAL federated
graph through the combined grapher's <repo_id>:<box> routing.
Two soundness invariants are ENFORCED (not merely asserted) so no adapter can
ever be built with an address-invalid or colliding source:
- Validate-and-skip. The FINAL resolved
source(local or federated) is checked against the Address-forbidden character set (:func:_is_address_safe_source) right before the adapter is constructed; a failing source is omitted (continue) rather than emitted. This backstops federated identities carrying the reserved~delimiter or a forbidden char AND boundary-colon names (":box","repo:") that :func:~zettelkasten.federation.split_namespacedeclines and that would otherwise reachAddressverbatim and crash the read path. - No collision with the reserved federation namespace. A LOCAL box whose
name begins with the reserved
~fed~marker is skipped, so a local source can never equal a federated encoded source (which always carries that marker). This keeps_dispatch_adapterfrom silently shadowing a federated node with a same-named local box.
Returns the adapters in deterministic scope order (memory first).
Source code in zettelkasten/synapse/assemble.py
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 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 | |
navigate_scope ¶
navigate_scope(question: str, projects: 'list[str] | None' = None, *, llm: 'object | None' = None, budget: 'Budget | None' = None) -> 'NavResult'
Run the full grounded-navigation loop over a resolved scope.
A thin convenience that ties the pieces together: compose the store adapters
for projects (:func:build_adapters), assemble the in-memory neighborhood
for question (:func:~zettelkasten.synapse.substrate.assemble_neighborhood),
and run a :class:~zettelkasten.synapse.navigation.Navigator wired with the
adapter-backed :func:adapter_expander / :func:adapter_grounder seams.
llm defaults to :func:zettelkasten.synapse.navigation.default_llm (the
production model seam); a test injects a scripted stub. budget bounds the
neighborhood assembly (:class:~zettelkasten.synapse.substrate.Budget): its
hops>0 turns on pre-loop breadth-first expansion and its max_nodes is
threaded through as the navigator's hard in-loop ceiling.
Degrades GRACEFULLY: any assembly/model/navigation failure (a scope-resolve,
kglite, embedding-build, or LLM error) is caught and returned as a labeled
abstain :class:~zettelkasten.synapse.navigation.NavResult — never a raise —
mirroring the synapse(action="navigate") handler.
Returns the navigator's :class:~zettelkasten.synapse.navigation.NavResult.
Source code in zettelkasten/synapse/assemble.py
render_neighborhood ¶
render_neighborhood(neighborhood: Neighborhood, node_status: Mapping[str, StatusVerdict], *, focus: str | None = None, expanded: Iterable[str] = (), max_body_chars: int | None = None) -> Envelope
Render an assembled substrate neighborhood into a MemDSL :class:Envelope.
neighborhood is the assembled nodes + edges (see
:func:zettelkasten.synapse.substrate.assemble_neighborhood); node_status
maps each :attr:Node.token to the :class:StatusVerdict epistemics derived
(see :func:zettelkasten.synapse.epistemics.apply_node_statuses). The wire
status of every rendered node is CONSUMED from that map, never re-derived.
focus optionally names the node token the render is centered on (resolved
to its assigned envelope-local ref). expanded names the node tokens whose
neighborhoods have already been fetched, so an expand affordance is only
offered toward not-yet-expanded neighbors. max_body_chars optionally
elides long bodies to a lossy view (each elided node gains an elided gap
and a ground fetch-back handle).
Determinism: nodes are ordered by their address token before refs are
assigned, and gaps are emitted node-by-node in that order (each node's own
gaps in a fixed stale → unresolved → outdated → missing → elided order), so
the same neighborhood always yields the same envelope. Returns the
:class:Envelope.
Source code in zettelkasten/synapse/memdsl/render.py
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 | |