Repository navigation
Description
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)
- 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`
- Forward all parameters in `exec_search_semantic()` by reading them from `SearchSemanticParams` and mapping them to `SearchSemanticInput` fields instead of hardcoding `None`.
- Note: `SearchSemanticParams` is already the deserialization target, so the struct fields just need to be forwarded.
Phase 2: Add include_edges parameter (both paths)
- Add `include_edges: Option` to `SearchSemanticParams` (MCP params struct in `packages/core/src/mcp/handlers/search.rs`).
- Add `include_edges: Option` to `SearchSemanticInput` (ops struct in `packages/core/src/ops/search_ops.rs`).
- 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.
- Update the MCP handler (`handle_search_semantic`) to pass `include_edges` through to the ops input.
- Update the local agent tool definition and executor to expose and forward `include_edges`.
Phase 3: Add graph_boost parameter (both paths)
- Add `graph_boost: Option` to both `SearchSemanticParams` and `SearchSemanticInput`.
- 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`.
- 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:
- Declaring them in the local agent's JSON schema (`def_search_semantic`)
- Forwarding them in the local agent's executor (`exec_search_semantic`)
- Forwarding them in the MCP handler (`handle_search_semantic`)
- 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 | ✅ | ❌ | ✅ | ✅ | |
| collection_id | ✅ | ❌ | ❌ | ✅ | ✅ |
| exclude_collections | ✅ | ❌ | ❌ | ✅ | ✅ |
| include_archived | ✅ | ❌ | ❌ None | ✅ | ✅ |
| scope | ✅ | ❌ | ❌ None | ✅ | ✅ |
| node_types | ✅ | ❌ | ❌ | ✅ | |
| property_filters | ✅ | ❌ | ❌ | ✅ | |
| 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
- Fix local agent document reading (get_node markdown, search_semantic, prompt tuning) #1081 (introduced local agent search_semantic tuning, reference implementation context)
- Fix e2e tool coverage gaps in ollama_integration tests and search_nodes prompt bias #1083 (local agent tool coverage — search_semantic parameter gaps affect e2e test coverage)
- Fix search_nodes: use title index, compose node_type filter, and expose property filters #1084 (search_nodes parameter exposure — same pattern of local agent schema gaps)
Activity
malibio commentedon Apr 11, 2026
Baseline: Frontend 128 test files, 3918 tests passed. Starting implementation of all 3 phases.
Feature: search_semantic graph-aware enhancements - include_edges, gr…
Address review: fix doc mismatch, cache duplicate edge lookups, add s…
malibio commentedon Apr 14, 2026
PR #1101 merged. All acceptance criteria met (29/29 after addressing review). Pragmatic review passed clean after one round of fixes.
Unify search_semantic: update prompts, fix stale comment, complete pa…
Unify search_semantic: update prompts, fix stale comment, complete pa…
Fix: unify search_semantic params - wire all fields through local age…
Feature: search_semantic graph-aware enhancements (closes #1085) (#1101)
Unify search_semantic: update prompts, fix stale comment, complete pa…
Fix: unify search_semantic params - wire all fields through local age…