Skip to content

[Bug]: query doc demotion (#4982) hurts markdown-first corpora — no way to turn it off #5084

Closed

Description

@yeochul-jeon

Summary

Since 0.9.102 (#4982, "Source nodes rank above tests and docs"), graphify query multiplies the score of every node whose source_file ends in .md (or whose file_type is document/paper, or which has no source file) by _QUERY_DEMOTE_WEIGHT = 0.3, unless the question contains doc/docs/documentation/readme.

In a repository where the knowledge itself is markdown (an LLM wiki: wiki/concepts/*.md, raw/*.md, plus a few helper scripts), the demotion lowers almost every node that holds an answer. The few code nodes and generic nodes then take the seed slots instead. There is no flag or .graphifyrc key to turn it off.

Measurement

  • Corpus: about 30k nodes, mostly markdown. 20 questions taken from the repo's own Q&A log, each with a known answer page.
  • Hit: the known page appears in graphify query "<q>" --budget 1500 output.
  • Every version was built from the same commit in its own venv.
version hits / 20
0.9.68 8
0.9.96 8
0.9.102 5
0.9.103 5
0.9.104 5

Bisect over the 4 questions that regressed (+1 that improved):

version Q2 Q9 Q11 Q13 Q16
0.9.96 – 0.9.101 hit hit hit hit miss
0.9.102, 0.9.103 miss miss miss miss hit

To separate the engine from the graph, I swapped them: the 0.9.103 engine on the graph built by 0.9.96, and the 0.9.96 engine on the graph built by 0.9.103. The hits follow the engine, not the graph. So the cause is the query scoring, not extraction.

Example (Q11, "SOLID Principles ... 핵심 정리")

  • 0.9.101 seeds include solid-principles-code-review.md (the answer page).
  • 0.9.102 seeds drop it. In its place come unrelated non-markdown nodes such as java.base Module and aws_secret_key prebuilt pattern (Block), along with generic word nodes (Code, Writing).

Relevant code (0.9.102 graphify/serve.py)

_QUERY_DEMOTE_WEIGHT = 0.3
_QUERY_DOC_WORDS = frozenset({"doc", "docs", "documentation", "readme"})
_QUERY_DOC_SUFFIXES = (".md", ".rst", ".txt", ".yml", ".yaml", ".toml", ".cfg", ".ini", ".json")
...
        if not keep_docs and (
            not path
            or data.get("file_type") in ("document", "paper")
            or parts[-1].endswith(_QUERY_DOC_SUFFIXES)
            or any(p in _QUERY_DOC_DIRS for p in parts[:-1])
        ):
            return _QUERY_DEMOTE_WEIGHT

Isolating the demotion inside one engine

This uses the 0.9.102 engine and the same graph throughout. Only path_weight changes. The table shows the rank of the answer page's best node in _score_query(...).ranked:

question demotion off (path_weight=None) demotion on (as query calls it)
Q2 3 7
Q9 3 9
Q11 4 5
Q13 14 33

Reproduction

  1. Bisect. For each version, install it and build the same commit, then run one query:
uv venv venv-$V --python 3.13 && uv pip install --python venv-$V/bin/python graphifyy==$V
# in a fresh checkout of the same commit:
PYTHONHASHSEED=0 venv-$V/bin/python -m graphify update .
PYTHONHASHSEED=0 venv-$V/bin/python -m graphify query "<question>" --budget 1500 | grep -c "<answer page>.md"
  1. Engine/graph swap. Run the 0.9.102 engine on the graph built by 0.9.101, and the other way round.

  2. In-engine A/B on any markdown-heavy graph. This needs no second version:

import sys
from graphify import serve
G = serve._load_graph("graphify-out/graph.json")
q, answer = sys.argv[1], sys.argv[2]          # question, path fragment of the expected file
terms = serve._query_terms(q)
def rank(pw):
    r = serve._score_query(G, terms, collect_per_term_seeds=False, path_weight=pw).ranked
    return next((i + 1 for i, (_, n) in enumerate(r) if answer in str(G.nodes[n].get("source_file", ""))), None)
print("off:", rank(None), "on:", rank(serve._query_path_weight(terms)))

A toy corpus does not show the regression. With 2 markdown notes and 30 Python functions whose names share the query words, both versions still seeded the answer note. The miss appears when many markdown nodes from other files also partly match the question. After the 0.3× demotion, those nodes and the few non-markdown nodes compete for the same seed and budget slots. I can't share the corpus, which is a personal wiki of about 30k nodes, but I'm happy to run any diagnostic you suggest.

Request

Any one of these would fix it for doc-first corpora:

  1. A .graphifyrc key or CLI flag (for example query_demote_docs: false, or a configurable weight).
  2. Skip the demotion when documents make up most of the graph, for example when more than half of the nodes have a doc-like source_file.
  3. Apply the demotion only when the graph contains a meaningful amount of code.

We pinned 0.9.96 for now. Environment: macOS, Python 3.13, uv tool install graphifyy==<ver>.

Activity

  1. github-actions commented on Nov 8, 2026

    @github-actions

    Thanks for opening this issue, @yeochul-jeon. 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.

  2. safishamsi commented on Nov 10, 2026

    @safishamsi
    Member

    Fixed in 0.9.106 (now on PyPI) via #5116: --no-doc-demotion (and the demote_docs rc key / MCP arg) disables the source-over-docs weight for a docs-first corpus.

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