Abstract
Complex Query Answering (CQA) is an important and fundamental task for knowledge graph (KG) reasoning. Query encoding (QE) is proposed as a fast and robust solution to CQA. In the encoding process, most existing QE methods first parse the logical query into an executable computational direct-acyclic graph (DAG), then use neural networks to parameterize the operators, and finally, recursively execute these neuralized operators. However, the parameterization-and-execution paradigm may be potentially over-complicated, as it can be structurally simplified by a single neural network encoder. Meanwhile, sequence encoders, like LSTM and Transformer, proved to be effective for encoding semantic graphs in related tasks. Motivated by this, we propose sequential query encoding (SQE) as an alternative to encode queries for CQA. Instead of parameterizing and executing the computational graph, SQE first uses a search-based algorithm to linearize the computational graph to a sequence of tokens and then uses a sequence encoder to compute its vector representation. Then this vector representation is used as a query embedding to retrieve answers from the embedding space according to similarity scores. Despite its simplicity, SQE demonstrates state-of-the-art neural query encoding performance on FB15k, FB15k-237, and NELL on an extended benchmark including twenty-nine types of in-distribution queries. Further experiment shows that SQE also demonstrates comparable knowledge inference capability on out-of-distribution queries, whose query types are not observed during the training process.
Introduction
Knowledge Graphs (KGs) such as Freebase and NELL serve as critical repositories of structured facts. However, these graphs are often incomplete, making the task of Complex Query Answering (CQA)—answering first-order logic queries where direct links may be missing—a significant challenge. Traditional Query Encoding (QE) methods address this by parsing queries into computational Directed Acyclic Graphs (DAGs) and recursively executing specialized neural operators (e.g., projection, intersection, union).
The authors of this paper argue that this "parameterize-and-execute" paradigm is unnecessarily complex. These specialized operators are difficult to optimize and may be structurally redundant. Instead, they propose that a single, powerful sequence encoder can learn to represent the entire query structure effectively through a process called Sequential Query Encoding (SQE).
Methodology: Sequential Query Encoding (SQE)
The proposed SQE framework treats graph reasoning as a sequence modeling task. The process consists of three main stages:
- Linearization: A search-based algorithm converts the query's computational DAG into a flat sequence of tokens. This sequence includes brackets for structure, logical operators (e.g.,
[P]for projection,[U]for union,[I]for intersection), and KG entities/relations. - Sequence Encoding: The tokenized sequence is processed by a standard architecture such as a CNN, GRU, LSTM, or Transformer. The encoder produces a final vector representation of the entire query.
- Retrieval: Answers are found by calculating the similarity (inner product) between the query vector and all entity embeddings in the KG.
The model is trained using cross-entropy loss to maximize the probability of retrieving correct answer entities. This approach demonstrates that answering complex logical queries doesn't require complicated, recursive neural operators.
Experimental Setup and Extended Benchmark
The study evaluates SQE on three standard KG benchmarks: FB15k, FB15k-237, and NELL-995. Notably, the authors introduced an extended benchmark to test the limits of query encoding. While previous work typically focused on approximately 14 query types, this study utilizes 58 query types—comprising 29 "in-distribution" types for training and 29 "out-of-distribution" (OOD) types to evaluate structural generalization.
Key Insights and Results
The experiments yielded several critical findings regarding the efficiency of sequential encoding:
- Optimization vs. Inductive Bias: While recursive models have a theoretical advantage in matching graph structures, they are harder to optimize. SQE's sequence encoders are easier to train, leading to superior "faithfulness" (answering queries where answers are explicitly present in the graph).
- State-of-the-Art Performance: SQE (specifically with LSTM and Transformer backbones) consistently outperformed existing QE methods like GQE, Q2B, and BetaE on in-distribution queries. For instance, on FB15k-237, SQE+Transformer achieved an MRR of 67.13 for Entailment, significantly higher than the previous best of 38.05.
- Generalization and Transformers: Standard Transformers initially struggled with OOD queries. However, the addition of Relative Positional Encoding (RPE) allowed them to handle unseen query structures effectively, rivaling specialized graph models.
- Vector Sufficiency: The results demonstrate that a single vector, when produced by a sufficiently strong encoder, is capable of capturing the nuances of multi-step logical queries, challenging the notion that simple vectors cannot represent complex sets.
Conclusion and Future Work
SQE demonstrates that simplicity can outperform structural complexity in KG reasoning. By flattening queries into sequences, the model leverages the optimization strengths of standard sequence encoders.
However, limitations remain. The model's performance is dependent on the linearization algorithm, and scaling to massive KGs requires efficient retrieval mechanisms. Future research may explore hybrid architectures that combine sequential ease-of-use with stronger structural priors to better handle complex First-Order Logic queries in OOD scenarios.
Summary updated