This project is a creation of an intelligent chatbot focused on the world of Game of Thrones, based on a Neo4j knowledge graph and books from the A Song of Ice and Fire series. The chatbot, acting as a Lore Master from the Citadel, provides detailed information about characters, houses, events, and the rich lore of Westeros and beyond.
In the first phase of the project, information from the books is translated into a knowledge graph using the langchain_experimental (graph_transformers package). This graph is then loaded into Neo4j AuraDB, where it can be queried using CYPHER queries.
The graph serves as the foundation for a chatbot with an agent that can perform several types of queries:
- RAG-style queries on the base documents
- Complex CYPHER queries on the knowledge graph created in the first phase
The bot stores its memory in Neo4j AuraDB, allowing analysis of past questions and answers, and formulating insights about the users' interests in the Game of Thrones universe.
An example from the knowledge graph, the results of the following query (Partial screenshot):
MATCH (h:House)<-[r:MEMBER_OF]-(c:Character)
WHERE h.name IN ['Stark', 'Lannister', 'Targaryen']
RETURN h, c, rAn example of the chat-bot's response in the Streamlit interface:
-
Create a Virtual Environment To create a virtual environment, run the following command:
python -m venv venv
-
Install the Requirements Activate the virtual environment and install the required packages by running:
source venv/bin/activate # On Windows use `venv\Scripts\activate` pip install -r requirements.txt
-
Create the .env File Create a
.envfile with the necessary passwords and configurations, following the format provided inexample_env.txt.
-
Add Files to the Books Directory Place the Game of Thrones books into a directory, and change the "PATH" variable in
Insert_to_the_graph.pyto the directory path. We use thebooksdirectory. -
Update config.py file Update the node and relationship types allowed in the
config.pyfile to match Game of Thrones entities (e.g., Character, House, Location). -
Run the Insert_to_the_graph Script Extract nodes and upload them to AuraDB by running:
python Insert_to_the_graph.py
-
Run the clean_graph Script Clean up irrelevant relationships by running:
python clean_graph.py
- Run the create_doc_vector_index Script
Create the document vector index for efficient text search by running:
python create_doc_vector_index.py
- Run the bot Script
To start the Game of Thrones Lore Master chatbot, run:
streamlit run bot.py
Enjoy exploring the vast world of Ice and Fire with your new AI Maester!