TL;DR
This paper introduces a novel pipeline to align Large Language Models (LLMs) with domain-specific graph databases for Natural Language to Graph Query Language (NL2GQL) translation. By generating synthetic NL-GQL data pairs and using efficient fine-tuning techniques, they significantly improve the accuracy of LLMs in understanding and querying complex graph structures.
What Problem Does This Paper Address?
Translating natural language questions into graph query languages (like GQL) is a challenging task due to the intricate nature of both natural language and GQL syntax. While LLMs have shown promise in similar tasks like text-to-SQL, a significant hurdle for domain-specific graph databases is the lack of readily available, high-quality NL-GQL paired data for training. This makes it difficult to align LLMs with the specific schemas and semantics of these specialized databases. The paper aims to bridge this gap by creating a method to generate this crucial training data and effectively fine-tune LLMs for accurate NL2GQL translation within a given domain.
Methods
The authors propose a two-stage pipeline:
- NL-GQL Pair Generation:
- Template Collection: They start by collecting canonical NL-GQL templates that decouple schema-specific information from the query logic.
- Two-Step Self-Instruct Generation: Leveraging ChatGPT, they generate NL-GQL pairs. The first step uses the graph database schema and seed templates to prompt ChatGPT. The second step uses a Chain-of-Thought (CoT) approach to verify the generated NL against the GQL.
- Graph DB Grounding: Placeholders in the template pairs are replaced with actual entities and properties from the graph database, and the generated GQLs are executed to ensure correctness. This results in a high-quality, domain-specific dataset.
- LLM Alignment:
- Parameter-Efficient Fine-Tuning (PEFT): They use LoRA (Low-Rank Adaptation) to fine-tune a foundation LLM. This method efficiently adapts the LLM to the graph database's knowledge without extensive parameter updates.
- Schema-Aware Prompting: For inference, they extract schema information relevant to the natural language query to provide context to the fine-tuned LLM, further guiding it to generate accurate GQL.
Datasets
The paper introduces two new domain-specific datasets:
- FinGQL: Derived from a financial domain graph database (StockKG).
- MediGQL: Derived from a medical domain graph database (DiseaseKG).
These datasets consist of NL-GQL pairs, template NL-GQL pairs, GQL answers, and query type IDs. They contain approximately 10,000 and 8,550 records, respectively.
Key Insights and Ideas
- Synthetic Data Generation is Crucial: The scarcity of domain-specific NL-GQL data is a major bottleneck. The paper demonstrates that a well-designed synthetic data generation pipeline, leveraging LLMs like ChatGPT, can effectively overcome this.
- Schema Relevance Matters: Providing only relevant schema information, rather than the entire schema, is key to achieving high accuracy and efficient inference. This prevents LLMs from being overwhelmed by irrelevant details.
- PEFT for Efficient Alignment: LoRA is an effective technique for aligning LLMs with graph databases, offering a good balance between performance and computational cost.
- CoT for Verification: Using Chain-of-Thought for GQL-to-NL verification helps ensure the quality and consistency of the generated NL-GQL pairs.
Key Results
The proposed method significantly outperforms baseline methods on both FinGQL and MediGQL datasets.
- FinGQL: Achieved 5.90% improvement in Exact Match (EM) and 6.00% improvement in Execution Accuracy (EX) over the best baselines.
- MediGQL: Achieved 6.36% improvement in EM and 7.09% improvement in EX over the best baselines.
- The method also showed a slight increase in inference time but a substantial enhancement in effectiveness, especially when using relevant Chinese schema information.
- Ablation studies confirmed the importance of schema context and the effectiveness of using relevant schema over full or no schema.
Limitations and Future Work
- Language Specificity: While the method is intended to be language-agnostic, the current experiments were limited to Chinese data due to data availability. Future work could explore broader language support.
- Domain-Specific LLMs: The paper found that general-domain LLMs, when properly aligned, outperformed specialized medical domain LLMs for the NL2GQL task, suggesting that domain-specific LLMs might over-specialize and lose general language conversion abilities.
- Query Type Performance: Accuracy was lower for "Yes/No question," "Edge property type," and "Attribute" query types, indicating these complex computational queries remain challenging. Future research could focus on improving performance for these specific query types.
Summary updated