feat(8191): knowledge reaches a session from every project, ranked below its own and labelled
CI & Build / TypeScript typecheck (push) Successful in 32s
CI & Build / Plugin hooks (push) Successful in 17s
CI & Build / Python lint (push) Successful in 3s
CI & Build / Python tests (push) Failing after 2m0s
CI & Build / Build & push image (push) Canceled after 0s
CI & Build / integration (push) Canceled after 2m7s
CI & Build / TypeScript typecheck (push) Successful in 32s
CI & Build / Plugin hooks (push) Successful in 17s
CI & Build / Python lint (push) Successful in 3s
CI & Build / Python tests (push) Failing after 2m0s
CI & Build / Build & push image (push) Canceled after 0s
CI & Build / integration (push) Canceled after 2m7s
A per-kind reach beside the kind-by-moment table (setting record_reach, default snippet/note/process/lesson) widens the passive note arms and their slots to the user's other projects. A record from elsewhere gives up 0.05 before the floor and the ranking, and its line names the project. Work kinds stay in their project, the visibility clause is unchanged, and an explicit project search still means that project. Settings > Moments edits the reach. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -184,6 +184,19 @@ def _cosine_similarity(a: list[float], b: list[float]) -> float:
|
||||
# name, and a superseded record is demoted, never hidden.
|
||||
_SUPERSESSION_PENALTY = 0.05
|
||||
|
||||
# What a record from another of the user's projects gives up against one from
|
||||
# the project being worked in (`cross_kinds` on `semantic_search_notes`).
|
||||
#
|
||||
# Taken off the score BEFORE the floor, unlike supersession: a record from
|
||||
# elsewhere has to be that much closer to be offered at all, as well as
|
||||
# ranking below an equally close one from here. Offered at the same bar, a
|
||||
# corpus of many projects would fill every menu with near-misses from
|
||||
# unrelated work, which is what keeping searches in their project was first
|
||||
# for. The size is the supersession penalty's: enough to settle a near-tie in
|
||||
# favour of the work's own project, small enough that a record from elsewhere
|
||||
# that answers clearly still reaches it.
|
||||
_CROSS_PROJECT_PENALTY = 0.05
|
||||
|
||||
# Candidates fetched per requested result when a re-rank follows. Three ranks of
|
||||
# headroom is far more than a 0.05 penalty can move anything through in a corpus
|
||||
# whose neighbours sit ~0.01-0.02 apart.
|
||||
@@ -944,9 +957,18 @@ async def semantic_search_notes(
|
||||
system_id: int | None = None,
|
||||
report: dict | None = None,
|
||||
record_kinds: Sequence[str] | None = None,
|
||||
cross_kinds: Sequence[str] | None = None,
|
||||
) -> list[tuple[float, Note]]:
|
||||
"""Return up to *limit* (score, note) pairs most relevant to *query*.
|
||||
|
||||
`cross_kinds` (kind×moment vocabulary) are the kinds a project-scoped
|
||||
search also takes from the caller's OTHER projects: knowledge reaching
|
||||
the work wherever it was learned (`record_kinds.reach_for`). Given, it
|
||||
replaces the GLOBAL_NOTE_TYPES carve-out (a lesson crosses when the list
|
||||
says so), and every record from outside `project_id` gives up
|
||||
`_CROSS_PROJECT_PENALTY` before the floor and the ranking. None leaves
|
||||
the project filter as it is; it means nothing without `project_id`.
|
||||
|
||||
`record_kinds` narrows to the kinds of the kind×moment table
|
||||
(`record_kinds`: `snippet`, `task:issue`, …), the vocabulary the
|
||||
injected arms filter by. It composes with every other filter.
|
||||
@@ -1063,10 +1085,17 @@ async def semantic_search_notes(
|
||||
stmt = stmt.where(Note.project_id.is_(None))
|
||||
elif project_id is not None:
|
||||
in_project = Note.project_id == project_id
|
||||
if include_global_kinds:
|
||||
if cross_kinds is not None:
|
||||
# Which kinds cross is the caller's (the user's reach);
|
||||
# whose records they are stays the visibility clause's.
|
||||
if cross_kinds:
|
||||
from grimoire.services.record_kinds import kinds_clause
|
||||
in_project = or_(in_project, kinds_clause(cross_kinds))
|
||||
elif include_global_kinds:
|
||||
in_project = or_(
|
||||
in_project, Note.note_type.in_(GLOBAL_NOTE_TYPES)
|
||||
)
|
||||
if include_global_kinds:
|
||||
# Family canon crosses the project
|
||||
# line the same way a lesson does, but only to a project
|
||||
# on one of the idea's platforms: the canon ideas reaching
|
||||
@@ -1175,6 +1204,16 @@ async def semantic_search_notes(
|
||||
"index": int(chunk_index),
|
||||
"text": chunk_text or "",
|
||||
}
|
||||
# A record from another project gives up its penalty here, before the
|
||||
# floor and the report, so the best score reported is one the bar could
|
||||
# actually have accepted. The sort is stable: equal scores keep the
|
||||
# distance order.
|
||||
if cross_kinds is not None and project_id is not None:
|
||||
scored = [
|
||||
(score - _CROSS_PROJECT_PENALTY if note.project_id != project_id else score, note)
|
||||
for score, note in scored
|
||||
]
|
||||
scored.sort(key=lambda pair: pair[0], reverse=True)
|
||||
# The best score anything reached, bar or no bar. Recorded BEFORE the
|
||||
# filter because a call that returns nothing is exactly when it matters.
|
||||
if report is not None:
|
||||
|
||||
Reference in New Issue
Block a user