NL2EQ: Generating Elasticsearch Query DSL from Natural Language Text Using Large Language Models
摘要
In the era of big data and machine learning, the ability to search and retrieve data from databases is crucial. Though there exists extensive research on converting natural language questions to structured query language (SQL) queries required to fetch data from relational databases, a similar task of generating queries for non-relational databases is least explored. In this paper, we present a solution for converting questions in natural language to JSON document-like NoSQL queries, such as those used in non-relational document-oriented databases like Elasticsearch. We also propose a custom evaluation metric called document query accuracy (DQA) to evaluate the performance of the models for Elasticsearch query generation based on tree edit distance and sequence similarity metric. We created a synthetic dataset for this task and benchmarked the performance of multiple prompt engineering and fine-tuning techniques with various models on this dataset as well as on our internal real-world test dataset obtained from domain experts. Our experiments show that supervised fine-tuning for the task combined with role-playing prompt engineering on a large language model (LLM) like GPT-3.5 provide the best results. Additionally, we share our approach in deploying the model in our production AI for IT operations (AIOps) system where this is applied and discuss the challenges faced during the deployment.