Query-first GraphRAG how it works
Back to the demo

Cut the graph first, then summarise it

GraphRAG answers questions by reading summaries of a knowledge graph. We make it read only the part of the graph that the question is about.

Open the demo Replay the example below

The idea

Microsoft's GraphRAG splits a whole graph into communities and has a language model write a report about each one. Questions are answered by reading those reports, which have to be written for the whole graph before anyone asks anything. We turn the order around.

GraphRAG on the whole graph
Whole graph→ Reports for everythingwritten once, in advance→ Question→ Answerreads many of them
Query-first
Question→ Subgrapharound the question→ A few reportswritten for it→ Answerreads only those

The whole-graph reports are written once and shared by every question; the small ones are written again for each question.

What happens when you ask

“What is Creutzfeldt-Jakob Disease (CJD)?”A question from BioASQ, followed through the five steps.

  1. Read the question

    Qwen 2.5 7B lists the genes, diseases and drugs the question names, with their type and standard English name. That is all the model decides.

    “Creutzfeldt-Jakob Disease (CJD)” → a disease
  2. Find it in the graph

    Each mention is looked up in a dictionary of node names and synonyms from UMLS, DisGeNET, HGNC and MeSH. Matches are exact after normalising case, punctuation and word order, so every link can be traced back to the name that produced it.

    → the node Creutzfeldt-Jakob disease (UMLS C0022336), by its name
  3. Grow a subgraph

    From the entity we take its direct neighbours, then let DIAMOnD and C3 add the nodes significantly connected to them, the disease module. A random walk from the whole selection adds a last handful of close nodes. No model is involved.

    neighbours + DIAMOnD + C3 + random walk

    Each node remembers which step added it, so one selection gives four nested subgraphs: neighbours only, plus DIAMOnD, plus C3, and the full one. The demo answers with all four.

  4. Communities and reports

    GraphRAG splits the subgraph into communities with Leiden, and Qwen3 30B writes a short report for each one, from the nodes, their edges and the definitions PrimeKG gives for them. This index is built for this question only.

    A handful of communities, each with its own report
  5. Answer

    The question is put to every report, the useful points are scored, and the best ones are merged into one paragraph that cites the reports it relies on.

    Only those reports are read · GraphRAG on the whole graph reads many more, and spends more tokens, for the same question

Under the hood

Entity linker: an LLM finds the mentions, then a dictionary links them to nodes.
Subgraph selection: DIAMOnD and C3 run inside each homogeneous layer of the graph, the genes, the diseases and the drugs, followed by a heterogeneous random walk with restart. It runs with a fixed seed, so the same question gives the same subgraph.
Bring Your Own Graph converter: turns any subgraph into the tables GraphRAG expects, so a curated graph can be indexed without extracting it from text.
Search with its context: every answer is stored together with the reports it read and the scored points of the map step. That record is what the demo shows.

The graph and the recorded runs

PrimeKG, integrated in an earlier thesis of the lab with gene and disease associations from DisGeNET, plus a drug layer of bioactivity and chemical similarity built in the lab. It is served from Neo4j. The demo replays the questions of the BioASQ summary evaluation from the pipeline's own outputs, packed so a browser can play them back without a GPU. The thesis will be published soon.

Ezequiel González Grenat, Bioinformatics Lab, Leloir Institute. Thesis work on query-first subgraph selection for biomedical GraphRAG.

Leloir Institute