Repository navigation
Description
Overview
The `search_nodes` agent tool has three related deficiencies that make structured node lookup unreliable:
- It searches `content` via a full table scan instead of the indexed `title` field
- The `node_type` filter is silently ignored whenever a text search is active (early-return bug)
- The model has no way to filter by node properties (e.g. `status = "open"`, `company = "Acme"`)
Problem Statement
Bug 1 — Full table scan instead of index:
`search_nodes` passes a `content contains` filter to `query_nodes`, which executes:
```sql
SELECT * FROM node WHERE string::lowercase(content) CONTAINS string::lowercase($query)
```
This is a full table scan. The `title` field is BM25-indexed (`idx_node_title` in `schema.surql`) and is populated for root and task nodes — it's the correct field for name/title lookup. `content` (also BM25-indexed via `idx_node_content_bm25`) is used by hybrid semantic search, not keyword name lookup.
Bug 2 — node_type filter silently ignored:
`surreal_store.rs::query_nodes` has early-return branches for `content_contains` (line ~1800) and `title_contains` (line ~1830) that both `return Ok(...)` before the `node_type` condition is ever applied (line ~1861):
```rust
// Early-return branch — node_type never reached
if let Some(ref search_query) = query.content_contains {
let sql = "SELECT * FROM node WHERE ... CONTAINS ..."; // no node_type clause
return Ok(...);
}
// ... title_contains branch same pattern ...
// node_type only reached for non-text queries
if query.node_type.is_some() {
conditions.push("node_type = $node_type".to_string()); // never gets here
}
```
So `search_nodes(query="Review quarterly report", node_type="task")` scans all node types and ignores the filter.
Gap 3 — No property filter capability:
The agent has no tool to ask "find all open tasks" or "find customers where company = 'Acme'". The ops layer (`QueryNodesInput`) has no `filters` field exposed to the agent. The `NodeFilter.property_filters` on the service layer exists but is applied in-memory after a DB fetch — the agent can't reach it through any tool.
The `node_ops::query_nodes` function already has a `filters: Vec` in `QueryNodesInput` with support for `equals`, `not_equals`, `contains`, `starts_with`, `ends_with` operators on arbitrary property paths — but it's not exposed in the `search_nodes` tool schema.
Proposed Solution
1. Fix the DB layer (surreal_store.rs)
Replace the early-return `content_contains` and `title_contains` branches with composable WHERE clause building that respects `node_type` when set:
```sql
-- title + node_type (target)
SELECT * FROM node
WHERE title IS NOT NONE
AND string::lowercase(title) CONTAINS string::lowercase($query)
AND node_type = $node_type
LIMIT $limit;
```
2. Fix the agent tool (tools.rs)
In `exec_search_nodes`, change the filter field from `"content"` to `"title"`:
```rust
// Before
filters: Some(vec![QueryFilterItem {
field: "content".to_string(),
...
}])
// After
filters: Some(vec![QueryFilterItem {
field: "title".to_string(),
...
}])
```
Expose a `filters` parameter in the tool schema so the model can pass property filters:
```json
"filters": {
"type": "object",
"description": "Property filters as key-value pairs, e.g. {"status": "open"} or {"status": "done"}. Keys are property names, values are matched with equals.",
"additionalProperties": { "type": "string" }
}
```
Wire these through to `QueryNodesInput.filters` as `QueryFilterItem` entries with operator `"equals"`.
3. Update prompt guidance (prompt_assembler.rs)
Update the Tool Strategy Guide to explain property filtering:
```
- To find nodes by name: use search_nodes with query=
- To filter by type: add node_type="task" (or text, date, etc.)
- To filter by property: add filters={"status": "open"} or {"company": "Acme"}
- Examples: search_nodes(query="", node_type="task", filters={"status": "open"})
```
4. Update the skill_pipeline.rs Research & Search guidance
The Research & Search skill guidance prompt should also document property filter usage.
Acceptance Criteria
- `search_nodes` searches `title` field (indexed) instead of `content`
- `node_type` filter is applied correctly when title search is active (no silent discard)
- `search_nodes(query="Review quarterly report", node_type="task")` returns only task nodes matching that title
- `search_nodes(query="", node_type="task")` returns all task nodes (empty query = no title filter)
- `search_nodes` tool schema exposes a `filters` parameter for property key-value pairs
- `search_nodes(query="", node_type="task", filters={"status": "open"})` returns only open tasks
- Tool description and parameter descriptions updated to reflect title search + property filter capability
- Prompt assembler Tool Strategy Guide updated with property filter examples
- Research & Search skill guidance updated with property filter examples
- Unit tests in `surreal_store` or `node_ops` cover: title+node_type composition, title+filters composition
- E2e test `test_pipeline_search_nodes_keyword` (from Fix e2e tool coverage gaps in ollama_integration tests and search_nodes prompt bias #1083) passes reliably
- New e2e test: model calls `search_nodes` with `node_type` when asked "find all my open tasks"
- Code passes `bun run quality:fix`
- Tests pass `bun run test:all`
Technical Specifications
Files to Modify
- `packages/core/src/db/surreal_store.rs` — `query_nodes` function (~line 1800): remove early-return pattern; compose `title_contains` + `node_type` into a single WHERE clause
- `packages/agent/src/local_agent/tools.rs` — `def_search_nodes` (~line 161): add `filters` to schema; `exec_search_nodes` (~line 564): change field to `"title"`, parse and wire `filters` param
- `packages/agent/src/prompt_assembler.rs` — Tool Strategy Guide seed (~line 257): add property filter guidance with examples
- `packages/agent/src/skill_pipeline.rs` — Research & Search guidance prompt (~line 218): add property filter examples
- `packages/agent/tests/ollama_integration.rs` — add `test_pipeline_search_nodes_with_type_filter` e2e test
Key Locations
```
packages/core/src/db/surreal_store.rs:1800 — content_contains early-return (bug)
packages/core/src/db/surreal_store.rs:1830 — title_contains early-return (bug)
packages/core/src/db/surreal_store.rs:1861 — node_type condition (never reached during text search)
packages/agent/src/local_agent/tools.rs:161 — def_search_nodes (tool schema)
packages/agent/src/local_agent/tools.rs:564 — exec_search_nodes (executor)
packages/agent/src/local_agent/tools.rs:588 — field: "content" (should be "title")
packages/agent/src/prompt_assembler.rs:257 — Tool Strategy Guide
packages/agent/src/skill_pipeline.rs:218 — Research & Search guidance
### Property filter wire-up
\`node_ops::QueryNodesInput\` already has \`filters: Option<Vec<QueryFilterItem>>\` with support for arbitrary property paths via \`PropertyFilter\`. The \`exec_search_nodes\` executor should convert the \`filters\` map from the tool call into \`QueryFilterItem\` entries with operator \`"equals"\` targeting \`$.{field}\` paths.
The in-memory \`PropertyFilter\` path in \`node_service.query_nodes\` is a separate mechanism — do not use it here. Use the \`node_ops\` path which is what the agent already calls.
### Note on title field availability
\`title\` is populated for root nodes and task nodes only. Child inline-text nodes have no title. This is correct — \`search_nodes\` is for finding named nodes, not scanning content fragments. \`search_semantic\` covers content-level search.
## Related Issues
- #1083 (e2e tool coverage — \`test_pipeline_search_nodes_keyword\` depends on this fix)
Activity
[-]Fix search_nodes: use indexed title field and apply node_type filter with text search[/-][+]Fix search_nodes: use title index, compose node_type filter, and expose property filters[/+]malibio commentedon Apr 11, 2026
Frontend baseline: 3918 passed, 0 failed (128 test files)
Fix: search_nodes uses title index, compose node_type filter, expose …
malibio commentedon Apr 11, 2026
PR #1097 merged. All acceptance criteria met. Review passed clean.
Fix search_nodes: use title index, compose node_type filter, and expo…
Fix search_nodes: use title index, compose node_type filter, and expo…