Skip to content

Store schema descriptions as a node subtree (markdown) instead of properties.description, and embed them for semantic schema discovery #1351

Closed

Description

@malibio

Overview

Schema nodes (node_type = 'schema') currently store their human-readable description as a flat string in properties.description. This has two problems:

  1. Descriptions are not semantically searchable. SchemaNodeBehavior does not override get_embeddable_content, so a schema embeds by its content (the name, e.g. "Invoice") alone. The description sitting in properties is ignored by the embedding pipeline. A semantic search for "billing" or "track money owed" cannot find an existing "Invoice" schema — which leads to duplicate near-synonym entity types (e.g. invoice and billing created as two separate schemas).

  2. Descriptions cannot be rich. A single properties.description string cannot hold structured markdown (headers, lists, code blocks, etc.). NodeSpace models all rich content as a node subtree ("everything is a node"); schema descriptions should follow the same model.

This refactor moves the description out of properties and represents it as a child node subtree of the schema node — authored as full markdown (headers, lists, text, code blocks, …), exactly like any other rich document in NodeSpace. The existing embedding-aggregation machinery (Issue #1018) then folds the whole subtree into the schema's embedding, making schemas semantically discoverable by meaning.

Problem Statement

  • SchemaNode.description: String is parsed from properties.description (packages/core/src/models/schema_node.rs).
  • SchemaNodeBehavior has can_have_children() == false and no get_aggregated_content, so schemas are leaf nodes embedded by name only (packages/core/src/behaviors/mod.rs).
  • The semantic schema retrieval that injects "relevant entity types" into the agent prompt (packages/core/src/ops/context_ops.rs, semantic_search_nodes_of_type("schema", ...), threshold 0.4) is therefore ineffective — there is no descriptive text in the schema embedding to match against.
  • Net effect during the A/B test Gemma 4 12B (Q4_K_M) vs E4B for the local ai-chat agent #1329 model trial: the agent cannot reliably tell whether a matching schema already exists before calling create_schema, so it recreates types and produces near-duplicates.

Proposed Solution

Represent the schema description as a child node subtree (single source of truth — remove properties.description).

  1. Behavior (packages/core/src/behaviors/mod.rs, SchemaNodeBehavior):

    • can_have_children() -> true.
    • Implement get_aggregated_content() to recursively aggregate child content (reuse the existing aggregate_children_content helper used by text/header behaviors). The traversal already recurses through headers/lists/text, so a full markdown subtree is folded into the schema's embedding.
  2. Model (packages/core/src/models/schema_node.rs):

    • Remove description from the properties round-trip. SchemaNode no longer carries the description as a plain String field (the description is a node subtree fetched on demand, not an inline property).
  3. Schema creation (packages/core/src/schema/mod.rs, handle_create_schema):

    • Stop writing properties.description.
    • After creating the schema node, parse the supplied description markdown into a node subtree (via the existing markdown -> nodes pipeline, e.g. prepare_nodes_from_template / create_nodes_from_markdown) and attach it as children of the schema node.
  4. Schema update (handle_update_schema / update_schema path in packages/core/src/schema/mod.rs):

    • Editing the description edits the child subtree, not a property.
  5. Tool outputs / API:

    • CreateSchemaOutput / UpdateSchemaOutput and any gRPC/JSON surface that currently returns description must source it from the child subtree (rendered to markdown) instead of properties.description.
  6. Frontend (packages/desktop-app):

    • Wherever the schema description is read/displayed (e.g. schema-plugin-loader), source it from the child subtree rather than properties.description.
  7. Backfill / migration:

    • One-time migration: for every existing schema node lacking a description subtree, create one from its current properties.description (treat the existing string as markdown), then re-embed the schema. Applies to seeded core schemas and any user schemas in existing databases.
  8. Embedding:

    • No embedding-service change required — Phase 2 aggregation (get_aggregated_content) is already invoked by the embedding service after Phase 1; enabling it on SchemaNodeBehavior is sufficient.

Acceptance Criteria

  • SchemaNodeBehavior::can_have_children() returns true and get_aggregated_content() aggregates the full description subtree.
  • create_schema stores the description as a markdown node subtree (headers/lists/text/etc.) under the schema node, not in properties.description.
  • update_schema edits the description subtree.
  • properties.description is no longer written or read anywhere for schema nodes (single source of truth).
  • Tool outputs, gRPC/JSON surfaces, and the desktop UI read the description from the subtree.
  • A schema's embedding includes its description text; a semantic search over node_type='schema' for a synonym (e.g. "billing" -> existing "Invoice" schema) returns the existing schema above threshold.
  • Migration backfills description subtrees for all existing schemas (including seeded core schemas) and re-embeds them.
  • All existing schema tests updated; new tests cover subtree aggregation into the embedding and the synonym-search behavior.
  • Code passes bun run quality:fix.
  • Tests pass (bun run test:all).

Technical Specifications

Reference Files

  • Schema behavior: packages/core/src/behaviors/mod.rs — SchemaNodeBehavior (currently can_have_children() == false, no get_aggregated_content). Pattern to copy: TextNodeBehavior::get_aggregated_content + aggregate_children_content.
  • Schema model: packages/core/src/models/schema_node.rs — SchemaNode struct; description parsed from properties (around the get("description") call).
  • Schema ops: packages/core/src/schema/mod.rs — handle_create_schema (writes properties.description), update path, and the CreateSchemaOutput / output serialization that returns description.
  • Prompt context: packages/core/src/ops/context_ops.rs — build_workspace_context / format_for_prompt (semantic schema retrieval that becomes effective once schemas embed richly).
  • Markdown -> nodes pipeline: existing create_nodes_from_markdown / prepare_nodes_from_template for building the subtree.
  • Frontend: packages/desktop-app/src — schema description display (schema-plugin-loader).

Implementation Notes

  • The aggregation traversal (aggregate_children_content, MAX_AGGREGATION_DEPTH = 20) already recurses through child types that can_have_children(), so a full markdown subtree (headers containing lists/text) is captured.
  • Keep schema validation (field rules, title_template token checks) unchanged — only the description storage changes.

Related Issues

Non-Goals

  • Changing schema field/relationship storage (fields stay in properties).
  • Changing the embedding model or the semantic-search threshold tuning.

Activity

  1. malibio commented on Jun 6, 2026

    @malibio
    CollaboratorAuthor

    Design note: reuse the existing root-node subtree mechanism

    Schema nodes should be treated as ordinary root nodes with a body — no description-specific storage or fetch logic.

    • Reading the description: use the existing get_subtree_data(node_id) / markdown-render path (packages/core/src/markdown/mod.rs, also used by get_node(format=markdown) and search_ops). Any root node can already be fetched with its full children tree and rendered to markdown; schema descriptions are just that same body. Callers that previously read SchemaNode.description should fetch+render the subtree instead.
    • Writing the description: the markdown -> nodes pipeline builds the child subtree under the schema node, identical to how prompt/skill root nodes hold their content as children.
    • Embedding: get_aggregated_content walks the same subtree (Issue Refactor embedding service to use NodeBehavior via NodeService for content extraction #1018), so name + full description body are embedded together.

    Net: schemas become consistent with prompt nodes and skill nodes (root + children body). The SchemaNode.description: String inline field is removed rather than re-pointed at a property — there is no second source of truth.

  2. malibio commented on Jun 6, 2026

    @malibio
    CollaboratorAuthor

    Frontend baseline: 134 passed (3844 tests)

  3. self-assigned this
    on Jun 6, 2026
  4. added a commit that references this issue on Jun 6, 2026
  5. added a commit that references this issue on Jun 22, 2026
    28c66eb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions