Skip to content

Schema retrieval embeds only the current message, missing 38% of follow-ups #1810

Closed

Description

@malibio

Overview

The RELEVANT ENTITY TYPES context block is built by embedding the current user message alone. Follow-up turns that reference an entity by pronoun or ellipsis retrieve nothing, and the model then has no legal node_type to supply. Blending the last two turns into the retrieval query takes recall from 77% to 100% at zero token and latency cost.

Problem Statement

packages/daemon/src/services/local_agent_service.rs:434 calls build_workspace_context(..., Some(&user_message)) — the current message only. packages/core/src/ops/context_ops.rs embeds that string and runs a KNN over schema nodes at SCHEMA_SIMILARITY_THRESHOLD = 0.2, MAX_SEMANTIC_SCHEMAS = 5.

"Set the Redwood one to rejected" carries no lexical signal for its target type; the discriminating words were in the previous turn. When retrieval misses, the block is empty or wrong — and agent_guidance.rs tells the model that a type absent from the block does not exist, so a miss actively invites a duplicate schema rather than degrading gracefully.

Conversation history is already available in the session; it is simply not used for retrieval.

Evidence

Measured with the production embedding model, 13 multi-turn conversations, recall@5 (was the needed schema in the block at all):

strategy follow-up topic switch overall
current message only (today) 62% 100% 77%
latest + last 2 turns, blended 100% 100% 100%
current-wins-then-history-fills 62% 100% 77%
  • Failures are pronoun/ellipsis references: "Set the Redwood one to rejected", "Which ones are still out?", "Add one for Strange Loop in September"
  • Not confined to create-vs-reuse. Recall by operation under today's approach: instance 75%, query 80%, update 75%. node_type is required by search_nodes/update_node/resolve_query alike
  • No trade-off observed — topic-switch recall stayed at 100%; the latest message still dominates and the cap is 5, not 1
  • "Current wins, history fills" is a dead end — identical to today, because the permissive 0.2 threshold already returns 5 matches so no slots are ever free

Do not implement entity extraction

An LLM preprocessing step that extracts the entity before embedding was measured and hurts: recall 100% → 73%, plus 322 ms per turn. The model abstracts "Who still owes me money?" to "Record", discarding the discriminating words. Concatenating raw turns works because it preserves the surface words the embedder needs.

Acceptance Criteria

  • The retrieval query concatenates the last 2 conversation turns with the current message
  • Raw text only — no summarization, extraction, or rewriting
  • Emitted prompt tokens unchanged; this affects the embedding input, not the rendered block
  • Tests cover a pronoun-reference follow-up, an ellipsis follow-up, and a topic switch (asserting no regression on the last)

Architecture Impact

Independent of the ADR-038 routing work; ships standalone. Highest value-to-effort item from the prompting spike — a call-site change at local_agent_service.rs:434 plus a signature change in context_ops.rs.

Activity

  1. malibio commented on Jul 30, 2026

    @malibio
    CollaboratorAuthor

    Frontend baseline: 171 test files passed, 4112 tests passed (Duration 46.40s)

  2. self-assigned this
    on Jul 30, 2026
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