Skip to content

Dynamic Cypher Generation

Required Graph Shape

Domain Graph

Description

A lot of user questions for structured data will contain several filters but not always the exact same ones. Let’s use the example of the Movie Graph to illustrate it. There might be several related questions being asked:

  • Which movies has Steven Spielberg directed?
  • Which movies has Steven Spielberg directed between 2000 and 2010?
  • Which movies has Steven Spielberg directed between 2000 and 2010 which …?

This list can infinitely continue. You would not want to create a Cypher Template for every one of these questions. The solution is to dynamically generate cypher queries based on the parameters actually given in the user question.

Given a user question an LLM decides which of the cypher templates to use. The LLM possibly extracts parameters from the user question and plugs them into the template. The query is executed on the database and the results are provided back to the LLM to generate an answer.

Usage

This pattern is an evolution of Cypher Templates. It is much more flexible allowing for more diverse user questions to be answered. Still, the range of questions is limited by the provided snippets.

Further reading

Existing Implementations

Example Implementations