ZeldaBot is a Retrieval-Augmented Generation (RAG) application that transforms walkthrough guides for The Legend of Zelda games into an interactive chatbot experience.
- The Legend of Zelda (NES)
- The Adventure of Link
- A Link to the Past
- Link's Awakening
- Ocarina of Time
- Majora's Mask
- Oracle of Ages
- Oracle of Seasons
- The Wind Waker HD
- The Minish Cap
- Twilight Princess
- Phantom Hourglass
- Spirit Tracks
- Skyward Sword
- A Link Between Worlds
- Tri Force Heroes
git clone <repository-url>
cd zelda_botWe recommend using a virtual environment for dependency management.
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
pip install -r requirements.txtBefore setting up the database, you need to prepare the Zelda guide data. This involves scraping guides (pre-scraped guides are already included), preprocessing them, and generating embeddings.
ZeldaBot also includes optional, experimental support for langextract (see the optional langextract step below).
Step 1: Configure Environment Variables
Create a .env file in the project root with the following entries (if you are going to use the langextract scripts, make sure to add the entries mentioned above):
# OpenAI API Configuration
OPENAI_API_KEY=your_openai_api_key_here
# Database Configuration
DB_HOST=localhost
DB_PORT=5432
DB_USER=zelda_user
DB_PASSWORD=your_password
DB_NAME=zelda_bot
# Optional LangExtract entries:
GEMINI_API_KEY=
# LangExtract Tracing Configuration
LANGEXTRACT_SECRET_KEY=
LANGEXTRACT_PUBLIC_KEY=
LANGEXTRACT_HOST=Step 2: Scrape Game Guides (Optional)
The guides have already been scraped and can be found in /guides, but if you want to scrape fresh guides from ZeldaDungeon, you'll need to use the separate zelda_guide_scraper repository:
- Clone the scraper repository:
git clone https://github.com/camachoh1/zelda_guide_scraper.git
cd zelda_guide_scraper- Set up and run the scraper:
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
pip install -r requirements.txt
python zelda_scraper.py- Copy the scraped guides:
After running the scraper, copy the generated markdown files from the
scraped_guides/directory to theguides/directory in this ZeldaBot repository.
Step 3: Preprocess the Guides
Run the preprocessing script to chunk guides semantically and generate embeddings:
# This script will:
# - Chunk guides semantically and use markdown structure to create metadata about guide sections
# - Generate embeddings using OpenAI API
# - Save processed data to processed_data/ directory for inspection/debugging purposes.
python run_preprocessing.pyStep 4: Load Data into Database
After preprocessing is complete, load the data into your database:
Prerequisites:
- PostgreSQL with pgvector extension installed
- A PostgreSQL database created (e.g.,
zelda_bot)
Setup:
# Run the complete database setup
# This script will:
# - Create the database schema and tables
# - Enable the pgvector extension
# - Set up performance indexes including vector similarity search
# - Loads processed chunks and structured data into the database
python load_database.pyStart the Gradio interface:
python app.pyThe interface will be available at:
http://localhost:7860
As part of our research into RAG techniques, we explored using LangExtract to extract structured information from our unstructured guides. This experimental approach aimed to create semantic relationship maps between different game elements such as items, NPCs, bosses, dungeons, and more, to provide richer context for the RAG system.
The provided script langextract_zelda.py uses the langextract library to parse all the guides and extract their semantic relationships. This exploration successfully demonstrated how we could identify and categorize game elements with their attributes. For example:
{
"text": "Red rupees",
"type": "item",
"attributes": {
"type": "currency",
"purpose": "general use"
}
}
This approach successfully identified red rupees as a currency item with specific attributes, and we were able to create similar structured relationships for locations, NPCs, items, and more across all guides.
The script outputs structured data objects into the processed_data directory, with 15 structured data objects mapping to each specific game guide. These are stored in the database alongside the traditional RAG chunks.
Current Status: This experimental feature is included in the codebase but not actively used in the current RAG pipeline. The exploration revealed interesting possibilities for hybrid retrieval approaches that combine traditional vector search with structured relationship queries.
Research Insights: While the JSON-based approach proved effective for data extraction, we discovered that integrating this structured data into the RAG context requires more sophisticated engineering. The exploration was limited by the high API costs of using Gemini tier 1 during development and testing, which constrained our ability to fully develop the integration approach. However, this exploration opened up exciting possibilities for future work, including:
- Graph Database Integration: Modeling relationships in a graph database rather than JSON for more efficient querying
- Hybrid Retrieval: Combining traditional vector search with graph-based relationship queries
- Enhanced Context: Using structured relationships to provide more precise context to the language model
This research exploration demonstrates the potential for combining unstructured and structured data in RAG systems, paving the way for more sophisticated retrieval strategies in future iterations.