zettelkasten.framing¶
zettelkasten.framing ¶
Question framing: reframe the existing corpus along a research question.
A research question is treated as a lens over material you already have, not a
new structure to curate. frame_question decomposes a question into facets
(either the landscape concept hubs most relevant to it, or agent-supplied
sub-questions), semantically projects the relevant notes per facet, and
characterizes each facet as established / contested / thin. It also
bundles the citations referenced by each facet's evidence.
The logic is parametrized by a get_graph callable so both the MCP server and
the dashboard backend (which keep separate graph caches) can share it.
frame_search_sources ¶
frame_search_sources(project: str, graphs_dir: 'Path | None' = None, namespace: Callable[[str], str] = lambda s: s) -> list[str]
Resolve the graphs to project a question across (sources + _cross).
graphs_dir points the source/project/cross lookups at a specific
.zettelkasten/ tree (defaults to the local GRAPHS_DIR). namespace
maps each resolved local graph name to the name the caller's get_graph
expects — for federation it prefixes <repo_id>: so the names route to the
federated repo and stay correct as source_graph on the way back.
Source code in zettelkasten/framing.py
project_query ¶
project_query(query: str, search_sources: list[str], top_k: int, get_graph: GetGraph, *, preserve_membership: bool = False, project: str = '', graphs_dir: 'Path | None' = None, extra_recall: 'Callable[[str, list[str], int, set[str]], tuple[set[str], dict]] | None' = None) -> list[Hit]
Hybrid (keyword + semantic) retrieval of notes for a query across graphs.
Per graph a semantic ranking (embeddings) and a tiered keyword ranking
(title → tag/alias → body substring, same tiering the MCP search_notes
uses) are fused with Reciprocal Rank Fusion; the per-graph fused lists are then
merged by fused rank (cosine breaks ties). This is the same hybrid the rest of
the store defaults to — it stops the sparse concept hubs from being drowned
out by the quote/finding majority in a pure-semantic top-k, and it rewards
exact factor terms (e.g. "z-score", "momentum") a vector search alone misses.
Each hit is (note_id, cosine_similarity, source_graph, keyword_tier) where
cosine_similarity is the true embedding score (0.0 when the note surfaced
ONLY via keyword) and keyword_tier is 0/1/2 for a title/tag/body match or
None when it surfaced only via embeddings. Downstream can therefore treat
an exact-term match as relevant even when its cosine is below the floor.
The similarity-recalled candidate set is then blended-reranked by
:func:zettelkasten.retrieval.rerank_hits (similarity + graph-centrality
importance + access-recency, diversified with MMR) and truncated to top_k.
To give the reranker room, the semantic channel OVER-FETCHES
(overfetch × top_k). Reranking only REORDERS the recalled set and always
returns the TRUE cosine per hit, so the relevance gate in :func:_frame_facet
(which filters on the real cosine or a high-precision keyword tier) is
preserved exactly — an importance/recency boost can never pull a sub-floor
note into a facet. When reranking is configured off (w_importance ==
w_recency == 0) the legacy fused-rank order is returned unchanged.
preserve_membership (used by :func:_frame_facet) fixes facet MEMBERSHIP
to the legacy fused-rank top_k and lets the reranker only REORDER within
it — so an importance/recency boost can never change WHICH notes are members
of a facet (it may only set their presentation order). Other surfaces leave
it False so the reranker can over-fetch and promote notes INTO the
top_k.
project and graphs_dir are threaded to the reranker so the (opt-in)
syllabus source-work importance channel scopes its cohort percentiles to the
current project (and caches per scope) rather than the global corpus.
Source code in zettelkasten/framing.py
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 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 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 480 481 482 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 | |
frame_question ¶
frame_question(question: str, get_graph: GetGraph, project: str = '', facets: list[str] | None = None, max_facets: int = 5, per_facet_k: int = 12, thin_min_results: int = 2, thin_min_similarity: float = 0.15, graphs_dir: 'Path | None' = None, namespace: Callable[[str], str] | None = None, search_sources: list[str] | None = None, extra_recall: 'Callable | None' = None) -> dict[str, Any]
Reframe the corpus along a research question. Returns a result dict.
Returns {"error": ...} on validation/empty-corpus problems. Callers
serialize as needed (the MCP tool json.dumps it; the dashboard returns it).
graphs_dir + namespace let the dashboard frame a federated repo:
sources/citations are read from that repo's .zettelkasten/ and each source
name is namespaced so the injected get_graph routes to it (read-only).
Both default to the local store, leaving the MCP tool's behavior unchanged.
search_sources overrides the project-derived source set. When supplied,
those exact source names are framed against (and get_graph must resolve
every one of them). This is how synapse frames across the memory tree +
intersecting ZK projects in a single pass — it hands in the union of each
project's sources plus the _memory source. project then only steers
curated _cross facet scoping and should normally be left empty.
Source code in zettelkasten/framing.py
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 | |