Skip to content

Measure whether context-block enrichment (types, relationships, related schemas) helps #1817

Closed

Description

@malibio

Overview

Three known gaps in the per-turn context block. The code gaps are real; the behavioral benefit is unmeasured. This is filed as a measurement issue so it does not get built on the intuition that more context is better — which measurement in this system contradicts.

Problem Statement

packages/core/src/ops/context_ops.rs:150 emits schema field names only:

let field_names: Vec<&str> = schema.fields.iter().map(|f| f.name.as_str()).collect();

Three omissions follow:

  1. No field types. The model cannot tell that a status field is an enum with fixed values, or that an amount is a number
  2. No relationships. SchemaNode::relationships (packages/nodespace-types/src/schema.rs:147) is never rendered anywhere in format_for_prompt — the model is never told relationships exist as a concept
  3. No related schemas. Retrieval matches the user's message, so a type reachable only through a relationship is absent unless the message happens to name it

The model is handed a flat, disconnected list of field names and asked to produce structured, linked output.

Note the inconsistency: packages/core/src/ops/skill_ops.rs does emit types and enum values in schema_metadata. Two code paths describe the same schemas to the same model at different fidelity.

Why this needs measuring rather than implementing

Separate measurement found that adding field types to the prompt did not stop the model packing values into a free-text field instead of structured properties — argument shape is governed by tool schemas, not the context block. If enrichment is motivated by argument-shape correctness, that result predicts no effect.

The defensible motivation is different: helping the model select the right type and know which fields exist. That is a retrieval/selection concern. Frame the experiment around selection, and be prepared for "no measurable benefit, don't spend the tokens".

There is also a direct cost: a larger resident context measurably degraded behavior in this system. Enrichment works against that, so it must earn its tokens.

Prior attempts

Three attempts to measure this during the prompting spike all failed for harness reasons — arm entanglement (two arms silently producing identical blocks), scoring a three-step chain that failed upstream of the variable, and a fixture that silently retrieved the wrong schemas. No usable data was produced. Do not treat the absence of a result as a null result.

Acceptance Criteria

  • Harness validated against a known-good control before arms are run, including an assertion that each arm produces a genuinely different context block — the specific failure that wasted three prior attempts
  • Three arms measured independently: +field types, +relationships, +one-hop related schemas
  • Scenarios chosen so the variable is observable — a relationship-dependent operation must not require a multi-step chain that can fail before the block matters
  • Each arm reports accuracy delta and token cost; a gain paid for in prompt bloat may be net-negative
  • A null result is an acceptable and publishable outcome. Do not implement on a null
  • Implementation happens only for arms showing measured benefit

Architecture Impact

Deliberately sequenced last. If enrichment does help selection, it may also reduce the need for a search_skills round trip on the instance-creation path, which currently exists partly to fetch schema metadata the block could have carried.

Activity

  1. malibio commented on Jul 31, 2026

    @malibio
    CollaboratorAuthor

    Measurement complete — null on 2 of 3 axes, narrow real gain on the third

    Built a dedicated probe (context_enrichment.rs, added to the existing nodespace-nlp-experiment harness alongside schema_context.rs/schema_retrieval.rs/prompt_ablation.rs) rather than editing context_ops.rs directly, per this issue's framing as a measurement, not an implementation.

    Setup: real E4B (Gemma-4, Q4_K_M) via the same OAI-compat tool-calling path as production, tool descriptions copied verbatim from def_create_node/def_search_nodes in packages/agent/src/local_agent/tools.rs for fidelity. 8-schema corpus with relationships modeled on schema_context.rs's existing workspace. 10 scenarios, each scored on exactly one tool call (never a multi-step chain) so a miss is attributable to the block, not upstream id/date resolution. 4 arms × 3 trials = 120 generations.

    Harness-validation gate (per this issue's own acceptance criteria): debug_assert_arms_differ renders, for every scenario, baseline vs. the arm that scenario targets, and asserts they're byte-different — run automatically before any live sweep and also as a #[test]. It caught two real bugs before a single generation ran: an entangled scenario where the relationships arm rendered identically to baseline (no relationships in that schema), and a one-directional relationship-traversal bug in the "related" arm (retrieving customer alone found nothing, because only outgoing links were walked). Both fixed; the gate now passes clean.

    Results

    axis baseline targeted arm avg block size verdict
    + field types 25% (3/12) 8% (1/12) 83 → 128 chars enrichment hurt
    + relationships 0% (0/9) 0% (0/9) 83 → 102 chars null
    + one-hop related schemas 0% (0/9) 33% (3/9) 83 → 168 chars real gain, off a floor of zero

    Types: adding field types made selection worse, not better. Small n, so don't over-read the magnitude, but the direction corroborates this issue's own prior finding — type info in the prompt doesn't fix argument-shape correctness, because that's governed by tool schemas, not the context block.

    Relationships: a clean, reproducible null, and the transcripts show why — the model already reflexively treats a named counterparty ("Acme Corp") as its own entity and spawns a separate node for it, identically across every arm including baseline. Naming the relationship as a property-key hint in the block doesn't change that instinct; in one trial it made things worse by inventing an extra spurious linking node. The block isn't the bottleneck for this behavior.

    Related: the one real, reproducible signal. Telling the model that invoice/freelance_gig/equipment_item are one-hop reachable from customer measurably helps it pick the right node_type for a query that names no type at all ("What does Acme Corp still owe me?"). Still low absolute accuracy and n=9 — not enough to ship on its own, but the only axis where enrichment did what it was designed to do, at roughly double baseline's block size.

    Recommendation

    Per the acceptance criteria, this is a publishable null on two axes and does not license implementing them. Do not add field types or relationship-name enrichment to context_ops.rs::format_for_prompt. The one-hop related-schema arm is a candidate for a better-powered follow-up (more scenarios, larger n) before any implementation — not enough signal yet to justify the token cost increase at current sample size.

    Harness lives at nodespace-nlp-experiment/src/context_enrichment.rs (--experiment context-enrichment), not committed to this repo since that project is a separate, disposable measurement scratch space (no git).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions