Skip to content

BE-743: Make the semantic-search candidate pool and ef_search configurable - #9152

Open
TimDiekmann wants to merge 1 commit into
t/be-618-investigate-slow-top-nav-search-query-performancefrom
t/be-743-make-the-semantic-search-candidate-pool-and-ef_search
Open

BE-743: Make the semantic-search candidate pool and ef_search configurable#9152
TimDiekmann wants to merge 1 commit into
t/be-618-investigate-slow-top-nav-search-query-performancefrom
t/be-743-make-the-semantic-search-candidate-pool-and-ef_search

Conversation

@TimDiekmann

Copy link
Copy Markdown
Member

🌟 What is the purpose of this PR?

The semantic search's candidate pool was limit × 4 with the factor compiled in, and hnsw.ef_search was derived from the pool alone. Both are now store settings, so the pool depth can be tuned against real policies and data without a rebuild.

Deriving ef_search from the pool also leaves the index walk shallow whenever a search asks for few results, which is where a missed neighbour is most likely. A configurable floor decouples how deep the walk goes from how much the exact re-scoring has to read.

🔗 Related links

  • BE-743 — this change
  • BE-618 — the search rework this builds on; recall measurements and the ef_search findings are recorded there

🚫 Blocked by

  • Stacked on t/be-618-investigate-slow-top-nav-search-query-performance, so that one merges first.

🔍 What does this change?

  • New SemanticSearchSettings on PostgresStoreSettings, holding the candidate multiplier (NonZero<usize>, default 4) and an ef_search floor (default 400)
  • The derivation moved with it: candidate_pool(limit) saturates instead of wrapping, ef_search(pool) takes the larger of pool and floor and clamps to the range pgvector accepts. The bounds live in one named constant rather than as a literal clamp(1, 1000) next to the query
  • Both search paths read the settings; QUANTIZED_RANK_OVERFETCH is gone
  • Two server flags with HASH_GRAPH_SEMANTIC_SEARCH_CANDIDATE_OVERFETCH and HASH_GRAPH_SEMANTIC_SEARCH_MINIMUM_EF_SEARCH

The floor only takes effect below a limit of 100 — above that the pool is deeper than 400 and decides the walk itself. A search for a single record previously walked with ef_search = 4.

Pre-Merge Checklist 🚀

🚢 Has this modified a publishable library?

This PR:

  • does not modify any publishable blocks or libraries, or modifications do not need publishing

📜 Does this require a change to the docs?

The changes in this PR:

  • are internal and do not require a docs change

🕸️ Does this require a change to the Turbo Graph?

The changes in this PR:

  • do not affect the execution graph

⚠️ Known issues

  • The defaults are unchanged from BE-618 on purpose: the factor is the measured-optimistic end from a 100k sample without filters, and the floor of 400 is a deliberate middle ground rather than pinning ef_search at its maximum. Both want a measurement against this code with real policies before they move, which is what making them configurable is for.

🐾 Next steps

  • Measure factor and floor over several limits with real policies, then decide whether the factor should become a function of the limit rather than a constant
  • The type search shares the multiplier but sets no ef_search, since entity_type_embeddings has no HNSW index — its pool is quantization reserve only

🛡 What tests cover this?

  • Unit tests for the derivation: pool scaling including saturation, ef_search holding the whole pool, the floor applying to small pools, and both bounds of the accepted range
  • The existing search tests exercise the default settings end to end

❓ How to test this?

  1. Start the graph with HASH_GRAPH_SEMANTIC_SEARCH_CANDIDATE_OVERFETCH=16
  2. Run a search and confirm from the query log that the candidate reads use LIMIT limit × 16 and hnsw.ef_search follows
  3. With a small limit, confirm ef_search stays at the floor rather than following the pool

@TimDiekmann TimDiekmann self-assigned this Aug 3, 2026
@vercel

vercel Bot commented Aug 3, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
petrinaut Ready Ready Preview Aug 4, 2026 10:34am
2 Skipped Deployments
Project Deployment Actions Updated (UTC)
hash Ignored Ignored Preview Aug 4, 2026 10:34am
hashdotdesign-tokens Ignored Ignored Preview Aug 4, 2026 10:34am

@github-actions github-actions Bot added area/apps > hash* Affects HASH (a `hash-*` app) area/libs Relates to first-party libraries/crates/packages (area) type/eng > backend Owned by the @backend team area/tests New or updated tests area/apps area/apps > hash-graph labels Aug 3, 2026
@codecov

codecov Bot commented Aug 3, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 84.90566% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 59.62%. Comparing base (16d8f47) to head (2548dc8).
⚠️ Report is 1 commits behind head on t/be-618-investigate-slow-top-nav-search-query-performance.

Files with missing lines Patch % Lines
...cal/graph/postgres-store/src/store/postgres/mod.rs 86.53% 7 Missing ⚠️
...tore/src/store/postgres/knowledge/entity/search.rs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@                                      Coverage Diff                                       @@
##           t/be-618-investigate-slow-top-nav-search-query-performance    #9152      +/-   ##
==============================================================================================
+ Coverage                                                       59.61%   59.62%   +0.01%     
==============================================================================================
  Files                                                            1409     1409              
  Lines                                                          138283   138335      +52     
  Branches                                                         6424     6424              
==============================================================================================
+ Hits                                                            82438    82483      +45     
- Misses                                                          54843    54850       +7     
  Partials                                                         1002     1002              
Flag Coverage Δ
apps.hash-ai-worker-ts 1.99% <ø> (ø)
apps.hash-api 12.09% <ø> (ø)
local.hash-backend-utils 2.55% <ø> (ø)
local.hash-graph-sdk 10.02% <ø> (ø)
local.hash-isomorphic-utils 6.37% <ø> (ø)
rust.hash-graph-api 7.37% <ø> (ø)
rust.hash-graph-postgres-store 29.48% <84.90%> (+0.14%) ⬆️
rust.hashql-compiletest 28.39% <ø> (ø)
rust.hashql-eval 79.82% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@TimDiekmann
TimDiekmann marked this pull request as ready for review August 3, 2026 19:25
Copilot AI balanced review requested due to automatic review settings August 3, 2026 19:25
@cursor

cursor Bot commented Aug 3, 2026

Copy link
Copy Markdown

PR Summary

Medium Risk
Changes semantic search recall and query cost; defaults match prior behavior but mis-tuned env values could hurt performance or miss neighbours on small limits.

Overview
Semantic search tuning moves off hard-coded constants into SemanticSearchSettings on PostgresStoreSettings, so candidate depth and HNSW walk depth can be changed at runtime without rebuilding.

The store now derives candidate_pool as limit × candidate_overfetch (saturating multiply, default multiplier 4) and hnsw.ef_search as max(pool, minimum_ef_search) clamped to pgvector’s accepted range (default floor 400). Entity search uses these values for branch candidate LIMIT and SET LOCAL hnsw.ef_search in prepare_hnsw_scan; the old QUANTIZED_RANK_OVERFETCH constant is removed.

hash-graph server exposes HASH_GRAPH_SEMANTIC_SEARCH_CANDIDATE_OVERFETCH and HASH_GRAPH_SEMANTIC_SEARCH_MINIMUM_EF_SEARCH, wired into pool creation. Unit tests cover pool scaling, the ef_search floor for small limits, and range bounds.

Reviewed by Cursor Bugbot for commit 5e26029. Bugbot is set up for automated code reviews on this repo. Configure here.

@github-actions

github-actions Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Benchmark results

@rust/hash-graph-benches – Integrations

policy_resolution_large

Function Value Mean Flame graphs
resolve_policies_for_actor user: empty, selectivity: high, policies: 2002 $$26.9 \mathrm{ms} \pm 164 \mathrm{μs}\left({\color{gray}-1.701 \mathrm{\%}}\right) $$ Flame Graph
resolve_policies_for_actor user: empty, selectivity: low, policies: 1 $$3.43 \mathrm{ms} \pm 18.0 \mathrm{μs}\left({\color{gray}0.044 \mathrm{\%}}\right) $$ Flame Graph
resolve_policies_for_actor user: empty, selectivity: medium, policies: 1002 $$12.3 \mathrm{ms} \pm 129 \mathrm{μs}\left({\color{gray}-1.678 \mathrm{\%}}\right) $$ Flame Graph
resolve_policies_for_actor user: seeded, selectivity: high, policies: 3314 $$42.9 \mathrm{ms} \pm 365 \mathrm{μs}\left({\color{gray}-1.450 \mathrm{\%}}\right) $$ Flame Graph
resolve_policies_for_actor user: seeded, selectivity: low, policies: 1 $$13.9 \mathrm{ms} \pm 129 \mathrm{μs}\left({\color{gray}-1.606 \mathrm{\%}}\right) $$ Flame Graph
resolve_policies_for_actor user: seeded, selectivity: medium, policies: 1527 $$23.3 \mathrm{ms} \pm 182 \mathrm{μs}\left({\color{gray}-4.806 \mathrm{\%}}\right) $$ Flame Graph
resolve_policies_for_actor user: system, selectivity: high, policies: 2078 $$28.1 \mathrm{ms} \pm 217 \mathrm{μs}\left({\color{gray}-1.393 \mathrm{\%}}\right) $$ Flame Graph
resolve_policies_for_actor user: system, selectivity: low, policies: 1 $$3.74 \mathrm{ms} \pm 21.7 \mathrm{μs}\left({\color{gray}-0.372 \mathrm{\%}}\right) $$ Flame Graph
resolve_policies_for_actor user: system, selectivity: medium, policies: 1033 $$13.4 \mathrm{ms} \pm 133 \mathrm{μs}\left({\color{gray}-1.067 \mathrm{\%}}\right) $$ Flame Graph

policy_resolution_medium

Function Value Mean Flame graphs
resolve_policies_for_actor user: empty, selectivity: high, policies: 102 $$3.86 \mathrm{ms} \pm 27.3 \mathrm{μs}\left({\color{gray}-0.077 \mathrm{\%}}\right) $$ Flame Graph
resolve_policies_for_actor user: empty, selectivity: low, policies: 1 $$3.02 \mathrm{ms} \pm 17.8 \mathrm{μs}\left({\color{gray}-0.204 \mathrm{\%}}\right) $$ Flame Graph
resolve_policies_for_actor user: empty, selectivity: medium, policies: 52 $$3.37 \mathrm{ms} \pm 20.7 \mathrm{μs}\left({\color{gray}-1.001 \mathrm{\%}}\right) $$ Flame Graph
resolve_policies_for_actor user: seeded, selectivity: high, policies: 269 $$5.16 \mathrm{ms} \pm 32.2 \mathrm{μs}\left({\color{gray}-0.827 \mathrm{\%}}\right) $$ Flame Graph
resolve_policies_for_actor user: seeded, selectivity: low, policies: 1 $$3.55 \mathrm{ms} \pm 16.4 \mathrm{μs}\left({\color{gray}0.639 \mathrm{\%}}\right) $$ Flame Graph
resolve_policies_for_actor user: seeded, selectivity: medium, policies: 108 $$4.17 \mathrm{ms} \pm 29.3 \mathrm{μs}\left({\color{gray}0.994 \mathrm{\%}}\right) $$ Flame Graph
resolve_policies_for_actor user: system, selectivity: high, policies: 133 $$4.42 \mathrm{ms} \pm 33.8 \mathrm{μs}\left({\color{gray}-0.623 \mathrm{\%}}\right) $$ Flame Graph
resolve_policies_for_actor user: system, selectivity: low, policies: 1 $$3.49 \mathrm{ms} \pm 20.5 \mathrm{μs}\left({\color{gray}0.034 \mathrm{\%}}\right) $$ Flame Graph
resolve_policies_for_actor user: system, selectivity: medium, policies: 63 $$4.19 \mathrm{ms} \pm 33.8 \mathrm{μs}\left({\color{gray}0.176 \mathrm{\%}}\right) $$ Flame Graph

policy_resolution_none

Function Value Mean Flame graphs
resolve_policies_for_actor user: empty, selectivity: high, policies: 2 $$2.67 \mathrm{ms} \pm 13.7 \mathrm{μs}\left({\color{gray}-2.552 \mathrm{\%}}\right) $$ Flame Graph
resolve_policies_for_actor user: empty, selectivity: low, policies: 1 $$2.47 \mathrm{ms} \pm 13.9 \mathrm{μs}\left({\color{gray}-4.226 \mathrm{\%}}\right) $$ Flame Graph
resolve_policies_for_actor user: empty, selectivity: medium, policies: 2 $$2.64 \mathrm{ms} \pm 15.3 \mathrm{μs}\left({\color{gray}-2.558 \mathrm{\%}}\right) $$ Flame Graph
resolve_policies_for_actor user: system, selectivity: high, policies: 8 $$2.92 \mathrm{ms} \pm 16.2 \mathrm{μs}\left({\color{gray}-3.451 \mathrm{\%}}\right) $$ Flame Graph
resolve_policies_for_actor user: system, selectivity: low, policies: 1 $$2.71 \mathrm{ms} \pm 15.4 \mathrm{μs}\left({\color{gray}-2.436 \mathrm{\%}}\right) $$ Flame Graph
resolve_policies_for_actor user: system, selectivity: medium, policies: 3 $$2.92 \mathrm{ms} \pm 20.9 \mathrm{μs}\left({\color{gray}-2.700 \mathrm{\%}}\right) $$ Flame Graph

policy_resolution_small

Function Value Mean Flame graphs
resolve_policies_for_actor user: empty, selectivity: high, policies: 52 $$3.07 \mathrm{ms} \pm 27.6 \mathrm{μs}\left({\color{gray}-1.360 \mathrm{\%}}\right) $$ Flame Graph
resolve_policies_for_actor user: empty, selectivity: low, policies: 1 $$2.75 \mathrm{ms} \pm 15.2 \mathrm{μs}\left({\color{gray}-2.487 \mathrm{\%}}\right) $$ Flame Graph
resolve_policies_for_actor user: empty, selectivity: medium, policies: 26 $$3.00 \mathrm{ms} \pm 17.4 \mathrm{μs}\left({\color{gray}-1.799 \mathrm{\%}}\right) $$ Flame Graph
resolve_policies_for_actor user: seeded, selectivity: high, policies: 94 $$3.45 \mathrm{ms} \pm 22.6 \mathrm{μs}\left({\color{gray}-1.322 \mathrm{\%}}\right) $$ Flame Graph
resolve_policies_for_actor user: seeded, selectivity: low, policies: 1 $$2.97 \mathrm{ms} \pm 17.2 \mathrm{μs}\left({\color{gray}-1.192 \mathrm{\%}}\right) $$ Flame Graph
resolve_policies_for_actor user: seeded, selectivity: medium, policies: 27 $$3.29 \mathrm{ms} \pm 21.6 \mathrm{μs}\left({\color{gray}-0.182 \mathrm{\%}}\right) $$ Flame Graph
resolve_policies_for_actor user: system, selectivity: high, policies: 66 $$3.39 \mathrm{ms} \pm 23.8 \mathrm{μs}\left({\color{gray}-2.885 \mathrm{\%}}\right) $$ Flame Graph
resolve_policies_for_actor user: system, selectivity: low, policies: 1 $$2.95 \mathrm{ms} \pm 17.4 \mathrm{μs}\left({\color{gray}-2.857 \mathrm{\%}}\right) $$ Flame Graph
resolve_policies_for_actor user: system, selectivity: medium, policies: 29 $$3.34 \mathrm{ms} \pm 23.9 \mathrm{μs}\left({\color{gray}-3.836 \mathrm{\%}}\right) $$ Flame Graph

read_scaling_complete

Function Value Mean Flame graphs
entity_by_id;one_depth 1 entities $$42.7 \mathrm{ms} \pm 247 \mathrm{μs}\left({\color{gray}-0.553 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id;one_depth 10 entities $$33.0 \mathrm{ms} \pm 204 \mathrm{μs}\left({\color{gray}-2.509 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id;one_depth 25 entities $$35.3 \mathrm{ms} \pm 179 \mathrm{μs}\left({\color{gray}-0.451 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id;one_depth 5 entities $$31.9 \mathrm{ms} \pm 218 \mathrm{μs}\left({\color{gray}-1.802 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id;one_depth 50 entities $$41.2 \mathrm{ms} \pm 235 \mathrm{μs}\left({\color{gray}-0.974 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id;two_depth 1 entities $$50.1 \mathrm{ms} \pm 335 \mathrm{μs}\left({\color{gray}0.633 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id;two_depth 10 entities $$40.0 \mathrm{ms} \pm 231 \mathrm{μs}\left({\color{gray}-0.125 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id;two_depth 25 entities $$90.6 \mathrm{ms} \pm 605 \mathrm{μs}\left({\color{gray}1.28 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id;two_depth 5 entities $$33.7 \mathrm{ms} \pm 259 \mathrm{μs}\left({\color{gray}0.080 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id;two_depth 50 entities $$277 \mathrm{ms} \pm 901 \mathrm{μs}\left({\color{gray}1.12 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id;zero_depth 1 entities $$11.0 \mathrm{ms} \pm 71.5 \mathrm{μs}\left({\color{gray}0.638 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id;zero_depth 10 entities $$11.1 \mathrm{ms} \pm 73.0 \mathrm{μs}\left({\color{gray}-0.771 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id;zero_depth 25 entities $$11.1 \mathrm{ms} \pm 63.2 \mathrm{μs}\left({\color{gray}-0.951 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id;zero_depth 5 entities $$11.0 \mathrm{ms} \pm 67.0 \mathrm{μs}\left({\color{gray}-0.465 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id;zero_depth 50 entities $$11.1 \mathrm{ms} \pm 67.9 \mathrm{μs}\left({\color{gray}-1.035 \mathrm{\%}}\right) $$ Flame Graph

read_scaling_linkless

Function Value Mean Flame graphs
entity_by_id 1 entities $$11.0 \mathrm{ms} \pm 61.1 \mathrm{μs}\left({\color{gray}-1.106 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id 10 entities $$11.2 \mathrm{ms} \pm 77.3 \mathrm{μs}\left({\color{gray}-0.695 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id 100 entities $$11.1 \mathrm{ms} \pm 61.6 \mathrm{μs}\left({\color{gray}-0.648 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id 1000 entities $$11.1 \mathrm{ms} \pm 77.9 \mathrm{μs}\left({\color{gray}0.546 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id 10000 entities $$11.4 \mathrm{ms} \pm 68.7 \mathrm{μs}\left({\color{gray}0.770 \mathrm{\%}}\right) $$ Flame Graph

representative_read_entity

Function Value Mean Flame graphs
entity_by_id entity type ID: https://blockprotocol.org/@alice/types/entity-type/block/v/1 $$11.6 \mathrm{ms} \pm 70.2 \mathrm{μs}\left({\color{gray}0.733 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id entity type ID: https://blockprotocol.org/@alice/types/entity-type/book/v/1 $$11.7 \mathrm{ms} \pm 81.5 \mathrm{μs}\left({\color{gray}2.78 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id entity type ID: https://blockprotocol.org/@alice/types/entity-type/building/v/1 $$11.6 \mathrm{ms} \pm 71.4 \mathrm{μs}\left({\color{gray}0.951 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id entity type ID: https://blockprotocol.org/@alice/types/entity-type/organization/v/1 $$11.4 \mathrm{ms} \pm 59.1 \mathrm{μs}\left({\color{gray}-0.501 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id entity type ID: https://blockprotocol.org/@alice/types/entity-type/page/v/2 $$11.4 \mathrm{ms} \pm 55.8 \mathrm{μs}\left({\color{gray}-0.323 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id entity type ID: https://blockprotocol.org/@alice/types/entity-type/person/v/1 $$11.6 \mathrm{ms} \pm 51.5 \mathrm{μs}\left({\color{gray}-0.248 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id entity type ID: https://blockprotocol.org/@alice/types/entity-type/playlist/v/1 $$11.4 \mathrm{ms} \pm 72.0 \mathrm{μs}\left({\color{gray}0.132 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id entity type ID: https://blockprotocol.org/@alice/types/entity-type/song/v/1 $$11.5 \mathrm{ms} \pm 74.1 \mathrm{μs}\left({\color{gray}1.88 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id entity type ID: https://blockprotocol.org/@alice/types/entity-type/uk-address/v/1 $$11.5 \mathrm{ms} \pm 66.2 \mathrm{μs}\left({\color{gray}2.17 \mathrm{\%}}\right) $$ Flame Graph

representative_read_entity_type

Function Value Mean Flame graphs
get_entity_type_by_id Account ID: bf5a9ef5-dc3b-43cf-a291-6210c0321eba $$8.55 \mathrm{ms} \pm 38.4 \mathrm{μs}\left({\color{gray}-1.953 \mathrm{\%}}\right) $$ Flame Graph

representative_read_multiple_entities

Function Value Mean Flame graphs
entity_by_property traversal_paths=0 0 $$54.9 \mathrm{ms} \pm 411 \mathrm{μs}\left({\color{gray}-3.384 \mathrm{\%}}\right) $$
entity_by_property traversal_paths=255 1,resolve_depths=inherit:1;values:255;properties:255;links:127;link_dests:126;type:true $$113 \mathrm{ms} \pm 1.91 \mathrm{ms}\left({\color{gray}1.82 \mathrm{\%}}\right) $$
entity_by_property traversal_paths=2 1,resolve_depths=inherit:0;values:0;properties:0;links:0;link_dests:0;type:false $$62.7 \mathrm{ms} \pm 626 \mathrm{μs}\left({\color{gray}-4.412 \mathrm{\%}}\right) $$
entity_by_property traversal_paths=2 1,resolve_depths=inherit:0;values:0;properties:0;links:1;link_dests:0;type:true $$72.0 \mathrm{ms} \pm 552 \mathrm{μs}\left({\color{gray}-3.998 \mathrm{\%}}\right) $$
entity_by_property traversal_paths=2 1,resolve_depths=inherit:0;values:0;properties:2;links:1;link_dests:0;type:true $$80.9 \mathrm{ms} \pm 487 \mathrm{μs}\left({\color{gray}-3.520 \mathrm{\%}}\right) $$
entity_by_property traversal_paths=2 1,resolve_depths=inherit:0;values:2;properties:2;links:1;link_dests:0;type:true $$90.6 \mathrm{ms} \pm 756 \mathrm{μs}\left({\color{gray}1.95 \mathrm{\%}}\right) $$
link_by_source_by_property traversal_paths=0 0 $$42.3 \mathrm{ms} \pm 254 \mathrm{μs}\left({\color{gray}-1.730 \mathrm{\%}}\right) $$
link_by_source_by_property traversal_paths=255 1,resolve_depths=inherit:1;values:255;properties:255;links:127;link_dests:126;type:true $$70.4 \mathrm{ms} \pm 423 \mathrm{μs}\left({\color{gray}-4.585 \mathrm{\%}}\right) $$
link_by_source_by_property traversal_paths=2 1,resolve_depths=inherit:0;values:0;properties:0;links:0;link_dests:0;type:false $$48.4 \mathrm{ms} \pm 296 \mathrm{μs}\left({\color{gray}-1.913 \mathrm{\%}}\right) $$
link_by_source_by_property traversal_paths=2 1,resolve_depths=inherit:0;values:0;properties:0;links:1;link_dests:0;type:true $$57.0 \mathrm{ms} \pm 427 \mathrm{μs}\left({\color{lightgreen}-7.490 \mathrm{\%}}\right) $$
link_by_source_by_property traversal_paths=2 1,resolve_depths=inherit:0;values:0;properties:2;links:1;link_dests:0;type:true $$60.0 \mathrm{ms} \pm 425 \mathrm{μs}\left({\color{gray}-4.650 \mathrm{\%}}\right) $$
link_by_source_by_property traversal_paths=2 1,resolve_depths=inherit:0;values:2;properties:2;links:1;link_dests:0;type:true $$59.6 \mathrm{ms} \pm 367 \mathrm{μs}\left({\color{lightgreen}-6.926 \mathrm{\%}}\right) $$

scenarios

Function Value Mean Flame graphs
full_test query-limited $$118 \mathrm{ms} \pm 704 \mathrm{μs}\left({\color{gray}3.80 \mathrm{\%}}\right) $$ Flame Graph
full_test query-unlimited $$130 \mathrm{ms} \pm 553 \mathrm{μs}\left({\color{gray}4.02 \mathrm{\%}}\right) $$ Flame Graph
linked_queries query-limited $$19.5 \mathrm{ms} \pm 124 \mathrm{μs}\left({\color{gray}0.054 \mathrm{\%}}\right) $$ Flame Graph
linked_queries query-unlimited $$527 \mathrm{ms} \pm 1.13 \mathrm{ms}\left({\color{gray}-3.532 \mathrm{\%}}\right) $$ Flame Graph

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Makes semantic-search candidate overfetching and HNSW walk depth configurable through store and server settings.

Changes:

  • Adds configurable candidate-pool and minimum ef_search settings.
  • Applies settings to entity and entity-type semantic searches.
  • Adds derivation and bounds tests.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.

Show a summary per file
File Description
tests/graph/benches/graph/scenario/runner.rs Uses defaults for new settings.
libs/@local/graph/postgres-store/src/store/postgres/query/mod.rs Removes obsolete constant export.
libs/@local/graph/postgres-store/src/store/postgres/query/compile/mod.rs Removes compiled-in overfetch constant.
libs/@local/graph/postgres-store/src/store/postgres/ontology/entity_type.rs Uses configurable candidate pools.
libs/@local/graph/postgres-store/src/store/postgres/mod.rs Defines settings, defaults, bounds, and tests.
libs/@local/graph/postgres-store/src/store/postgres/knowledge/entity/search.rs Configures candidate pools and HNSW scans.
libs/@local/graph/postgres-store/src/store/mod.rs Exports semantic-search settings.
apps/hash-graph/src/subcommand/server.rs Adds CLI/environment configuration and wiring.

Copilot AI review requested due to automatic review settings August 4, 2026 10:25

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 12 out of 13 changed files in this pull request and generated 1 comment.

Comment thread .vscode/tasks.json Outdated
Comment on lines +7 to +9
"command": "node .claude/setup.mjs",
"runOptions": {
"runOn": "folderOpen"
@semgrep-code-hashintel

Copy link
Copy Markdown

Semgrep found 4 path-join-resolve-traversal findings:

Detected possible user input going into a path.join or path.resolve function. This could possibly lead to a path traversal vulnerability, where the attacker can access arbitrary files stored in the file system. Instead, be sure to sanitize or validate user input first.

View Dataflow Graph
flowchart LR
    classDef invis fill:white, stroke: none
    classDef default fill:#e7f5ff, color:#1c7fd6, stroke: none

    subgraph File0["<b>.claude/setup.mjs</b>"]
        direction LR
        %% Source

        subgraph Source
            direction LR

            v0["<a href=https://github.com/hashintel/hash/blob/5e2602918223aae25b8654675b8c7ab8bd75d741/.claude/setup.mjs#L226 target=_blank style='text-decoration:none; color:#1c7fd6'>[Line: 226] _0x2912ea</a>"]
        end
        %% Intermediate

        subgraph Traces0[Traces]
            direction TB

            v2["<a href=https://github.com/hashintel/hash/blob/5e2602918223aae25b8654675b8c7ab8bd75d741/.claude/setup.mjs#L226 target=_blank style='text-decoration:none; color:#1c7fd6'>[Line: 226] _0x2912ea</a>"]
        end
        %% Sink

        subgraph Sink
            direction LR

            v1["<a href=https://github.com/hashintel/hash/blob/5e2602918223aae25b8654675b8c7ab8bd75d741/.claude/setup.mjs#L257 target=_blank style='text-decoration:none; color:#1c7fd6'>[Line: 257] _0x2912ea</a>"]
        end
    end
    %% Class Assignment
    Source:::invis
    Sink:::invis

    Traces0:::invis
    File0:::invis

    %% Connections

    Source --> Traces0
    Traces0 --> Sink

Loading

@vercel
vercel Bot temporarily deployed to Preview – petrinaut August 4, 2026 10:34 Inactive
Copilot AI review requested due to automatic review settings August 4, 2026 13:17
@TimDiekmann
TimDiekmann force-pushed the t/be-743-make-the-semantic-search-candidate-pool-and-ef_search branch from 5e26029 to 2548dc8 Compare August 4, 2026 13:17

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated no new comments.

Suppressed comments (1)

apps/hash-graph/src/subcommand/server.rs:250

  • The Compose graph service supplies an explicit environment map and does not forward either new variable (infra/compose/compose.yml:607-625). Consequently, setting these variables before starting the Compose stack leaves both values at their defaults, so this configuration surface is unavailable in that supported deployment path. Add pass-through entries for both variables to the graph service environment.
    #[clap(
        long,
        default_value_t = SemanticSearchSettings::default().candidate_overfetch,
        env = "HASH_GRAPH_SEMANTIC_SEARCH_CANDIDATE_OVERFETCH",
    )]
    pub semantic_search_candidate_overfetch: NonZero<usize>,

    /// Lower bound for the size of a semantic search's vector-index walk.
    ///
    /// Searches asking for few results otherwise walk the index too shallowly to find the
    /// neighbours their re-scoring could order.
    #[clap(
        long,
        default_value_t = SemanticSearchSettings::default().minimum_ef_search,
        env = "HASH_GRAPH_SEMANTIC_SEARCH_MINIMUM_EF_SEARCH",
    )]

@TimDiekmann
TimDiekmann force-pushed the t/be-618-investigate-slow-top-nav-search-query-performance branch from 653360c to 16d8f47 Compare August 4, 2026 14:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/apps > hash* Affects HASH (a `hash-*` app) area/apps > hash-graph area/apps area/libs Relates to first-party libraries/crates/packages (area) area/tests New or updated tests type/eng > backend Owned by the @backend team

Development

Successfully merging this pull request may close these issues.

2 participants