T ext2 C ypher: Bridging Natural Language and Graph Databases (2025)

Abstract: Knowledge graphs use nodes, relationships, and properties to represent arbitrarily complex data. When stored in a graph database, the Cypher query language enables efficient modeling and querying of knowledge graphs. However, using Cypher requires specialized knowledge, which can present a challenge for non-expert users. Our work Text2Cypher aims to bridge this gap by translating natural language queries into Cypher query language and extending the utility of knowledge graphs to non-technical expert users. While large language models (LLMs) can be used for this purpose, they often struggle to capture complex nuances, resulting in incomplete or incorrect outputs. Fine-tuning LLMs on domain-specific datasets has proven to be a more promising approach, but the limited availability of high-quality, publicly available Text2Cypher datasets makes this challenging. In this work, we show how we combined, cleaned and organized several publicly available datasets into a total of 44,387 instances, enabling effective fine-tuning and evaluation. Models fine-tuned on this dataset showed significant performance gains, with improvements in Google-BLEU and Exact Match scores over baseline models, highlighting the importance of high-quality datasets and fine-tuning in improving Text2Cypher performance.

## introduction databases are essential in applications, supporting data storage and knowledge management, and are typically accessed via query languages like sql (for relational databases) or cypher (for graph databases). with advancements in llms, users can now query databases using natural language through applications that perform tasks such as text2sql or text2cypher. consequently, even with minimal technical expertise, users can easily retrieve information, build applications such as dashboards or analytics, or integrate knowledge into other systems, such as retrieval-augmented generation (rag). the text2cypher task converts plain language questions into cypher query language (see figure 1 ). in the figure, a user wants to write a cypher query for 'what are the movies of tom hanks'. a text2cypher model translates the input natural language question into cypher, i.e., it returns 'match (actor:person {name: "tom hanks"})-[:acted_in]->(movie:movie) return movie.title as movies'. this generated cypher query can then be used to retrieve relevant data from the database, allowing for utilization based on the needs of the user. foundational large language models (llms) can be utilized for text2cypher task directly with an appropriate prompt. however, they may struggle with complex queries, leading to incomplete or incorrect outputs which damage the utility of the knowledge graph. fine-tuning llms on domain-specific datasets offers a promising solution but requires high quality data that pairs natural language queries with cypher translations, plus schema information for greater accuracy. however, creating such a dataset is challenging, as it requires an understand-ing of graph representation, domain-specific knowledge to formulate effective natural language questions, and proficiency in cypher syntax. if the training set does not include high-quality, diverse and sufficient examples, the fine-tuned text2cypher model may underperform. the number of publicly available text2cypher datasets is limited. a few examples include those created by neo4jlabs (neo4jlabs, 2024), datasets converted from text2sql sets @xcite , and others constructed synthetically @xcite . however, these datasets are prepared independently, which makes it difficult to use them together. in this work, we combine and refine instances from publicly available datasets, creating a large dataset for training and testing, and use it to benchmark and fine-tune foundational models for text2cypher. our main contributions are as follows: the paper is structured as follows: section 2 discusses related work on translating natural language to query languages, with a focus on text2cypher. section 3 details the dataset preparation process. section 4 and section 5 present our experiments for benchmarking and fine-tuning. finally, section 6 concludes the paper. ## dataset construction while several text2cypher datasets exist, many are prepared separately, making them hard to use together. in this work we bring instances from publicly available datasets together, clean and organize them for smoother use. for this purpose, we executed three main steps: (i) identification and collection of publicly available datasets, (ii) combining and cleaning the data, and (iii) creating the training and test splits. ## model evaluation and benchmarking after constructing a larger and more organized dataset, this section presents the benchmarking results. ## model finetuning and evaluation based on the findings of benchmarking, presented in section 4, we selected six baseline models for our subsequent steps, presented in ## conclusion databases are essential for data storage, management, and retrieval, often accessed through query languages like cypher. recent advancements in large language models (llms) have made it pos-sible to access databases using natural language through tasks like text2cypher. while llms can be directly used for this task, they often struggle with complex queries, resulting in incomplete or incorrect cypher outputs. fine-tuning llms on specific text2cypher datasets offers a more effective solution. however, publicly available text2cypher datasets are limited and often created independently, making them difficult to combine and use effectively. to address this, we combined and refined several datasets into a unified set of 44,387 instances, with 89% in the training split and 11% in testing. fine-tuned models trained on this dataset outperformed baselines, achieving up to a 0.34 increase in google-bleu score and a 0.11 increase in exact match score. this work highlights the importance of dataset and fine-tuning for text2cypher task. future work will refine the dataset further, analyze challenging cases, and explore improvements through prompt engineering and model optimization.