Skip to content

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

Backlog

Description

@Max17190

What happened?

When graphify query falls back to a full scan, it scores every term against every node. This includes terms whose trigrams are missing from the graph index. A long question can spend most of its time checking these terms before returning a result or a miss.

On a clean v8 checkout at 013a6461 (v0.9.118 runtime), the example below took 1.03 s on an Apple M5 with Python 3.13.9. It returns No matching nodes found. with exit code 4. The expected improvement is to keep that result while skipping the impossible per-term checks.

Steps to reproduce

import json
import random
import string
import subprocess
import tempfile
import time
from pathlib import Path

rng = random.Random(2909)
terms = ["".join(rng.choices(string.ascii_lowercase, k=12)) for _ in range(512)]
nodes = [{"id": f"node_{i}", "label": "widget"} for i in range(10_000)]
with tempfile.TemporaryDirectory() as directory:
    graph = Path(directory) / "graph.json"
    graph.write_text(json.dumps({
        "directed": False, "multigraph": False, "graph": {}, "nodes": nodes, "links": [],
    }), encoding="utf-8")
    start = time.perf_counter()
    result = subprocess.run(["graphify", "query", "42 " + " ".join(terms), "--graph", str(graph)])
    print(f"exit={result.returncode}, wall={time.perf_counter() - start:.3f}s")

42 forces the existing short-term fallback. The graph and question are generated locally. The reproduction uses the CLI with a saved graph.

Related work includes #1889 and #1431.

Activity

  1. github-actions commented on Nov 24, 2026

    @github-actions

    Thanks for opening this issue, @Max17190. A maintainer will take a look soon.

    If you would like to discuss it in real time, come say hi on our Discord server. For longer-form questions and ideas there is also GitHub Discussions.

    To help us triage, please make sure the report includes what you expected, what actually happened, and the steps (and a small sample) to reproduce it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions