Skip to content

Search's keyword half should match root titles, not node content at every depth #2867

Closed

Description

@malibio

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:

  1. SqliteStore::bm25_search_roots (packages/core/src/db/sqlite_store/embeddings.rs) queries node_fts, which holds content for every node regardless of depth.
  2. It resolves each hit through a recursive has_child CTE that refuses to step into a parent whose type is in NON_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.
  3. NodeEmbeddingService::semantic_search (packages/core/src/services/embedding_service.rs) merges these as Tier 3 (keyword-only) results. They are ordered by node_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):

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_TYPES and its parity test (container_type_parity_tests::non_embeddable_container_types_match_behaviors in packages/core/src/services/node_service/mod.rs) have no other consumer.
  • Widen the scope: the default Knowledge scope filter keeps only text | header | code-block | schema | table, so a title hit on a task or 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's include_title_matches path and node query --content-contains first.

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 indexes content for 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): Knowledge is defined there as text, header, code-block, schema, table. This issue extends that definition to admit titled roots such as task and 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_BOOST on vector hits): unaffected.

Acceptance Criteria

  • The keyword half of general search queries node_title_fts. No search path queries node.content via 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 task root, a date page, and an agent-guidance root.
  • nodespace search "<exact task title>" and nodespace search "<user-defined record title>" (e.g. a company named Northwind Trading) return that root.
  • A freshly seeded database returns no agent-guidance, skill or tool content, 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_TYPES and its parity test are deleted.
  • node_fts and 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: schema has no title; person and database-settings are titled but unindexed.
  • packages/skill/SKILL.md and packages/skill/references/cli.md are updated. The current guidance says a name search matches only prose and never returns tasks or typed records, which becomes false. Revisit the node query --title-contains recommendation in the same change (the CLI-change-needs-guidance rule).
  • Companion nodespace-docs edits land: data-layer.md loses the content-FTS exception, and ADR-029's Knowledge scope is updated.
  • Tests pass (bun run test:all), code passes bun 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 by node_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 in packages/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_fts DDL 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 over node_title_fts with 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, play and other system types. Allow-list the user-knowledge types rather than admitting "anything titled".
  • Do not run bare cargo test -p nodespace-core; use bun run rust:test:lib.

Related Issues

Activity

  1. added
    bug
    on Sep 23, 2026
  2. malibio commented on Sep 23, 2026

    @malibio
    CollaboratorAuthor

    Frontend: 262 files / 5264 tests passed

  3. self-assigned this
    on Sep 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

architecturebackendbug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions