Skip to content
Merged
1 change: 1 addition & 0 deletions .wordlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ www
faq
Ollama
ollama
Cypher
43 changes: 41 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,9 @@ After generating the initial ontology, you can review it and make any necessary

Once you are satisfied with the ontology, you can proceed to use it for creating and managing your Knowledge Graph (KG).

### Knowledge Graph
### Knowledge Graph Agent

Now, you can use the SDK to create a Knowledge Graph (KG) from your sources and ontology.
Now, you can use the SDK to create a Knowledge Graph (KG) from your sources and ontology for Q&A.

```python
# After approving the ontology, load it from disk.
Expand All @@ -191,6 +191,45 @@ kg.process_sources(sources)

You can update the KG at any time by processing more sources with the `process_sources` method.

#### Configurable Prompts
When creating your Knowledge Graph (KG) agent, you can customize the prompts to tailor its behavior. This step is optional but can enhance functionality.

There are five types of prompts:

1. **`cypher_system_instruction`**
- System instructions for the Cypher generation step.
- **Note:** Ensure your prompt includes `{ontology}`.

2. **`qa_system_instruction`**
- System instructions for the Q&A step.

3. **`cypher_gen_prompt`**
- The prompt used during the Cypher generation step.
- **Note:** Include `{question}` in your prompt.

4. **`cypher_gen_prompt_history`**
- The prompt for Cypher generation when history needs to be considered.
- **Note:** Include `{question}` and `{last_answer}` in your prompt.

5. **`qa_prompt`**
- The prompt used during the Q&A step.
- **Note:** Include `{question}`, `{context}`, and `{cypher}` in your prompt.

Here’s an example configuration:

```python
kg = KnowledgeGraph(
name="kg_name",
model_config=KnowledgeGraphModelConfig.with_model(model),
ontology=ontology,
cypher_system_instruction=cypher_system_instruction,
qa_system_instruction=qa_system_instruction,
cypher_gen_prompt=cypher_gen_prompt,
cypher_gen_prompt_history=cypher_gen_prompt_history,
qa_prompt=qa_prompt
)
```

### Graph RAG

At this point, you have a Knowledge Graph that can be queried using this SDK. Use the method `chat_session` for start a conversation.
Expand Down
22 changes: 11 additions & 11 deletions examples/movies/demo-movies.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -20,7 +20,7 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 2,
"metadata": {},
"outputs": [
{
Expand All @@ -29,7 +29,7 @@
"True"
]
},
"execution_count": 11,
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
Expand Down Expand Up @@ -59,7 +59,7 @@
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -84,7 +84,7 @@
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -113,7 +113,7 @@
},
{
"cell_type": "code",
"execution_count": 14,
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -136,17 +136,17 @@
},
{
"cell_type": "code",
"execution_count": 16,
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The directors of the movie \"The Matrix\" are Lilly Wachowski and Lana Wachowski.\n",
"The directors, Lilly Wachowski and Lana Wachowski, are connected to Keanu Reeves through their collaboration on the movies \"The Matrix,\" \"The Matrix Reloaded,\" and \"The Matrix Revolutions,\" in which Keanu Reeves acted.\n",
"The director of the movie \"Side by Side\" is Chris Kenneally.\n",
"The directors, ordered lexically, are Chris Kenneally, Lana Wachowski, and Lilly Wachowski.\n"
"{'question': 'Who is the director of the movie The Matrix?', 'response': 'The directors of the movie \"The Matrix\" are Lilly Wachowski and Lana Wachowski.', 'context': '[[\\'(:Movie{box_office_gross_usa:0,duration:\"2h 18m\",genre:\"Sci-Fi, Action\",popcornmeter_score:72,rating:\"R\",release_date:\"2003-05-15\",runtime:\"2h 18m\",title:\"The Matrix Reloaded\",tomatometer_score:74})\\', \\'(:Person{name:\"Lilly Wachowski\"})\\'], [\\'(:Movie{box_office_gross_usa:0,duration:\"2h 18m\",genre:\"Sci-Fi, Action\",popcornmeter_score:72,rating:\"R\",release_date:\"2003-05-15\",runtime:\"2h 18m\",title:\"The Matrix Reloaded\",tomatometer_score:74})\\', \\'(:Person{name:\"Lana Wachowski\"})\\'], [\\'(:Movie{box_office_gross_usa:0,duration:\"2h 16m\",genre:\"Sci-Fi, Action, Mystery & Thriller\",popcornmeter_score:85,rating:\"R\",release_date:\"1999-03-31\",title:\"The Matrix\",tomatometer_score:83})\\', \\'(:Person{name:\"Lilly Wachowski\"})\\'], [\\'(:Movie{box_office_gross_usa:0,duration:\"2h 16m\",genre:\"Sci-Fi, Action, Mystery & Thriller\",popcornmeter_score:85,rating:\"R\",release_date:\"1999-03-31\",title:\"The Matrix\",tomatometer_score:83})\\', \\'(:Person{name:\"Lana Wachowski\"})\\']]', 'cypher': \"\\nMATCH (m:Movie)-[:DIRECTED_BY]->(p:Person)\\nWHERE m.title CONTAINS 'The Matrix'\\nRETURN m, p\\n\"}\n",
"{'question': 'How this director connected to Keanu Reeves?', 'response': 'The directors Lilly Wachowski and Lana Wachowski are connected to Keanu Reeves through the movie \"The Matrix,\" where Keanu Reeves acted in the film.', 'context': '[[\\'(:Person{name:\"Lilly Wachowski\"})\\', \\'(:Movie{box_office_gross_usa:0,duration:\"2h 16m\",genre:\"Sci-Fi, Action, Mystery & Thriller\",popcornmeter_score:85,rating:\"R\",release_date:\"1999-03-31\",title:\"The Matrix\",tomatometer_score:83})\\', \\'(:Person{name:\"Keanu Reeves\",role:\"John Wick\"})\\'], [\\'(:Person{name:\"Lana Wachowski\"})\\', \\'(:Movie{box_office_gross_usa:0,duration:\"2h 16m\",genre:\"Sci-Fi, Action, Mystery & Thriller\",popcornmeter_score:85,rating:\"R\",release_date:\"1999-03-31\",title:\"The Matrix\",tomatometer_score:83})\\', \\'(:Person{name:\"Keanu Reeves\",role:\"John Wick\"})\\']]', 'cypher': \"\\nMATCH (p:Person)-[:DIRECTED]->(m:Movie)<-[:ACTED_IN]-(k:Person)\\nWHERE p.name IN ['Lilly Wachowski', 'Lana Wachowski'] AND k.name CONTAINS 'Keanu Reeves'\\nRETURN p, m, k\\n\"}\n",
"{'question': 'Who is the director of the movie Side by Side?', 'response': 'The director of the movie \"Side by Side\" is Chris Kenneally.', 'context': '[[\\'(:Movie{box_office_gross_usa:0,duration:\"1h 38m\",genre:\"Documentary\",popcornmeter_score:86,rating:\"Not Rated\",release_date:\"2012-08-17\",runtime:\"1h 38m\",title:\"Side by Side\",tomatometer_score:92})\\', \\'(:Person{name:\"Chris Kenneally\"})\\']]', 'cypher': \"\\nMATCH (m:Movie)-[:DIRECTED_BY]->(p:Person)\\nWHERE m.title CONTAINS 'Side by Side'\\nRETURN m, p\\n\"}\n",
"{'question': 'Order the directors that you mentioned in all of our conversation by lexical order.', 'response': 'The directors, ordered lexically, are Chris Kenneally, Lana Wachowski, and Lilly Wachowski.', 'context': '[[\\'(:Person{name:\"Chris Kenneally\"})\\'], [\\'(:Person{name:\"Lana Wachowski\"})\\'], [\\'(:Person{name:\"Lilly Wachowski\"})\\']]', 'cypher': \"\\nMATCH (p:Person)\\nWHERE p.name IN ['Lilly Wachowski', 'Lana Wachowski', 'Chris Kenneally']\\nRETURN p\\nORDER BY p.name\\n\"}\n"
]
}
],
Expand Down
Loading