Repository navigation
Description
Overview
General search's keyword half runs full-text search over node.content at every depth, then walks each hit up to a root. The walk stops below any type on a hardcoded "container" list, so a child line comes back as if it were a document. A child node has no meaning outside its root. The keyword half should match root titles (node_title_fts), which only roots carry, and return the root.
This is already the documented design (data-layer.md: "Keyword search targets documents, not body text"). The hybrid keyword half is the one place the code doesn't follow it.
Problem Statement
Observed (freshly seeded database, no user data): nodespace search "clarification before deleting" returns two bare text nodes, TOOL STRATEGY: and RESPONSE RULES:. Both are child lines of agent-guidance roots (the local agent's system-prompt templates). They come back with no parent and no context. An external agent (Claude Code, Sonnet) read these as prompt injection in 4 of 10 runs.
Mechanism:
SqliteStore::bm25_search_roots(packages/core/src/db/sqlite_store/embeddings.rs) queriesnode_fts, which holds content for every node regardless of depth.- It resolves each hit through a recursive
has_childCTE that refuses to step into a parent whose type is inNON_EMBEDDABLE_CONTAINER_TYPES=["date", "task", "collection", "agent-guidance"](packages/core/src/behaviors/mod.rs). Under one of those, the child line itself is treated as the root. NodeEmbeddingService::semantic_search(packages/core/src/services/embedding_service.rs) merges these as Tier 3 (keyword-only) results. They are ordered bynode_id, not by rank, because no score is carried.
Why the list exists and why it's stale: it encodes "each child of a date page is its own document". That rule predates titles. A parity test forces the list to equal every built-in type that is both non-embeddable and has children, which is how agent-guidance and task were swept in. Their children are parts of one document, not independent notes. Now that every root carries a title (probe below), the title is what identifies a document, and the container list has no job left.
Probe of the seeded database (children vs roots, titles, title index):
- 134 child nodes (
textandheader): 0 titled, 0 innode_title_fts. So child titles are no longer set (create_node_in_tx recomputes a child node's title as if it were a root, titling body nodes with their own text #2849 is closed). - Roots of type
skill,tool,agent-guidance,play: titled and indexed. - Anomalies:
- 19
schemaroots have no title. personanddatabase-settingsroots are titled but absent fromnode_title_fts.
- 19
Who uses this search (and so who is affected): the desktop search box (SearchSemantic RPC), the local agent's search_semantic tool, external agents via nodespace search, and agent-catalog context assembly. Skill routing, schema retrieval and nodespace skill guidance go through the typed vector lookup (semantic_search_nodes_of_type) and never touch this path.
Proposed Solution
Replace the keyword half's content search with a title search:
- Match:
node_title_fts, which holds only titled roots. Every hit is already a document, so the ancestor walk is removed. - Keep bm25 rank: carry the score, so keyword-only results are ordered by relevance instead of
node_id. - Delete the container rule:
NON_EMBEDDABLE_CONTAINER_TYPESand its parity test (container_type_parity_tests::non_embeddable_container_types_match_behaviorsinpackages/core/src/services/node_service/mod.rs) have no other consumer. - Widen the scope: the default
Knowledgescope filter keeps onlytext | header | code-block | schema | table, so a title hit on ataskor a user-defined type (e.g.company) would be discarded afterwards. Tasks and user-defined types must be admitted. node_fts: if no consumer remains after this change, delete the index, its triggers and its bootstrap DDL (packages/core/src/db/schema.rs), per the no-dead-code rule. Check the desktop search box'sinclude_title_matchespath andnode query --content-containsfirst.
Body text stays reachable through the root's embedding, which aggregates the root's descendants for text/header/schema. Losing an exact keyword match on a word that only appears in a child line is intended.
Architecture Impact
nodespace-docs/architecture/data-layer.md(§ Structured search, "Keyword search targets documents, not body text"): this issue conforms to the stated rule. It removes the exception recorded there, "The FTS index is the one surface that indexescontentfor every node regardless of depth." Companion docs edit required: delete that sentence. Also update the § Semantic Search embedding lists if the scope change affects them.nodespace-docs/decisions/029-behavior-owned-embedding.md(§5 SearchScope):Knowledgeis defined there astext,header,code-block,schema,table. This issue extends that definition to admit titled roots such astaskand user-defined types. Companion docs edit required, recorded either as a revision note on ADR-029 or in a new ADR. The same edit should state that keyword matching is title-only.decisions/040-semantic-search-ranking-formula.md(TITLE_BOOSTon vector hits): unaffected.
Acceptance Criteria
- The keyword half of general search queries
node_title_fts. No search path queriesnode.contentvia FTS. - A search can no longer return a non-root node. There is a test on a seeded tree where a word appears only in a child line under a
taskroot, a date page, and anagent-guidanceroot. -
nodespace search "<exact task title>"andnodespace search "<user-defined record title>"(e.g. acompanynamedNorthwind Trading) return that root. - A freshly seeded database returns no
agent-guidance,skillortoolcontent, root or child, for any query in the default scope. - Keyword-only results are ordered by bm25 rank, not by
node_id. -
NON_EMBEDDABLE_CONTAINER_TYPESand its parity test are deleted. -
node_ftsand its triggers are deleted if no consumer remains; otherwise the remaining consumer is named in the PR. - Every root type that general search should return carries a title and is indexed. Covers the three probe anomalies:
schemahas no title;personanddatabase-settingsare titled but unindexed. -
packages/skill/SKILL.mdandpackages/skill/references/cli.mdare updated. The current guidance says a name search matches only prose and never returns tasks or typed records, which becomes false. Revisit thenode query --title-containsrecommendation in the same change (the CLI-change-needs-guidance rule). - Companion
nodespace-docsedits land:data-layer.mdloses the content-FTS exception, and ADR-029'sKnowledgescope is updated. - Tests pass (
bun run test:all), code passesbun run quality:fix.
Technical Specifications
Reference Files
- Keyword half:
packages/core/src/db/sqlite_store/embeddings.rs,bm25_search_roots. Content FTS plus the ancestor CTE to replace. - Hybrid merge:
packages/core/src/services/embedding_service.rs,semantic_search. The tier 1/2/3 merge; Tier 3 currently sorts bynode_id. - Container list:
packages/core/src/behaviors/mod.rs,NON_EMBEDDABLE_CONTAINER_TYPES. - Parity test:
packages/core/src/services/node_service/mod.rs,container_type_parity_tests. - Scope filter:
packages/core/src/services/embedding_service.rs,matches_scope(SearchScope::Knowledge). Applied inpackages/core/src/ops/search_ops.rs,search_semantic. - Title index DDL and triggers:
packages/core/src/db/schema.rs,node_title_fts(the insert trigger skips null or empty titles).node_ftsDDL is in the same file. - Existing title lookup to reuse or align with:
packages/core/src/db/sqlite_store/nodes.rs,resolve_entities_by_title. It already does bm25 overnode_title_ftswith stop-word filtering. - External guidance:
packages/skill/SKILL.md,packages/skill/references/cli.md.
Implementation Notes
- Rank from
bm25(node_title_fts)should flow into the merge, so Tier 3 can sort by it. - Admitting titled roots into the default scope must still exclude
agent-guidance,skill,tool,playand other system types. Allow-list the user-knowledge types rather than admitting "anything titled". - Do not run bare
cargo test -p nodespace-core; usebun run rust:test:lib.
Related Issues
- create_node_in_tx recomputes a child node's title as if it were a root, titling body nodes with their own text #2849 (child nodes no longer carry titles; prerequisite, closed)
- Propagate entity resolution to the external agent surface: skill guidance, and whether a resolve verb should exist #2850 (external-agent guidance that points name lookups at
--title-contains) - Entity-grounded routing: resolve named entities to nodes before routing, so one lookup constrains skill, schema and operation #2841 (entity resolution over
node_title_fts)
Activity
malibio commentedon Sep 23, 2026
Frontend: 262 files / 5264 tests passed