Skip to content

search_semantic: expose missing opt-in parameters in local agent tool and add graph-aware enhancements #1085

Closed

Description

@malibio

Overview

The `search_semantic` tool has two call paths: the MCP handler (`packages/core/src/mcp/handlers/search.rs`) and the local agent tool executor (`packages/agent/src/local_agent/tools.rs`). These paths have diverged significantly: the MCP handler accepts and processes a rich set of parameters that the local agent tool neither exposes in its schema nor forwards to the ops layer. Additionally, both paths are missing graph-aware search enhancements (`include_edges`, `graph_boost`) that would improve result quality by surfacing relationship context alongside vector similarity results.

Problem Statement

Gap 1: Local agent tool definition is incomplete

The local agent's `def_search_semantic()` in `packages/agent/src/local_agent/tools.rs` exposes only 4 parameters in its JSON schema:

  • `query` (required)
  • `limit`
  • `include_markdown`
  • `collection`

The shared `SearchSemanticParams` struct (in `packages/core/src/mcp/handlers/search.rs`, re-exported via `nodespace_core::mcp::params`) already defines these additional parameters, fully supported by the MCP handler:

  • `threshold` — similarity cutoff (0.0–1.0)
  • `collection_id` — filter by collection ID directly
  • `exclude_collections` — exclude specific collections by path
  • `include_archived` — include archived nodes in results
  • `scope` — search scope: `"knowledge"` (default), `"conversations"`, `"everything"`
  • `node_types` — filter by specific node types (e.g. `["task", "text"]`)
  • `property_filters` — filter by node property key-value pairs

None of these are declared in the local agent's tool schema, so the LLM never knows they exist and cannot use them.

Gap 2: Local agent exec_search_semantic hardcodes missing params

`exec_search_semantic` in the local agent builds a `SearchSemanticInput` with several fields always set to `None`:

```rust
let input = search_ops::SearchSemanticInput {
query: query.clone(),
threshold: Some(SEMANTIC_THRESHOLD), // hardcoded constant, not from params
limit: Some(limit),
collection_id: None, // never forwarded
collection,
exclude_collections: None, // never forwarded
include_markdown,
include_archived: None, // always None = false
scope: None, // always None = knowledge
};
```

Even if the LLM somehow passed these parameters, the executor silently drops them.

Gap 3: Missing graph-aware enhancement parameters (both paths)

Neither the MCP handler nor the local agent tool supports:

  • `include_edges` (bool, default: false) — When true, attach the outgoing relationships of each result node to the result item. This lets the LLM understand how a found node connects to others without a separate `get_related_nodes` call, reducing round-trips in relationship-heavy queries.

  • `graph_boost` (bool, default: false) — When true, re-rank vector similarity results using graph connectivity: nodes with more incoming and outgoing relationships within the result set score higher. This surfaces well-connected, central knowledge nodes over isolated but textually similar ones. Useful when the user wants the most important/referenced node on a topic, not just the nearest embedding match.

These are opt-in (default: false) to avoid breaking existing call sites and to keep the default response payload compact.

Proposed Solution

Phase 1: Expose existing parameters in local agent tool (zero new logic)

  1. Add missing parameters to `def_search_semantic()`'s `parameters_schema` in `packages/agent/src/local_agent/tools.rs`:
    • `threshold`, `include_archived`, `scope`, `node_types`, `property_filters`, `exclude_collections`
  2. Forward all parameters in `exec_search_semantic()` by reading them from `SearchSemanticParams` and mapping them to `SearchSemanticInput` fields instead of hardcoding `None`.
  3. Note: `SearchSemanticParams` is already the deserialization target, so the struct fields just need to be forwarded.

Phase 2: Add include_edges parameter (both paths)

  1. Add `include_edges: Option` to `SearchSemanticParams` (MCP params struct in `packages/core/src/mcp/handlers/search.rs`).
  2. Add `include_edges: Option` to `SearchSemanticInput` (ops struct in `packages/core/src/ops/search_ops.rs`).
  3. In `search_ops::search_semantic`, when `include_edges` is true, fetch outgoing relationships for each result node (using `rel_ops` or `node_service.get_related_nodes`) and attach them to the node JSON as an `"edges"` array.
  4. Update the MCP handler (`handle_search_semantic`) to pass `include_edges` through to the ops input.
  5. Update the local agent tool definition and executor to expose and forward `include_edges`.

Phase 3: Add graph_boost parameter (both paths)

  1. Add `graph_boost: Option` to both `SearchSemanticParams` and `SearchSemanticInput`.
  2. In `search_ops::search_semantic`, when `graph_boost` is true, after collecting the filtered vector results, count the relationship degree (in + out edges) for each result node and blend it into the ranking score before the final sort and truncation to `limit`.
  3. Update both the MCP handler and local agent executor to pass this through.

Acceptance Criteria

Phase 1 (parameter gap closure)

  • `def_search_semantic()` in `packages/agent/src/local_agent/tools.rs` declares all parameters from `SearchSemanticParams` in its JSON schema: `threshold`, `include_archived`, `scope`, `node_types`, `property_filters`, `exclude_collections`
  • `exec_search_semantic()` forwards all parsed `SearchSemanticParams` fields to `SearchSemanticInput` (no hardcoded `None` for params that have user-facing values)
  • Local agent tool passes `include_archived` from params → ops (currently always `None`)
  • Local agent tool passes `scope` from params → ops (currently always `None`)
  • Local agent tool passes `threshold` from params → ops (currently uses a hardcoded constant `SEMANTIC_THRESHOLD` ignoring caller value)
  • Unit test: local agent executor passes `scope="conversations"` through to ops call correctly

Phase 2 (include_edges)

  • `SearchSemanticParams` struct has `include_edges: Option` field
  • `SearchSemanticInput` struct has `include_edges: Option` field
  • `search_ops::search_semantic` includes outgoing edge data in result when `include_edges=true`
  • Edge data format per result item: `"edges": [{"relationship": "...", "target_id": "...", "target_title": "..."}]`
  • MCP handler forwards `include_edges` to ops input
  • Local agent `def_search_semantic()` JSON schema exposes `include_edges`
  • Local agent `exec_search_semantic()` forwards `include_edges` to ops input
  • Default behavior (include_edges not set or false) is identical to current behavior (no regression)

Phase 3 (graph_boost)

  • `SearchSemanticParams` struct has `graph_boost: Option` field
  • `SearchSemanticInput` struct has `graph_boost: Option` field
  • `search_ops::search_semantic` re-ranks results by blending edge degree with similarity score when `graph_boost=true`
  • Blending formula documented in code comments (e.g., `combined = 0.7 * similarity + 0.3 * normalized_degree`)
  • MCP handler forwards `graph_boost` to ops input
  • Local agent tool exposes and forwards `graph_boost`
  • Default behavior when `graph_boost` not set is identical to current behavior (pure similarity ranking)
  • Unit test: graph_boost re-ranks a result set where the lower-similarity node has more connections

General

  • No existing tests broken
  • All new parameters are opt-in with backward-compatible defaults
  • Code passes `cargo clippy` and `bun run quality:fix`

Technical Notes

Shared struct across both paths

`SearchSemanticParams` is defined in `packages/core/src/mcp/handlers/search.rs` and re-exported from `packages/core/src/mcp/params.rs`. The local agent imports it via `nodespace_core::mcp::params::SearchSemanticParams`. Adding fields to this struct automatically makes them deserializable in both paths — the only work is:

  1. Declaring them in the local agent's JSON schema (`def_search_semantic`)
  2. Forwarding them in the local agent's executor (`exec_search_semantic`)
  3. Forwarding them in the MCP handler (`handle_search_semantic`)
  4. Implementing them in `search_ops::search_semantic` via `SearchSemanticInput`

Current parameter gap summary

Parameter SearchSemanticParams Local agent schema Local agent exec MCP handler Ops layer
query ✅ ✅ ✅ ✅ ✅
limit ✅ ✅ ✅ ✅ ✅
include_markdown ✅ ✅ ✅ ✅ ✅
collection ✅ ✅ ✅ ✅ ✅
threshold ✅ ❌ ⚠️ hardcoded ✅ ✅
collection_id ✅ ❌ ❌ ✅ ✅
exclude_collections ✅ ❌ ❌ ✅ ✅
include_archived ✅ ❌ ❌ None ✅ ✅
scope ✅ ❌ ❌ None ✅ ✅
node_types ✅ ❌ ❌ ✅ ⚠️ partial
property_filters ✅ ❌ ❌ ✅ ⚠️ partial
include_edges ❌ ❌ ❌ ❌ ❌
graph_boost ❌ ❌ ❌ ❌ ❌

Files to modify

  • `packages/core/src/mcp/handlers/search.rs` — Add `include_edges`, `graph_boost` to `SearchSemanticParams`; update `handle_search_semantic` to forward them
  • `packages/core/src/ops/search_ops.rs` — Add `include_edges`, `graph_boost` to `SearchSemanticInput`; implement graph edge fetching and re-ranking logic in `search_semantic`
  • `packages/agent/src/local_agent/tools.rs` — Expand `def_search_semantic()` JSON schema; update `exec_search_semantic()` to forward all params

Implementation order

Phase 1 (gap closure) can be done independently of Phases 2 and 3. Phase 3 (graph_boost) logically depends on Phase 2 (include_edges) since the degree counting uses the same relationship lookup. All three phases can be done in a single PR or split by phase.

Related Issues

Activity

  1. added
    enhancement
    on Apr 10, 2026
  2. self-assigned this
    on Apr 11, 2026
  3. malibio commented on Apr 11, 2026

    @malibio
    CollaboratorAuthor

    Baseline: Frontend 128 test files, 3918 tests passed. Starting implementation of all 3 phases.

  4. added 2 commits that reference this issue on Apr 14, 2026
    f2249ae
    0830c07
  5. malibio commented on Apr 14, 2026

    @malibio
    CollaboratorAuthor

    PR #1101 merged. All acceptance criteria met (29/29 after addressing review). Pragmatic review passed clean after one round of fixes.

  6. added 3 commits that reference this issue on Jun 22, 2026
    248590a
    6150e41
    9d565bb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

backendenhancement

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions