From 1fb794cd36e7c3539faa80d8e454c2be692e0c74 Mon Sep 17 00:00:00 2001 From: Michael Hunger Date: Wed, 27 Nov 2024 14:00:40 +0100 Subject: [PATCH] Cypher templates + domain graph --- src/assets/images/domain-graph.svg | 252 ++++++++++++++++++ .../reference/graphrag/cypher-templates.md | 19 +- .../hypothetical-question-retriever.md | 2 +- .../reference/knowledge-graph/domain-graph.md | 11 +- 4 files changed, 277 insertions(+), 7 deletions(-) create mode 100644 src/assets/images/domain-graph.svg diff --git a/src/assets/images/domain-graph.svg b/src/assets/images/domain-graph.svg new file mode 100644 index 0000000..faa8148 --- /dev/null +++ b/src/assets/images/domain-graph.svg @@ -0,0 +1,252 @@ + + + + + + + + + + + + + + + + + + + + + + +Actor + + + + + + + + + +Movie + + + + + + + + + + + + + + + + + + + + + + + +ACTED_IN + + + +Domain Graph with Embeddings: + + + + + + + + + +name: String + +bio: String + +bio_emb: float[] + + + + + + + + + +title: String + +year: int + +plot: String + +plot_emb: float[] + + + + + + + + + +Genere + + + + + + + + + + + + + + + + + + + + + + + +IN_GENRE + + + + + + + + + + + + + + + + + + + + + + + +RATED + + + + + + + + + +User + + + + + + + + + +Director + + + + + + + + + + + + + + + + + + + + + + + +DIRECTED + + + + + + + + + +name: String + + + + + + + + + +name: String + + + + + + + + + +rating: int + + + + + + + + + +role: String + + + + + + + + + +name: String + +bio: String + +bio_emb: float[] + + diff --git a/src/content/docs/reference/graphrag/cypher-templates.md b/src/content/docs/reference/graphrag/cypher-templates.md index dd675f5..e97973e 100644 --- a/src/content/docs/reference/graphrag/cypher-templates.md +++ b/src/content/docs/reference/graphrag/cypher-templates.md @@ -6,17 +6,28 @@ tags: ["Intermediate"] ## Required Graph Shape +![Domain Graph](../../../../assets/images/domain-graph.svg) [Domain Graph](/reference/knowledge-graph/domain-graph) -## Description +## Context + +For the retrieval of structured data, we need to translate a user question into a query that can be executed on a database. +A basic approach is to have predefined queries written by domain experts to which a user question can be mapped to. -For the retrieval of structured data, we need to translate a user question into a query that can be executed on a database. A basic approach is to have predefined queries ready that a user question can be mapped to. +## Description -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. +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 -When the type of questions that a user will pose to the Domain Graph is previously known, these templates can be created. A shortcoming of this approach is the restriction to given template queries. What happens if the user asks a question that would result in a query that isn’t existent in the templates? +When the type of questions that a user will pose to the Domain Graph is previously known, these templates can be created. +A shortcoming of this approach is the restriction to given template queries. +What happens if the user asks a question that would result in a query that isn’t existent in the templates? + +## Required pre-processing + +Several domain-specific Cypher queries (containing parameters) and a description of what they do are made available to the LLM. ## Further reading diff --git a/src/content/docs/reference/graphrag/hypothetical-question-retriever.md b/src/content/docs/reference/graphrag/hypothetical-question-retriever.md index c8f008e..5e8ffc7 100644 --- a/src/content/docs/reference/graphrag/hypothetical-question-retriever.md +++ b/src/content/docs/reference/graphrag/hypothetical-question-retriever.md @@ -9,7 +9,7 @@ tags: ["Basic"] [Lexical Graph with Hypothetical Questions](/reference/knowledge-graph/lexical-graph-hypothetical-questions) ![Lexical Graph with Hypothetical Questions](../../../../assets/images/knowledge-graph-lexical-graph-hypothetical-questions.svg) -## Context: +## Context The vector similarity between a question’s embedding and the text embedding of an appropriate answer or text source might be quite low. If we have question-chunk pairs available, we can execute a vector similarity search on the question embeddings, which will probably deliver much better results than a vector similarity search on the original text chunk. diff --git a/src/content/docs/reference/knowledge-graph/domain-graph.md b/src/content/docs/reference/knowledge-graph/domain-graph.md index e129da7..a41fe30 100644 --- a/src/content/docs/reference/knowledge-graph/domain-graph.md +++ b/src/content/docs/reference/knowledge-graph/domain-graph.md @@ -3,5 +3,12 @@ title: Domain Graph description: Entities and relationships that reflect the real world --- -A Domain Graph contains Business Domain Knowledge. It contains real-world entities and the relationships between them. Frequently used example Domain Graphs are the Movie Graph or the Northwind Graph. -Since Domain Graphs will look very different based on the underlying Domain it is not possible to provide a blueprint of how a Domain Graph would look. +A Domain Graph contains Business Domain Knowledge. It contains real-world entities and the relationships between them. +Frequently used example Domain Graphs are the Movie Graph or the Northwind Graph. + +Since Domain Graphs will look different based on the underlying domain, it isn’t possible to provide a blueprint of how one would look. +Just keep in mind that they contain structured data adhering to a schema. + +Providing the information contained in a Domain Graph within a question-answer application where natural language queries lead to (deterministic) structured retrieval of data can be executed in several ways. + +![Domain Graph](../../../../assets/images/domain-graph.svg) \ No newline at end of file