Query-Specific Graph Neural Networks
- QSGNN is a methodological pattern where the query directly influences graph computations by altering topology, node features, and propagation mechanisms.
- It empowers advanced tasks like multi-hop reasoning, multi-document retrieval, and knowledge graph completion by constructing query-tailored graphs or subgraphs.
- Instantiations vary from explicit query graph encoding to query-induced subgraph extraction and query-conditioned message passing, enhancing inference accuracy.
Query-Specific Graph Neural Network (QSGNN) denotes a family of graph-neural methods in which the graph computation performed at inference is conditioned on the input query rather than being a purely query-independent encoder. In the literature, this conditioning appears in several non-equivalent forms: the query itself may be converted into a graph and processed by message passing; a global graph may be reduced to a query-induced or query-pruned subgraph; or a largely fixed graph may be traversed with query-conditioned node features, attention, pooling, or scoring. QSGNN is therefore best understood as a methodological pattern rather than a single canonical architecture, with instantiations in conjunctive query answering, knowledge graph completion, retrieval and reranking, community search, and subgraph matching (Daza et al., 2020, Francesco et al., 2024, Yan et al., 13 Oct 2025). A terminological caveat is that the acronym “QSGNN” is also used for “Quality-aware Self-improving Graph Neural Network” in open-set social event detection, which is unrelated to the query-specific sense (Ren et al., 2022).
1. Conceptual scope and recurrent design patterns
Taken together, the literature suggests three recurring constructions of query specificity.
| Construction | Query-dependent object | Representative papers |
|---|---|---|
| Query graph encoding | The query itself defines the computation graph | MPQE (Daza et al., 2020), AnyCQ (Olejniczak et al., 2024) |
| Query-induced or query-pruned subgraph | A larger graph is restricted per query | GNRR (Francesco et al., 2024), Context Pooling (Su et al., 10 Jul 2025), Q-GNN (He et al., 4 Jun 2026) |
| Query-conditioned propagation on a mostly fixed graph | The query changes node states, routing, pooling, or scoring | GNN-Ret/RGNN-Ret (Li et al., 2024), query-aware RAG reranker (Agrawal et al., 25 Jul 2025), multi-hop RAG QSGNN (Yan et al., 13 Oct 2025), QD-GNN/AQD-GNN (Jiang et al., 2021), NSubS (Bai et al., 2022) |
This taxonomy implies that “query-specific” is a graded property. In the strongest sense, the query determines the graph topology itself; in a weaker but still important sense, the topology may remain static while the query changes the effective diffusion process through query-dependent node initialization, attention, top- routing, or graph readout. The literature also shows that query specificity can act at several levels simultaneously: graph construction, message passing, state updates, and final scoring.
A plausible implication is that QSGNNs are most useful where isolated query-item scoring is structurally inadequate. This includes multi-hop reasoning, multi-document retrieval, high-arity query answering, and local search problems in which the meaning of a node or edge depends on the current information need rather than on global graph structure alone.
2. Query materialization and graph construction
In the most direct formulation, the query becomes the graph. MPQE represents a conjunctive query
as a graph whose nodes are constant entities and query variables and whose edges are the query predicates. Variables are initialized by type embeddings, entities by entity embeddings, and the target variable may itself serve as the query representation under the Target Message variant after message-passing steps, where is the query diameter (Daza et al., 2020).
AnyCQ materializes the query even more explicitly as a search graph built from three node types: term nodes, value nodes for possible assignments, and literal nodes. Its query specificity is not only topological but stateful: the current assignment changes the graph labels through potential-edge and light-edge indicators, so the same logical query produces different computational states during search (Olejniczak et al., 2024).
A second pattern keeps a large background graph but extracts a query-specific subgraph at inference. GNRR builds an offline corpus graph over 8.8M MS MARCO passages using TCT-ColBERT document similarity, with fixed degree . For each query, BM25 retrieves the top-1000 candidates, and the model forms the induced subgraph
so the runtime graph is query-specific even though the underlying corpus graph is static. Node features are query-conditioned through 0, augmented in the graph branch with the initial BM25 ranking signal (Francesco et al., 2024).
Context Pooling for knowledge-graph link prediction constructs a query-specific context graph 1 by expanding from a query such as 2 while retaining only neighboring relations whose logical relevance to the query relation exceeds a threshold. In its optimized form, the retained neighbors are
3
which makes the effective graph topology depend on the current query relation and frontier state (Su et al., 10 Jul 2025).
A third pattern keeps graph topology largely fixed but makes node states query-dependent. GNN-Ret builds a passage graph offline from structure-related and keyword-related edges, then initializes each node by the query-passage semantic distance 4; query specificity enters through these node states and through top-5 relevance routing rather than through a newly constructed topology (Li et al., 2024).
3. Message passing, conditioning mechanisms, and graph readout
The message-passing backbone varies widely across QSGNN instantiations. MPQE uses an R-GCN: 6 followed by either sum/max/CMLP pooling or, in the most query-specific Target Message variant, direct use of the target-node state 7 as the query embedding (Daza et al., 2020).
AnyCQ and NSubS show a different pattern: the GNN is embedded inside a search process. AnyCQ runs message passing on the query-instantiated graph 8 and outputs per-variable distributions over candidate assignments, trained with REINFORCE on Boolean satisfiability improvement. NSubS, in exact subgraph matching, combines intra-graph propagation on both query and target graphs with a matching module that passes candidate-restricted messages across graphs according to the current partial mapping 9 and its augmentation 0. In both cases, query specificity is inseparable from search state, not merely from graph structure (Olejniczak et al., 2024, Bai et al., 2022).
In retrieval, query conditioning often appears as routing or scalar relevance diffusion. GNN-Ret initializes passage nodes with semantic distances and propagates only from the top-1 currently relevant nodes using
2
Its multi-hop extension RGNN-Ret recurrently accumulates scores across retrieval steps through
3
The query therefore changes both initialization and propagation schedule, even though the passage graph is static (Li et al., 2024).
Other systems use explicit query-aware attention or pooling. The query-aware RAG reranker of (Agrawal et al., 25 Jul 2025) performs query-aware subgraph extraction, applies an edge-aware Enhanced GAT encoder, then computes query-guided pooling by assigning each node a query-specific importance score before graph-level scoring. The multi-hop RAG model explicitly titled QSGNN uses query-guided intra-level and inter-level message passing over a Multi-L KG of entities, chunks, and documents; intra-level attention combines node-node similarity 4 with query-conditioned pair relevance 5, while inter-level aggregation uses a query-conditioned score 6 over heterogeneous pairs (Yan et al., 13 Oct 2025).
Q-GNN for knowledge graph completion is one of the clearest examples of explicit query-conditioned propagation. It first builds a query-context representation 7 for the query entity with reverse message passing, then concatenates 8 with the query relation embedding 9 to generate FiLM parameters 0. These modulate every candidate message through
1
while type-aware attention and a type-specific decoder
2
make the propagation depend jointly on query entity and query relation (He et al., 4 Jun 2026).
4. Principal application domains
In knowledge-graph reasoning, QSGNNs support several distinct tasks. MPQE answers complex conjunctive queries by encoding the query graph itself and ranking entities for the target variable with cosine similarity. AnyCQ introduces query answer classification (QAC) and query answer retrieval (QAR), reducing both to Boolean search over incomplete KGs and aiming to handle arbitrary conjunctive-query structures. Context Pooling adds query-specific graph generation to inductive and transductive link prediction by pruning logically irrelevant neighbors. Q-GNN addresses knowledge graph completion for 3 queries, arguing that earlier query-centered GNNs overused the query relation and underused the query entity (Daza et al., 2020, Olejniczak et al., 2024, Su et al., 10 Jul 2025, He et al., 4 Jun 2026).
In retrieval and reranking, the common theme is graph-enhanced relevance propagation. GNRR is a second-stage reranker that operates on the BM25 top-1000 candidates and uses graph-encoded cross-document interactions to reorder them. GNN-Ret and RGNN-Ret model passage relatedness for question answering with LLMs, propagating query-conditioned relevance scores over a static passage graph. The query-aware RAG reranker of (Agrawal et al., 25 Jul 2025) scores query-relevant subgraphs extracted from per-episode knowledge graphs. The multi-hop RAG model explicitly named QSGNN builds a Multi-L KG with entity-, chunk-, and document-level nodes and performs query-guided representation learning over this heterogeneous graph (Francesco et al., 2024, Li et al., 2024, Agrawal et al., 25 Jul 2025, Yan et al., 13 Oct 2025).
In graph search and graph mining, QSGNN ideas appear in exact subgraph matching and community search. NSubS formulates subgraph isomorphism search as a policy problem over partial mappings 4, with a query-conditioned encoder Qc-Sgmnn that refines target-node embeddings according to both the small query graph and the current search state. QD-GNN and AQD-GNN formulate community search and attributed community search as per-query vertex classification: the query vertex set is encoded as a one-hot seed vector 5, AQD-GNN additionally injects query attributes through a node-attribute bipartite graph, and the final community is extracted by thresholding and constrained BFS (Bai et al., 2022, Jiang et al., 2021).
5. Training paradigms and reported empirical behavior
The empirical literature is heterogeneous because QSGNNs solve different tasks and use different supervision signals. Ranking losses include LambdaRank in GNRR, margin ranking in MPQE, contrastive NT-Xent training in multi-hop RAG QSGNN, and multi-class log loss in Q-GNN. Search-based systems use policy-gradient training: AnyCQ is optimized with REINFORCE over Boolean-query satisfiability improvement, whereas NSubS uses a look-ahead loss combined with max-margin supervision over successful search trajectories. This suggests that “QSGNN” is compatible with both direct scoring and learned search.
| Paper | Setting | Representative reported result |
|---|---|---|
| MPQE (Daza et al., 2020) | Link-prediction-only training generalization | AIFB 6 AUC on chains/all; Bio 7 |
| GNRR (Francesco et al., 2024) | TREC-DL19 reranking | TCT+GCN AP 8 vs 9; 0 relative AP gain; no statistical significance |
| GNN-Ret / RGNN-Ret (Li et al., 2024) | 2WikiMQA retrieval for QA | GNN-Ret 1 accuracy; RGNN-Ret 2; up to 3 improvement |
| Context Pooling (Su et al., 10 Jul 2025) | KG link prediction | SOTA in 42 of 48 settings |
| Q-GNN (He et al., 4 Jun 2026) | Knowledge graph completion | MRR 4 on WN18RR, 5 on FB15k-237; best MRR on 9 of 12 inductive splits |
| QSGNN for multi-hop RAG (Yan et al., 13 Oct 2025) | MuSiQue 4-hop retrieval | Recall@5 6 vs 7; 8 relative improvement |
| QD/AQD-GNN (Jiang et al., 2021) | Interactive community search | 9 F1 improvement without attributes and 0 with attributes |
| AnyCQ (Olejniczak et al., 2024) | Large conjunctive-query benchmarks | 1 F1 with a perfect predictor on large QAC and QAR |
A cautious reading is necessary. Some papers report especially large gains only in the hardest settings, such as 4-hop retrieval or large cyclic conjunctive queries. Others show modest but consistent improvements, as in GNRR, where gains did not reach statistical significance. Several strong results are also conditional on auxiliary components: AnyCQ’s upper-bound behavior depends on link-prediction quality, Q-GNN depends on type inference, and QSGNN for RAG depends heavily on synthetic pre-training. This suggests that QSGNNs often derive their practical strength from the interaction between query-conditioned graph computation and a domain-specific supporting pipeline, not from message passing alone.
6. Terminological boundaries, misconceptions, and adjacent directions
The label QSGNN is not standardized. The literature supports a spectrum running from direct query-graph encoders to query-induced subgraph methods and finally to models that keep a mostly fixed graph but make propagation or pooling query-dependent. MPQE is near the strongest end because the query itself defines the graph; GNRR and Context Pooling are query-specific mainly through induced or pruned subgraphs; GNN-Ret is query-conditioned in computation but not in graph topology; and the query-aware RAG reranker lies between these poles because it performs query-aware subgraph extraction and query-guided pooling without fully specifying query-parameterized message passing (Daza et al., 2020, Francesco et al., 2024, Su et al., 10 Jul 2025, Li et al., 2024, Agrawal et al., 25 Jul 2025).
A common misconception is that any GNN used in a query-facing application is automatically a QSGNN. The surveyed papers argue for a narrower criterion: the query must materially alter the graph computation. In practice, this alteration may come from stateful assignment search, as in AnyCQ; type- and context-conditioned modulation, as in Q-GNN; synthetic-pretraining-driven multi-level query guidance, as in the multi-hop RAG QSGNN; or candidate-restricted cross-graph communication inside a classical backtracking framework, as in NSubS (Olejniczak et al., 2024, He et al., 4 Jun 2026, Yan et al., 13 Oct 2025, Bai et al., 2022).
The acronym also has an independent meaning. In open-set social event detection, QSGNN stands for “Quality-aware Self-improving Graph Neural Network,” a 2-layer GAT-based framework that transfers from known to unknown events using reference similarity distributions, diversity-based pseudo-pair selection, and quality-guided optimization; it is not a query-specific graph method in the sense used elsewhere (Ren et al., 2022). Related but not equivalent work also exists in learned query optimization: BiGG represents a physical query plan as a plan-specific graph and applies bidirectional GNN propagation with GRU readout, which is close in spirit to query-instance graph representation but not a canonical query-conditioned architecture (Chang et al., 2024).
In the broadest encyclopedic sense, QSGNN therefore names a research direction concerned with making graph neural computation conditional on an information need. What varies across the literature is where that condition enters: topology, node features, attention, search state, pooling, or decoder. The main conceptual contribution of the area is the replacement of query-item isolation by graph-structured, query-dependent inference.