Introduction
Large Language Models (LLMs) have demonstrated remarkable capabilities in natural language understanding and generation. However, two persistent challenges hinder their deployment in enterprise environments: hallucination and knowledge cutoff. Hallucination occurs when models generate factually incorrect but plausible-sounding information, while knowledge cutoff refers to the model's inability to access information beyond its training data. For business applications, the ability to query private, live, and structured data stored in relational databases (RDBs) is essential.
Bridging the gap between natural language and RDBs—often referred to as the "Text-to-SQL" problem—is fraught with difficulties. A primary issue is "value unawareness," where an LLM fails to match user input to specific database entries (e.g., querying for "Los Angeles" when the database uses the abbreviation "LA"). Furthermore, existing systems often struggle with complex queries that span multiple disparate databases.
System Architecture
This paper introduces a novel, LLM-agnostic framework that treats relational databases as external memory. By operating as a wrapper around existing models like GPT-3.5 and Claude-2, the system avoids the need for costly fine-tuning while providing precise data retrieval.
The architecture is composed of several specialized modules designed to handle the complexities of structured data retrieval:
- Context Switch Module: This module performs a preliminary analysis of the user's query. If the required information is already present in the prompt context, it bypasses the database retrieval process to save computational resources.
- Database Selection Memory: Utilizing semantic embeddings, this component identifies the "Top-K" most relevant databases from a large repository.
- LLM-based Refinement & Planning: The LLM acts as a reasoning agent, examining the schemas of selected databases to formulate a concrete, multi-step retrieval plan.
- Data Value Memory (DVM): To solve the "value unawareness" problem, the DVM stores embeddings of actual database values. This allows the system to map natural language terms to exact database strings during SQL generation, ensuring the
WHEREclauses are accurate. - Output Generation: The final module executes the generated SQL queries and synthesizes the raw results into a natural language response.
Experimental Setup
The framework was evaluated using a comprehensive dataset of 1,500 questions categorized into three types to test different aspects of the system:
- Zero DB Questions: Sourced from SQUAD-v2 and Commonsense QA to test the system's ability to identify when database access is unnecessary.
- Single DB Questions: Derived from the Spider and Dr-Spider benchmarks to evaluate standard Text-to-SQL performance.
- Double DB Questions: A custom set of complex queries requiring information from two separate databases simultaneously (e.g., comparing counts across different domains).
Results and Discussion
The experimental results highlight the limitations of standalone LLMs and the efficacy of the proposed augmentation. Vanilla LLMs achieved 0% accuracy on database-dependent questions, as they cannot natively interface with RDBs. In contrast, the augmented framework achieved:
- 60-66% SQL accuracy on single-database tasks.
- Significant performance gains from the Data Value Memory (DVM), which improved SQL accuracy by an average of 6.3% and answer accuracy by 3.8%.
- Robust performance on "Zero DB" questions, indicating that the Context Switch Module effectively prevents unnecessary retrieval without degrading standard NLP performance.
Conclusion
By integrating relational databases as external memory, this framework provides a scalable and model-agnostic solution to the problems of hallucination and static knowledge in LLMs. The introduction of Data Value Memory is a critical step toward making LLMs "value aware," enabling them to interact reliably with real-world structured data. Future work will focus on testing with open-source models and enhancing privacy safeguards for cloud-based deployments.
Summary updated