Answering Complex Logical Queries on Knowledge Graphs via Query Computation Tree Optimization

Yushi Bai, Xin Lv, Juanzi Li, Lei Hou

Knowledge Graphs (KGs) are massive networks of interconnected facts (e.g., "Albert Einstein" — won — "Nobel Prize"). However, they are notoriously incomplete. Answering a complex First-Order Logic (FOL) query—such as "Where was the physicist who won the Nobel Prize in 1921 born?"—requires reasoning across multiple missing links.

To address this, researchers have introduced Query Computation Tree Optimization (QTO), a novel optimization-based framework that solves complex FOL queries on incomplete KGs by finding the exact optimal solution. Unlike previous methods that rely on massive training datasets or greedy approximations, QTO requires no training on complex queries, generalizes perfectly to "easy" queries, and provides highly interpretable intermediate results.

The Limitations of Current Approaches

Historically, approaches to complex KG queries have fallen into two primary camps, both with significant drawbacks:

  1. Embedding-based methods: These models learn to represent sets of entities as geometric shapes or distributions. While popular, they require training on millions of generated queries, struggle to generalize to out-of-distribution structures they haven't seen before, and act as "black boxes" unable to explain why they arrived at a specific answer.
  2. Optimization-based methods (e.g., CQD): These methods use a pre-trained link predictor to score potential answers. Because the search space grows exponentially with the number of variables in the query, they rely on approximations like beam search. Unfortunately, beam search often prematurely prunes away the correct answer.

The core gap in the field has been the lack of a method to find the theoretically optimal set of entity assignments without triggering a computational explosion.

The QTO Framework: A Divide-and-Conquer Strategy

The central innovation of QTO is treating the logical query as a Query Computation Tree, where nodes represent variables and edges represent relations or logical operators (AND, OR, NOT). Instead of searching the entire exponential space at once, QTO utilizes the conditional independence encoded in the tree structure to perform dynamic programming:

  • Forward Propagation: Starting from the "leaves" (known entities), the algorithm recursively calculates the maximum possible truth value for each sub-query. This is conceptually similar to the Viterbi algorithm or message passing in graphical models.
  • Backward Propagation: Once the root (the target answer variable) is reached, the algorithm performs a backward pass using an arg max operation. This identifies the specific entities for every intermediate variable that led to the optimal score.
  • Neural Adjacency Matrix: To handle missing links, QTO uses a pre-trained Knowledge Graph Embedding (KGE) model to create a "soft" adjacency matrix, where entries represent the probability of a link existing.

Key Insights and Theoretical Guarantees

By framing the problem as a tree optimization, QTO introduces several major theoretical and practical advantages:

  • Exact Optimality: The authors prove that QTO can find the global maximum truth value using only local computations, entirely eliminating the "accuracy floor" caused by beam search.
  • Disentangling Reasoning from Prediction: QTO does not need to be trained on complex queries. It simply "plugs in" a pre-trained link predictor. As underlying KGE models improve, QTO's performance improves "for free" without any retraining.
  • The "Easy Query" Guarantee: QTO is the first neural method mathematically guaranteed to return 100% correct answers for "easy" queries—queries where all necessary links actually exist in the graph.
  • High Interpretability: Because of the backward pass, QTO reveals exactly which intermediate entities it "hopped" through to reach the final answer. Empirical evaluations show these intermediate interpretations are correct over 90% of the time.

Empirical Results

The researchers evaluated QTO on three standard Knowledge Graph benchmarks (FB15k, FB15k-237, and NELL995) across 14 different query structures, including Existential Positive First-Order (EPFO) queries and queries involving negation.

  • State-of-the-Art Performance: QTO outperformed the previous best method (GNN-QE) by an average of 22% across all datasets.
  • Superiority over Beam Search: It outperformed the previous optimization-based leader (CQD) by 30.8%, proving that exact optimization is significantly more effective than beam search approximations.
  • Negation Handling: On queries involving negation—traditionally the hardest type to model—QTO achieved a massive relative gain of 37.5%.
  • Efficiency: Despite executing an "exact" search, QTO is faster than many baselines because its operations are reduced to sparse matrix multiplications, which are highly optimized for modern GPUs.

Limitations and Future Work

While QTO represents a significant leap forward, it has a few constraints. Currently, the framework is limited to queries that can be represented as trees; it cannot handle cyclic queries (e.g., where three variables form a closed triangle of relations).

Additionally, while sparse matrix filtering aids efficiency, pre-computing the neural adjacency matrix for extremely large KGs (with millions of entities) remains resource-intensive. Finally, QTO relies heavily on how well the underlying KGE model's scores are calibrated into true probabilities. Future work focusing on learning better calibration functions could push QTO's performance even higher.

Summary updated

BibTeX
@inproceedings{bai2023answering,
  author = {Yushi Bai and Xin Lv and Juanzi Li and Lei Hou},
  title = {{Answering Complex Logical Queries on Knowledge Graphs via Query Computation Tree Optimization}},
  booktitle = {International Conference on Machine Learning},
  year = {2023},
  url = {https://openreview.net/forum?id=KTJ6E8t9Cy},
}
Figure