Skip to content

perf(query): skip absent terms during CLI full scans - #5430

Closed
Max17190 wants to merge 1 commit into
Graphify-Labs:v8from
Max17190:perf/skip-absent-query-terms
Closed

Max17190 wants to merge 1 commit into
Graphify-Labs:v8from
Max17190:perf/skip-absent-query-terms

Conversation

@Max17190

@Max17190 Max17190 commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Why

When the trigram guard selects a full scan, the CLI scores every term against every node, including terms whose trigrams are missing. Fixes #5429.

Summary

  • Skip impossible per-term checks using the index built for the current unseeded CLI query.
  • Keep the original term count and whole-question score. Graph files with an inherited index use stock scoring.
  • Cover full rankings, per-term seeds, and the inherited-index fallback.

Related work includes the trigram prefilter in #1431 and the opt-in SQLite snapshot in #5383.

Evidence

Five alternating fresh CLI pairs per workload on Apple M5, CPython 3.13.9, v8 at 013a6461. Each pair matched stdout, stderr, and exit status.

Workload Stock median (range) Patch median (range)
#5429 reproduction, 512 absent terms 1.00 s (0.96 to 1.07) 0.23 s (0.21 to 0.24)
Guava ordinary query 3.43 s (3.09 to 3.57) 3.43 s (3.11 to 4.16)
Guava, 1,024 absent terms 22.92 s (22.13 to 29.08) 4.92 s (4.35 to 7.80)

The long misses are controlled stress cases. Ordinary-query ranges overlap. This optimization applies to full scans where the index rules out terms.

Test Plan

  • uv run --frozen pytest tests -q --tb=short (11,888 passed before a test-only edit)
  • uv run --frozen pytest -q tests/test_query_cli.py tests/test_serve.py
  • uv run --frozen ruff check .
  • uv run --frozen pyright (same 772 upstream diagnostics)
  • uv run --frozen graphify update .

The focused query suite passed on Python 3.11, 3.12, 3.13 and 3.14 on macOS, with 310 tests per version.

The seven hosted watcher failures under /dev/shm also occur on the exact upstream v8 base.

Use the trigram index built for the current CLI invocation to skip terms
that cannot contribute to literal scoring. Keep the original coverage
denominator, whole-question scoring, and behavior for imported indexes.

Refs Graphify-Labs#5429

Co-Authored-By: Codex <[email protected]>
@Max17190
Max17190 requested a review from safishamsi as a code owner November 24, 2026 01:11
@github-actions

Copy link
Copy Markdown

Thanks for the pull request, @Max17190. A maintainer will review it soon.

Want to talk it through while it is in review? Come join us on our Discord server. For longer-form discussion there is also GitHub Discussions.

A couple of things that speed up review: make sure the test suite passes on Python 3.11 and 3.13, and that the change keeps extraction deterministic.

@github-actions github-actions Bot added the contributor Pull request from a returning community contributor label Nov 24, 2026

@graphify-labs graphify-labs Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Graphify review View in Graphify

Nothing blocking · 4 possible issues to check · Merge confidence 5/5

4 possible issues to check · High impact

The CLI marks unseeded queries with no cached trigram index for a one-shot optimization.

4 possible issues we couldn't confirm
  • A persisted search index that is present but missing postings for the loaded rows still disables the one-shot query flag · graphify/cli.py:2296
  • Skipping absent terms can drop source-file, rationale and attribute matches that the trigram index may not cover · graphify/serve.py:814
  • New CLI test node omits community and location attributes that other query fixtures set, so it may fail on an unrelated missing-key error · tests/test_query_cli.py:61
  • +1 more in Graphify

They don't change the score.

What this review covered
  • Some lookups asked for files or lines that do not exist; the review was told and carried on.
  • 4 of 4 changed files inspected. This is scope, not a correctness guarantee.
Code graph · 1203 functions depend on this change
  • 2 functions became more coupled. main() (130 callers), _score_query() (26 callers).
  • 66 of 620 test files are affected by this change.
  • Gate, test list and every flagged function: in the Graphify check.

Reviewed 4f8f74d · Full report in the Graphify check

safishamsi added a commit that referenced this pull request Nov 24, 2026
…batch

Fold the Python-lambda (#5417), Go-import-shadow (#5411) and COBOL GO-TO
(#5423) AST-output changes into one combined _AST_CACHE_SCHEMA bump 53 -> 54,
so cached Python/Go/COBOL extractions re-run. Fix the #5422 regression test's
cwd-fragile `query` assertion to check the queried node (returncode==0 is the
real invariant). 0.9.119 changelog and version bump. The headline is the
#5320 anyio regression fix (graph commands broke on core installs in 0.9.118).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@safishamsi

Copy link
Copy Markdown
Member

Landed in v0.9.119 via an authorship-preserving cherry-pick. A CLI full-graph scan now skips query terms that are provably absent (no trigram present), so a long question stops wasting time on terms that can match nothing; results are byte-identical. Thanks @Max17190!

@safishamsi safishamsi closed this Nov 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contributor Pull request from a returning community contributor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Long CLI queries repeat scoring for absent terms during a full scan

2 participants