zettelkasten.papers¶
zettelkasten.papers ¶
Papers-view payload assembly: the EXPOSURE layer over the syllabus engine.
:mod:zettelkasten.syllabus is the deterministic, LLM-free scoring/trend/theme
engine. This module is the thin seam that turns its primitives into the single
JSON payload the Papers view consumes — exactly once, in one place, so the MCP
build_syllabus tool and the dashboard's /papers endpoints can never
drift. Like :mod:zettelkasten.framing it is parametrized by a get_graph
callable (the MCP server and the dashboard keep separate graph caches) and is
pure given its inputs: every score is a reproducible function of the corpus.
The engine is scoped only by project (a source list) or globally. A single
graph is a one-source scope the public engine does not express directly, so
:func:_graph_scoped_corpus realises it by driving :func:build_corpus with a
get_graph restricted to the target graph (every other source raises and is
skipped, so endorsement edges, PageRank, and the referenced-citation pool are
all confined to that one graph) and then keeping only the works the graph
actually engages with. That yields the same single-source semantics a one-source
project would, without touching the locked engine.
Semantic inputs the engine cannot derive itself — note embeddings and cluster
membership — are accepted as explicit work_id → … mappings (the same
convention the engine's :func:interestingness/:func:situate use). The
dashboard supplies them (projected from its note-level embedding/cluster
machinery); the MCP server omits them and the corresponding fields degrade to
null rather than failing. relation_edges and landscape hubs ARE derivable
from the graph's own links, so this module derives them for both callers.
assemble_papers ¶
assemble_papers(get_graph: GetGraph, *, project: str = '', graph: str = '', budget: int = DEFAULT_COVER_BUDGET, suggested_only: bool = False, as_of: 'str | int | None' = '', sort: str = '', reverse: bool = False, scope_name: str = '', graphs_dir: 'Path | None' = None, namespace: Callable[[str], str] | None = None, localize: Callable[[str], str] | None = None, embeddings: 'dict[str, Sequence[float]] | None' = None, clusters: 'dict[str, str] | None' = None, now_year: int | None = None) -> dict[str, Any]
Assemble the full Papers-view payload from the syllabus engine.
Scoped to a single graph (one source) or a project (its source set),
or globally when both are empty. embeddings/clusters are optional
work_id → … mappings; when omitted (the MCP server) the embedding-driven
signals degrade to 0 and relation_edges/trends still populate
interestingness/situate. relation_edges and landscape hubs are derived
from the graph's own links for both callers.
Source code in zettelkasten/papers.py
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 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 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 | |
apply_papers_view ¶
apply_papers_view(payload: dict[str, Any], *, sort: str = '', reverse: bool = False, suggested_only: bool = False) -> dict[str, Any]
Apply the per-request sort/reverse/suggested_only view over a base payload.
:func:assemble_papers already scores every work and (when called with the
default sort="", reverse=False, suggested_only=False) returns the
rows in the engine's DEFAULT order (read_priority then importance,
both descending). This helper turns that one scored base payload into the
view a specific request wants — WITHOUT rescoring — so a sort/filter toggle
is a cheap O(n) reorder over a cached payload instead of a full syllabus
recompute.
Byte-identical to calling assemble_papers directly with the same
sort/reverse/suggested_only: the default order's tie-break
(read_priority, importance) is a subset of every other sort's
tie-break, so re-sorting the default-ordered rows preserves the exact
build-corpus tie order a from-scratch sort would produce. Non-works fields
(themes, key_claims, suggested_set, counts, …) are independent of the view and
are carried through unchanged. The input payload is never mutated — the
top-level dict and the works list are copied — so a shared cache entry
stays reusable across requests.
The DEFAULT view (no sort, no reverse, no filter) is returned AS-IS — the same object — because the base payload is already assembled in that exact order. This keeps the cache-hit contract "an unchanged corpus returns the memoized object" intact for the common poll path (a repeat default request is object- identical to the cached payload, not merely equal).