zettelkasten.coverage¶
zettelkasten.coverage ¶
Zettelkasten coverage, concept-hub, and project-render computation.
Deterministic coverage/grounding audits, cross-source concept-hub and link-mesh
suggestions, and the composite project-graph render — carved out of
:mod:zettelkasten.server for clarity. server re-exports every name here so
existing importers keep working unchanged. Server-level helpers and the graph
cache are reached through the server module object (not value-imported) so
everything resolves at CALL time against the live module, preserving behavior
and test monkeypatching. The import is safe against cycles because server
performs its re-export import of this module at end-of-file.
project_graph ¶
Get the composite graph for a project: all source notes, cross-links, and citations.
Loads every source graph in the project plus the _cross graph, and returns merged notes (with source attribution), all links, and citations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
project
|
str
|
Project name |
required |
Source code in zettelkasten/coverage.py
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 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 | |
set_coverage ¶
Set a source's processing coverage level.
Coverage tracks how thoroughly a source has been processed. coverage.agent
auto-advances none -> skimmed when the first note is added; use this tool to
record deeper progress (e.g. "full") or to set the human level.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
str
|
Source graph name |
required |
agent
|
str
|
Agent coverage: none | skimmed | full (omit to leave unchanged) |
''
|
human
|
str
|
Human coverage: none | skimmed | full (omit to leave unchanged) |
''
|
Source code in zettelkasten/coverage.py
coverage_matrix ¶
Coverage matrix for a source's notes against its schema dimensions.
Deterministic Covered/Thin/Missing per dimension tag — the model-independent
backstop the auditor reads instead of hand-building the matrix. Dimension
tags come from schema (a registry schema name) when given, else from the
rubric the extraction run persisted onto the source meta.
This is ADVISORY, not a hard gate: a source legitimately may not cover every
dimension. ok is true only when no dimension is Missing, but coverage is
not enforced anywhere — the auditor uses judgement on the matrix.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
str
|
Source graph name (folder under .zettelkasten/) |
required |
schema
|
str
|
Optional registry schema name; overrides the persisted tags |
''
|
Source code in zettelkasten/coverage.py
verify_extraction ¶
Audit a source for grounding violations (anti-invention check).
Scans every note in a source and reports where extraction may have invented
or unmoored content: quotes not confirmed verbatim against the source,
claims/findings with no supporting quote, page mismatches, and orphan quotes.
Run this before marking a source's agent coverage as "full" — that level is
gated on a clean audit (blocking_count == 0).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
str
|
Source graph name (folder under .zettelkasten/) |
required |
Source code in zettelkasten/coverage.py
suggest_concept_hubs ¶
suggest_concept_hubs(project: str, similarity_threshold: float = 0.7, min_sources: int = 2, since_source: str = '', max_suggestions: int = 10) -> str
Find implicit concept clusters across project sources.
Identifies groups of semantically similar notes from different sources that could benefit from a synthesis (concept hub) note in _cross/.
Each suggestion carries an action so the caller knows whether to grow the
_cross graph or just attach to it:
attach: an existing _cross hub already covers this theme — link the related note into that hub instead of minting a new one. This is the main guard against _cross growing without bound, so it is always preferred.new_hub: no existing hub covers the cluster — a new synthesis note in _cross/ is warranted.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
project
|
str
|
Project name |
required |
similarity_threshold
|
float
|
Minimum similarity to consider a pair related (default 0.7) |
0.7
|
min_sources
|
int
|
Minimum number of distinct sources a cluster must span (default 2) |
2
|
since_source
|
str
|
When set, only evaluate clusters involving this one source
(incremental mode). This keeps the cost O(sources) per call instead of
the full O(sources^2) sweep, so it is cheap enough to run on every
source addition. It also follows the source's own links: when a note it
links to is already covered by a hub, that hub is surfaced as an
|
''
|
max_suggestions
|
int
|
Hard cap on returned suggestions (keeps the payload light regardless of how large the project or _cross graph grows). |
10
|
Source code in zettelkasten/coverage.py
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 | |
link_mesh ¶
link_mesh(project: str, similarity_threshold: 'float | None' = None, per_note_top_k: 'int | None' = None, max_links: int = 200, max_notes_per_source: int = _MAX_NOTES_PER_SOURCE_SAFETY, dry_run: bool = True) -> str
Weave a dense cross-source related mesh across a project's sources.
The alternative to :func:suggest_concept_hubs (hub-and-spoke synthesis):
instead of minting _cross hubs, this authors DIRECT related edges
between semantically similar notes that live in different source graphs of
the project. When a source is folded into a project it has no edges to the
project's other sources yet — this creates them so the composite project
graph is actually connected.
Every authored edge is stamped origin='link-mesh' (provable ownership for
a later prune → reversible) and carries the pair's cosine similarity as its
confidence. Authoring is idempotent: a pair already linked with a
related edge across the same graphs is left untouched and counted under
skipped_existing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
project
|
str
|
Project name. |
required |
similarity_threshold
|
'float | None'
|
Minimum cosine similarity for a pair to be linked.
|
None
|
per_note_top_k
|
'int | None'
|
Cap on new mesh edges incident to any single note, so a
hub-like note doesn't monopolize the budget (strongest pairs win).
|
None
|
max_links
|
int
|
Hard cap on total edges considered/authored in one pass. |
200
|
max_notes_per_source
|
int
|
Per-source SAFETY VALVE on how many notes enter the neighbor search (guards a pathologically huge single source). Defaults high enough never to bind on a real project — it no longer caps recall the way the former small cap did. |
_MAX_NOTES_PER_SOURCE_SAFETY
|
dry_run
|
bool
|
When true (default), compute and return the pairs that WOULD be linked without writing anything. When false, author the edges. |
True
|
Source code in zettelkasten/coverage.py
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 | |
suggest_cross_connections ¶
suggest_cross_connections(project: str = '', graph: str = '', note_id: str = '', top_k: int = 8, similarity_threshold: float = 0.5, target_scope: str = 'project', include_types: 'list[str] | None' = None, min_cross_degree: int = 1, max_candidates: int = 500, max_notes_per_source: int = 200) -> str
Cross-graph connectivity engine: candidate world edges + island audit.
Surfaces, for the content notes in scope, semantically related notes in a
DIFFERENT graph that are not yet linked -- the job-2 (flat cross-graph
connectivity) candidates suggest(kind="connections") cannot find because it is
graph-local -- plus a connectivity audit flagging island graphs and
under-connected notes. READ-ONLY: the agent writes the edges it judges real
via note(action="link", ..., target_graph=
Scope (choose one):
- note_id (+ graph): one note -> the rest of the target scope.
- graph: one source graph's notes -> the rest of the target scope.
- project: every content note in the project's sources <-> each other.
- none: the whole corpus.
target_scope ('project' default | 'corpus') controls where target
notes may live; with a project it restricts targets to that project's sources.
Idempotent: already-linked pairs (a direct link in either direction, or a prerequisite) are excluded, so a re-run after the agent wires edges returns only what is still missing -- islands should trend to zero.
Source code in zettelkasten/coverage.py
1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 | |