Repository navigation
Description
Problem
nodespace search costs roughly 250 ms per result returned. On a 32,000-node database:
--limit |
wall clock |
|---|---|
| 1 | 0.32 s |
| 2 | 0.45 s |
| 5 | 1.17 s |
| 10 | 2.78 s |
| 20 | 5.03 s |
| 50 | 5.09 s |
Near-perfectly linear in the result count. The skill's default limit is 20, so a plain nodespace search takes about five seconds.
It is not what it looks like
Three hypotheses ruled out by measurement:
Not cold model load. Three consecutive identical searches: 4.22 s, 4.23 s, 4.25 s. A cold-start would show one slow run then fast ones. The cost is constant per call and paid every time.
Not query embedding. Cost tracks --limit, not query length, and embedding happens once per call regardless of how many results are returned. A 1-character query at limit 5 and a 71-character query at limit 5 differ (0.04 s vs 1.30 s) only because the short one matched fewer results above threshold — vary --limit on a fixed query and the line is straight.
Not the vector scan. Ranking 32k rows costs the same whether you return 1 or 20; sqlite-vec would brute-force that set in single-digit milliseconds. A scan does not produce a per-result slope.
Not socket or RPC overhead. nodespace query --type task --limit 5 returns in 0.00 s and nodespace diagnostics in 0.05 s against the same daemon. The transport is free.
So the cost is per-result work performed after ranking, inside the daemon.
Where it appears to be
ops::search_ops logs exactly one line for the whole call (Semantic search for: 'tech stack' (scope: Knowledge)) and then delegates to EmbeddingService::semantic_search_nodes (packages/core/src/services/embedding_service.rs:897), which calls semantic_search.
Two candidates ruled out by reading: the hydration in semantic_search_nodes is a plain filter_map over already-fetched results with no per-item await, and the title-boost loop at :698-710 is trivial string comparison. The cost is therefore in producing the KNN results with their nodes attached — most likely a per-result node fetch, or per-result aggregated-content assembly, executed serially.
The absence of any span or timing around that path is itself part of the problem: a 5-second operation emits one log line and nothing attributable.
Why it matters
Semantic search is the skill's primary discovery verb — it is what an agent runs first to orient itself in a session. Five seconds per call, several calls per session, is a large share of an agent's wall-clock budget spent waiting.
It also silently pushes agents away from the graph's best feature. An agent that learns search is slow will reach for query and node get instead, which answer narrower questions.
Note a prior benchmark in development/benchmarks/search-skills-latency.md measured a cross-type multi-skill turn at 7.2 s min / 40.5 s max — with search_skills called zero times. Whether that is related is unestablished, but both point at the same subsystem.
Acceptance criteria
- Instrument the search path so per-phase cost is attributable — query embedding, KNN, BM25, per-result hydration, ranking — rather than one log line for the whole call
- Identify the per-result work and confirm it against the measured ~250 ms/result slope — per-result work found and removed in four places; the ~250 ms/result figure did NOT reproduce at the store layer (per-result DB work measures in microseconds). See the measurements comment.
- If it is serial per-result fetching, batch it — the store already has batch node fetches
- Target: search cost dominated by a fixed per-call component, with the per-result slope near zero at these sizes
- Regression test asserting search at
--limit 20stays within a fixed budget on a seeded database, so this cannot silently return - Re-measure the 1/2/5/10/20/50 series afterwards and record it, so the improvement is evidenced rather than asserted
Reproduction
On a 32k-node database (this install, v0.2.7):
for L in 1 2 5 10 20; do
printf "limit=%-3s " "$L"
/usr/bin/time -p nodespace search "tech stack" --limit $L >/dev/null
doneContext
Surfaced by an external agent that noticed a 4.2 s search against a 29 ms node export and asked whether that was fast. Its diagnosis was cold model load; the measurements above rule that out and point at per-result work instead.
Activity
malibio commentedon Sep 8, 2026
Frontend baseline: 233 test files passed, 4900 tests passed (Duration 81.11s).
malibio commentedon Sep 8, 2026
Measurements and findings
All numbers from a release build (
cargo test --release) on a seeded 32,000-node corpus (matching the reproduction size), best of 3 runs per limit. Seeding: 32ktextnodes, each with a paragraph of body content and one 768-dim embedding chunk, inserted through the normalcreate_node+upsert_embeddingsstore API into a temp SQLite database.Instrumentation added first (AC 1)
semantic_searchnow emits a structured per-phase profile —embed_ms,knn_ms,bm25_ms,search_ms,tier3_hydrate_ms,total_ms— instead of one opaque duration.search_embeddingsemits its ownknn_ms/score_ms/hydrate_mssplit plus candidate andkcounts. KNN and BM25 are timed inside thetokio::join!so each leg is attributable even though they overlap in wall clock.What the instrumentation showed
The search path had per-result work in four places, all the same shape (one query per result, serial):
search_embeddings— oneget_nodeper surviving candidate, before truncation, so it also hydrated rows ranking then discarded.search_embeddings_by_node_type— same loop.get_nodeper root.SearchNodeshandler — re-read every result from the store by id, discarding the nodes search had already fetched.Before / after (release, 32k corpus, best of 3)
--limitCost is dominated by the fixed ~27 ms KNN scan; the per-result slope is ~0.18 ms/result at limit 50 and within noise at limit 20.
Finding that differs from the issue's hypothesis
The ~250 ms/result slope did not reproduce at this layer, and the per-result DB work is not large enough to explain it. Measured individually on the 32k corpus:
get_nodere-fetch: 0.007 ms per result (0.14 ms at limit 20)get_related_nodesper result: 0.01 ms each (graph_boost / include_edges, both default false)get_subtree_dataper result: 6.4 ms each — by far the largest per-result cost, but it is capped atinclude_markdown(default 1, max 5) and the CLI path passesinclude_markdown: 0, so it cannot produce a slope that scales to limit 50So the loops fixed here are the right shape — work that grows with result count rather than corpus size — and removing them is correct, but they do not by themselves account for the reported 250 ms/result. The remaining candidate is above the store layer (embedding-model or daemon-side behavior on the live install, which this harness does not exercise). The per-phase profile is what makes that attributable next time rather than requiring a fresh investigation.
Regression test
packages/core/tests/search_result_scaling_test.rs, 4 tests over a 2,000-node seeded corpus:limit, not the candidate set, and results stay rank-ordered.Tests pass in both debug and release.
malibio commentedon Sep 8, 2026
Closed by #2452, but the reported symptom is not fixed — tracking in #2455.
#2452 removed five per-result fetch loops and added per-phase instrumentation to the search path. That work is real, but the ~250ms/result slope this issue reported did not reproduce: measured release on a 32k-node corpus it was flat before the change (27.6ms at limit 1, 30.2ms at limit 20) and flat after, with per-result store work at 0.007ms — three orders of magnitude too small to explain 0.32s→5.03s.
So the loops were the right shape to remove and were not the reported cost. #2455 carries the unexplained remainder: the measurements, what the in-process harness did not exercise (gRPC transport, real embedding generation, cold state, concurrent daemon load), and the strongest lead — a blocking
generate_embedding()call inside an async fn with nospawn_blocking, which can stall a live daemon's runtime in ways an in-process benchmark never shows.