Skip to content

Commit e618df9

Browse files
committed
Dynamic cypher generation
1 parent 1fb794c commit e618df9

File tree

1 file changed

+24
-7
lines changed

1 file changed

+24
-7
lines changed

src/content/docs/reference/graphrag/dynamic-cypher-generation.md

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,42 @@ tags: ["Intermediate"]
88

99
[Domain Graph](/reference/knowledge-graph/domain-graph)
1010

11-
## Description
11+
## Context
12+
13+
Many user questions for structured data will contain several filters, but not always the exact same ones.
14+
Let’s use the example of the Movie Graph to illustrate.
1215

13-
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:
16+
There might be several related questions being asked:
1417

1518
- Which movies has Steven Spielberg directed?
16-
- Which movies has Steven Spielberg directed between 2000 and 2010?
17-
- Which movies has Steven Spielberg directed between 2000 and 2010 which …?
19+
- Which movies did Steven Spielberg direct between 2000 and 2010?
20+
- Which movies did Steven Spielberg direct between 2000 and 2010 that [example]?
21+
22+
This list can infinitely continue.
23+
You would not want to create a Cypher Template for every one of these questions.
24+
The solution is to (partially) dynamically generate Cypher queries based on the parameters actually given in the user question.
1825

19-
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.
26+
## Description
2027

21-
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.
28+
Given a user question an LLM decides which of the Cypher templates to use.
29+
The LLM possibly extracts parameters from the user question and plugs them into the template.
30+
The query is executed on the database and the results are provided back to the LLM to generate an answer.
31+
Multiple templates can also be used in a chain or loop, which then leads to an agentic query system.
2232

2333
## Usage
2434

25-
This pattern is an evolution of [Cypher Templates](/reference/graphrag/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.
35+
This pattern is an evolution of [Cypher Templates](/reference/graphrag/cypher-templates).
36+
It is much more flexible allowing for more diverse user questions to be answered.
37+
Still, the range of questions is limited by the provided snippets.
38+
39+
## Required pre-processing
40+
41+
Snippets of parameterized Cypher queries and a description of what they do are made available to the LLM.
2642

2743
## Further reading
2844

2945
- [Build a Knowledge Graph-based Agent With Llama 3.1, NVIDIA NIM, and LangChain](https://medium.com/neo4j/build-a-knowledge-graph-based-agent-with-llama-3-1-nvidia-nim-and-langchain-feb65788e637) (Tomaz Bratanic, August 2024)
46+
* [GraphRAG in Action: From Commercial Contracts to a Dynamic Q&A Agent](https://towardsdatascience.com/graphrag-in-action-from-commercial-contracts-to-a-dynamic-q-a-agent-7d4a6caa6eb5)
3047

3148
## Existing Implementations
3249

0 commit comments

Comments
 (0)