Text to Graph Query Using Filter Condition Attributes

Yang Liu, Xin Wang, Jiake Ge, Hui Wang, Dawei Xu, Yongzhe JiaWorkshops @ VLDB 2024

TL;DR

This research introduces FCAV (Filter Condition Attribute Values), a pipeline designed to enhance the precision of Natural Language to Graph Query Language (NL2GQL) translation. By integrating real-world attribute values retrieved from a vector database into Large Language Model (LLM) prompts, the system significantly mitigates mapping errors. The approach demonstrates superior performance on complex, domain-specific datasets in fields such as Traditional Chinese Medicine and Education.

The Mapping Problem in Text-to-GQL

While Large Language Models (LLMs) excel at code generation, converting natural language into Graph Query Language (GQL) presents a unique challenge: semantic ambiguity. A primary bottleneck is the "mapping problem." For instance, if a user queries "Titanic," the LLM must determine whether "Titanic" refers to a node label (a category), a property key (an attribute name), or a specific property value (the title of a movie).

Ambiguity in mapping natural language entities to graph schema elements.

Standard methodologies typically provide the LLM with the database schema—the structural definition of nodes and edges. However, schema information alone is insufficient to disambiguate specific data values. This often results in "hallucinated" queries: syntactically valid code that fails to retrieve data because it searches the wrong schema elements. Furthermore, existing benchmarks frequently rely on oversimplified labels, failing to capture the complexity of real-world graph databases.

The FCAV Pipeline

To bridge the gap between abstract schema and concrete data, the authors propose the FCAV pipeline. This framework utilizes a "cheat sheet" approach to ground LLM generation in actual database content through three primary stages:

  1. Graph Vectorization: The system traverses the graph database to extract attribute values (e.g., "Titanic," "Ginseng"). These values are then stored in a vector database (V-DB) for efficient retrieval.
  2. Contextual Prompting (SGP): During the inference phase, user queries trigger a similarity search within the V-DB. The system identifies the most relevant real-world attributes and injects them into the LLM prompt alongside the schema. This explicitly links natural language keywords to specific labels and keys (e.g., mapping "Titanic" to the Movie label and title key).
  3. Automated Dataset Generation: The researchers developed a robust four-step process to create high-quality training data:
  4. Base-Dataset: Generating initial NL-GQL pairs using structured templates.
  5. Grammar-Extended: Incorporating complex query features such as sorting (ORDER BY) and pagination (LIMIT).
  6. LLM-Extended: Leveraging LLMs to paraphrase queries into diverse, natural language variations.
  7. Training-Dataset: Finalizing the pairs by integrating the FCAV context.
The complete FCAV pipeline, including dataset generation and inference with vector-based retrieval.

The models—specifically ChatGLM3-6B, Llama3-8B, and Qwen-7B—were fine-tuned using LoRA (Low-Rank Adaptation) to ensure computational efficiency while maximizing performance.

Datasets and Evaluation

To address the limitations of older benchmarks like SpCQL, the study introduces two new datasets:

  • TCMGQL: Derived from a Traditional Chinese Medicine database, it features intricate relationships between herbs, symptoms, and medical functions.
  • EduGQL: An education-focused dataset designed to test "domain migration"—the ability of a model trained in one domain to generalize to another.

Key Results and Insights

The evaluation focused on three metrics: Syntactic Accuracy (SyA), Semantic Accuracy (SeA), and Exact Match Rate (EMR).

  • Performance Leaders: Llama3-8B, when fine-tuned with the FCAV approach, achieved a 99.47% Syntactic Accuracy and 89.52% Semantic Accuracy on the TCMGQL dataset.
  • Ablation Analysis: Removing FCAV information (relying solely on schema) led to a significant drop in semantic accuracy. This confirms that data-level context, rather than just structural context, is the primary driver of query precision.
  • Robustness: In domain migration tests from TCM to Education, the FCAV method consistently outperformed traditional schema-only prompting by 2–3%, indicating better generalization capabilities.

Conclusion and Future Directions

The FCAV pipeline demonstrates that knowing the content of a database is as critical as knowing its structure for high-precision Text-to-GQL tasks. By combining vector retrieval for data values with generative LLMs for syntax, the system effectively compensates for the model's lack of domain-specific knowledge.

Currently, the method is optimized for property graphs. Future research will focus on extending the pipeline to handle "label-heavy" architectures—where entities are represented by labels rather than attributes—and generating more complex, multi-hop graph queries.

Summary updated

BibTeX
@inproceedings{liu2024text,
  author = {Yang Liu and Xin Wang and Jiake Ge and Hui Wang and Dawei Xu and Yongzhe Jia},
  title = {{Text to Graph Query Using Filter Condition Attributes}},
  booktitle = {Workshops @ VLDB},
  year = {2024},
}
Figure