Repository navigation
feat(prime): add prime.exclude_types for the Key concepts section - #121
weshofmann wants to merge 2 commits into
Conversation
`kin prime` fills "Key concepts" from a search on the topic it detects from the working directory. Auto-captured session nodes are titled after that same directory, so they match the topic and can take every slot with near-identical stubs, crowding out real concepts. prime.exclude_types names node types to leave out. They are excluded through hybrid_search's node_filter, so they never take a slot in the candidate window and the next matches fill the section; filtering the results afterwards would leave it empty when every hit is excluded. The same filter keeps excluded types out of the neighbor titles shown beside each entry. It chooses entries, not caveats: an imported Kinbase fact's open Unknowns are re-attached unfiltered, so excluding question never strips them. Constraints, watches, directives and recent activity are unaffected. The default is empty and the search runs unfiltered, as before. An unknown type name is refused at config load, as other invalid values are, rather than silently matching nothing. The key is user-config only (added to _PROJECT_LAYER_UNTRUSTED_KEYS): a repository's .kin/config could otherwise hide node types from the prime of everyone working in it, without their seeing it.
There was a problem hiding this comment.
Confidence Score: 2/5
Summary
Score reconciled from 4/5 because the review includes a blocking finding.
Adds user-only prime.exclude_types that filters Key concepts inside hybrid_search; default is a no-op and tests cover refill, neighbours, Unknowns and authority. Low code risk, but the documented enablement command fails as written.
Important Files Changed
| File | Overview |
|---|---|
| src/kindex/config.py | New PrimeConfig with type validation; prime added to project-untrusted keys |
| src/kindex/hooks.py | Passes node_filter to hybrid_search; re-attaches Unknowns unfiltered when excluding |
| README.md | Documents the key; quoted kin config set --global invocation errors |
| kin.sample.yaml | Commented example; same broken --global ordering |
| CHANGELOG.md | Unreleased/Added entry |
| tests/test_hooks.py | TestPrimeExcludeTypes covers default, refill, neighbour, Unknowns, validation |
| tests/test_clone_config_authority.py | Repo .kin/config prime value ignored and recorded |
Reviewed 528566c...9629512 · ↻ Re-run review · View in Adapt
| shown. Constraints, watches, directives and recent activity are unaffected. An | ||
| unknown type name is refused when the config loads. Only your own config sets | ||
| it; a repository's `.kin/config` cannot hide node types from your prime, so | ||
| set it with `kin config set --global prime.exclude_types session` or in |
There was a problem hiding this comment.
Verified: kin config set --global prime.exclude_types session exits 2 with "unrecognized arguments" (argparse consumes the nargs='?' positionals before --global); document kin config --global set prime.exclude_types session instead.
| # auto-captured session nodes, titled after the working directory, match the | ||
| # detected topic and crowd out real concepts. Unknown type names are refused. | ||
| # User config only: a repository's .kin/config cannot set it, so use | ||
| # `kin config set --global prime.exclude_types session` or set it here. |
There was a problem hiding this comment.
Same broken invocation as README; use kin config --global set prime.exclude_types session (or put --global last).
| def _known_types(cls, value: list[str]) -> list[str]: | ||
| from .schema import STORAGE_NODE_TYPES | ||
|
|
||
| unknown = [t for t in value if t not in STORAGE_NODE_TYPES] |
There was a problem hiding this comment.
kin config set writes the value unvalidated, so a typo like sesion makes every later kin command fail and the prime hook degrade silently; pre-validate prime.* in _config_write as sim.* already is.
| # Configured types (prime.exclude_types) are left out of the search | ||
| # itself, not dropped afterwards, so they never take a slot the next | ||
| # match could fill. With none configured the search runs unfiltered. | ||
| excluded = frozenset(getattr(getattr(config, "prime", None), "exclude_types", None) or ()) |
There was a problem hiding this comment.
The "never take a slot" claim holds for FTS and cues only: vector_search fetches top_k unfiltered and scoped_ranks drops excluded hits afterwards, so the vector channel can still be crowded out; adjust comment or filter vectors upstream.
| # imported fact keeps its open Unknowns (question nodes) | ||
| # even when questions are excluded as entries. | ||
| from .kinbase import attach_unknowns | ||
| attach_unknowns(store, r) |
There was a problem hiding this comment.
Unfiltered attach_unknowns re-queries every kinbase result whenever any type is excluded; gate on "question" in excluded and hoist the import out of the loop.
- Document `kin config --global set prime.exclude_types session`. With
--global after `set`, Python 3.10 and 3.11 argparse exit 2
("unrecognized arguments"); the leading form works on 3.10-3.14.
- `kin config set prime.*` validates before writing, as `sim.*` does,
so a typo is refused instead of saved and failing every later load.
- Correct the refill claim: text and recall-cue candidates are admitted
through the filter, but the vector channel fetches top_k before
filtering, so excluded types can still use up its share.
- Re-attach Kinbase Unknowns only when `question` is excluded, with the
import hoisted out of the loop.
|
Addressed the review in 264685d:
Full suite: 4968 passed, 4 skipped; the new tests also pass on Python 3.10. |
Problem
kin prime --for hookfills "Key concepts" from a search on the topic it detects from the working directory. Auto-captured session nodes are titled after that directory (for exampleSession: -home-dev-notes), so they match the topic too. Once enough of them accumulate, they take every Key concepts slot with near-identical stubs and crowd out the concepts the section is for. No setting controls this today.Change
A new
primeconfig section with one key:hybrid_searchas anode_filter. Text and recall-cue candidates are admitted through it, so excluded types don't take their places and the next matches fill the section. Dropping them from the results afterwards would leave the section short, or empty when every hit is excluded. The vector channel still fetchestop_kbefore filtering, so excluded types can use up its share; filtering vectors earlier would change shared retrieval code for every caller.node_filteralso applies to the[...]neighbor titles beside each entry, so an excluded type isn't named there either. (Session nodes already never appear there, because their edges aren't semantic.)hybrid_searchalso usesnode_filterwhen it attaches an imported Kinbase fact's open Unknowns, which are question nodes. So whenquestionis excluded, the prime re-attaches them without the filter, and excludingquestionstill leaves a fact's "Unknown [open]" line in place.[]. No filter is passed and the prime is unchanged.ValidationErrorat config load, like other invalid values, instead of silently matching nothing.kin config set prime.*validates before writing, assim.*does, so a typo is refused rather than saved. A single type can be given as a bare string, ascode_ingest.excludeallows, sokin config --global set prime.exclude_types sessionworks. (--globalgoes beforeset: after it, Python 3.10 and 3.11 argparse reject the command.)primeis in_PROJECT_LAYER_UNTRUSTED_KEYS, so a repository's.kin/configcan't quietly hide node types from the prime of everyone working in it. Loosening that later is easy; tightening it after a release would be a breaking change.Docs
CHANGELOG.md: an entry under Unreleased / Added.README.md: the key in the configuration example, plus a paragraph after it that says to set it with--global.kin.sample.yaml: a commented example.Tests
New
TestPrimeExcludeTypesintests/test_hooks.py:exclude_types: [session]and more matching sessions than slots, no session entry appears and both real concepts fill the freed slots.decisionneighbor, which the default config does name.questionkeeps an imported fact's open Unknown on its entry.constraintleaves Active constraints untouched.Config(...)and throughload_configon akin.yaml.kin config setrefuses an unknown type without writing the file, and writes a valid one.New test in
tests/test_clone_config_authority.py: a repository's.kin/configvalue is ignored and recorded in_ignored_project_keys, and the user's own value still applies.The refill, neighbor and Unknowns tests fail without the change. The full suite passes:
pytest tests/ -n auto --dist loadfile --timeout 300(4968 passed, 4 skipped), andmake lintis clean. The new tests also pass on Python 3.10.