← All posts

From Question to Graph: Turning Natural Language into Cypher with Agentic AI

Aditya Korlahalli · · 4 min read

From Question to Graph: Turning Natural Language into Cypher with Agentic AI

The Task This summer, I was a software engineer intern at Kineviz working on GraphXR. My task was to make words into graphs: building an agentic AI tool that allows users to ask natural language queries and turn them into cypher queries which would then be presented as a graph.

The Problem Graph databases are a powerful way to represent connections in data because they allow you to store both entities and relationships. You access this data using a graph query language such as Cypher. Here is a simple Cypher query that returns the actors who acted in movies beginning with the letter P.

MATCH (a:Actor)-[:ACTED_IN]->(m:Movie) WHERE m.title STARTS WITH ‘P’ RETURN a, m

For a non-technical GraphXR user, even such a simple Cypher query could create a barrier. You would have to know the Cypher syntax, the labels in the database schema (for its nodes, relationships, properties), and how to interpret the results.

The Solution My goal was to create an agentic AI tool that could do each of the following:

  1. Process natural language questions from the user
  2. Retrieve the structure of the database
  3. Suggest database-relevant questions for the user
  4. Generate accurate Cypher queries using Anthropic AI
  5. Visualize the results in GraphXR

This process, which could take more than 10 minutes if done manually, would be reduced to seconds with this tool. Data analysis with GraphXR would then be more accessible to non-technical users, not just data scientists.

What is MCP? To create this agentic AI tool, I used the Model Context Protocol (MCP). MCP connects AI models to different data sources and tools. It can connect to databases, APIs, filesystems, and custom scripts/programs. MCP expands AI capability by providing access to real-time data, APIs, and tools that AI normally cannot use.

Below is a simple example to show how the Model Context Protocol works:

How it works Let’s use an example from the Neo4j Sandbox of a database of movies and people. Shown below is a visual schema of this Neo4j database showing its defined categories (node labels) and relationships:

  • @mcp.tool(): Retrieve the Database Schema

Using MCP (Model Context Protocol), the system pulls all the nodes and their relationships. This helps give the AI context about the database to make the Cypher queries accurate

  1. @mcp.tool(): Get the Node Labels and Properties of the Database

This MCP tool retrieves the node labels and properties of the database to help with coming up with database-relevant natural language queries for the user.

  1. @mcp.tool(): Organize Database Schema Data

This tool uses Anthropic AI to organize the data from the first MCP tool to make it into a more readable JSON file for the AI to make the Cypher query.

  1. @mcp.tool(): Suggest Natural Language Questions

This tool uses the data from the database schema, the labels, and properties to draft three database-relevant questions that the user can ask to make a Cypher query. This helps the user if they do not know anything about the database.

  1. @mcp.tool(): Get the Cypher Query

This tool uses the data from the database schema and the labels and properties to return a relevant Cypher query that can be visualized in GraphXR

Shown below is a diagram of how all of these MCP tools work together to write the Cypher query:

Final Product Natural Language Question Suggestion for User

Generates a Cypher query from the user’s natural language question

Run the Cypher query to graph the nodes and their relationships in GraphXR

Why Agentic AI? Traditional AI relies on sending a prompt and receiving a result. Agentic AI powered by MCP allows you to chain multiple tools together to perform larger and often more complicated tasks. It is a more autonomous, multi-step reasoning process that allows the user to use a wide variety of databases.

What’s Next? Graph databases are incredibly powerful, but their usefulness is limited to those who understand how to write Cypher queries and understand the database schema. By removing this technical barrier, anyone can ask questions and see their answers in a visual, intuitive way. However, this is just the start. I’m excited to integrate my tool with other graph databases like KuzuDB, and continue improving the complexity of questions that are suggested to the user.

Graph DatabaseAgentic AiData VisualizationModel Context ProtocolCypher Queries