A Retrieval-Augmented Generation (RAG) bot that uses wasmCloud documentation to answer questions about wasmCloud. Built with FastAPI, PostgreSQL with pgvector, and OpenAI GPT-4.
- Documentation Scraping: Automatically scrapes and processes wasmCloud documentation
- Vector Database: Uses PostgreSQL with pgvector for efficient similarity search
- MCP Integration: Model Context Protocol client and server for AI assistant integration
- GPT-4 Integration: Uses OpenAI GPT-4 for intelligent responses
- Chunking Pipeline: Smart text chunking with overlap for better context
- Web Interface: Beautiful chat interface for easy interaction
Just cloned this repository? See SETUP_GUIDE.md for a 5-minute setup guide!
- Python 3.9+
- PostgreSQL with pgvector extension
- OpenAI API key
- Required: OpenAI API key (get from OpenAI Platform)
Complete Setup with Virtual Environment (recommended):
./scripts/setup.zsh
# or
make setupThis will:
- Create a Python virtual environment (
venv/) - Install all dependencies in isolation
- Set up PostgreSQL with Docker
- Initialize the database
- Create activation scripts
Start All Services (using zsh):
./scripts/start.zsh # Auto-activates virtual environment
# or
make startStop All Services:
./scripts/stop.zsh
# or
make stopManual Virtual Environment Usage:
source venv/bin/activate # Activate virtual environment
# or
source activate_wasmcloud_rag.zsh # Use helper scriptAlternative Setup (Python script):
python3 setup.py # Creates virtual environment automatically- Dependency Isolation: No conflicts with system Python packages
- Reproducible Environment: Consistent dependencies across systems
- Easy Cleanup: Remove
venv/directory to clean up completely - Automatic Management: Scripts handle activation automatically
- Create and activate virtual environment:
python3 -m venv venv
source venv/bin/activate- Install dependencies:
pip3 install -r requirements.txt- Set up PostgreSQL with pgvector:
# Using Docker (recommended)
docker-compose up -d postgres
# Or install PostgreSQL manually and add pgvector extension
CREATE EXTENSION IF NOT EXISTS vector;- Configure environment:
cp config.env.example .env
# Edit .env with your OpenAI API key and database settingsBefore running the application, you must configure the following environment variables:
-
Copy the example configuration:
cp config.env.example .env
-
Set your OpenAI API key:
- Get your API key from OpenAI Platform
- Edit
.envand replaceyour_openai_api_key_herewith your actual key:
OPENAI_API_KEY=sk-proj-your-actual-api-key-here
-
Database configuration (default values work with Docker):
# These values match docker-compose.yml - no changes needed if using Docker DATABASE_URL=postgresql://wasmcloud_user:wasmcloud_password@localhost:5432/wasmcloud_rag PGVECTOR_USER=wasmcloud_user PGVECTOR_PASSWORD=wasmcloud_password -
Optional: Customize AI models and processing:
# Use different OpenAI models if preferred EMBEDDING_MODEL=text-embedding-3-small # or text-embedding-ada-002 CHAT_MODEL=gpt-4-1106-preview # or gpt-3.5-turbo # Adjust text processing CHUNK_SIZE=1000 # Larger = more context, slower processing CHUNK_OVERLAP=200 # Overlap between text chunks
Quick setup for local development:
# Copy and edit the configuration
cp config.env.example .env
# Edit with your favorite editor
nano .env
# or
code .env
# or
vim .env
# Update the OpenAI API key line:
# OPENAI_API_KEY=sk-proj-your-actual-api-key-hereProduction setup:
# Set environment variables directly (for deployment)
export OPENAI_API_KEY="your-actual-api-key"
export DATABASE_URL="postgresql://user:pass@host:5432/db"
export CHAT_MODEL="gpt-4-1106-preview"- Never commit
.envfiles to git - they contain sensitive API keys - Use different API keys for development and production
- Rotate API keys regularly for security
- Set up billing alerts in OpenAI dashboard to monitor usage
OpenAI API Key Issues:
# Test your API key
curl -H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
https://api.openai.com/v1/modelsDatabase Connection Issues:
# Test database connection
python3 -c "
from server.database import check_database_connection
print('Database connected:', check_database_connection())
"Check all environment variables are loaded:
python3 -c "
import os
from dotenv import load_dotenv
load_dotenv()
print('OpenAI Key configured:', bool(os.getenv('OPENAI_API_KEY')))
print('Database URL:', os.getenv('DATABASE_URL'))
print('Embedding Model:', os.getenv('EMBEDDING_MODEL'))
"Run the database initialization:
python3 scripts/init_db.pyScrape and ingest wasmCloud documentation:
python3 scripts/ingest_docs.pyUsing zsh scripts (recommended):
./scripts/start.zsh # Start all services
./scripts/start.zsh --with-mcp # Include MCP server
./scripts/dev.zsh # Development environment
./scripts/dev.zsh --with-tests --with-mcp # Full development setupManual start:
python3 -m server.main
# or
make runThe server will be available at:
- Web Interface:
http://localhost:8000 - API Documentation:
http://localhost:8000/docs - Database Admin:
http://localhost:8080(Adminer)
POST /query- Ask questions about wasmCloudGET /health- Health checkPOST /ingest- Manually trigger documentation ingestionGET /stats- Get database statistics
Open http://localhost:8000 in your browser for an interactive chat interface.
import requests
response = requests.post("http://localhost:8000/query", json={
"question": "What is wasmCloud and how does it work?"
})
print(response.json()["answer"])python3 test_client.pyUse with AI assistants like Claude Desktop:
# Test MCP client
python3 mcp_client.py
# Start MCP server for AI assistant integration
python3 mcp_server.py- Knowledge Graph Guide - Advanced knowledge graph enhancement for relationship-aware reasoning
- System Design - Comprehensive architecture, data flow, and implementation details
- Optimization Analysis - AI enhancement features and performance improvements
- Setup Guide - Complete installation and configuration instructions
- MCP Usage Guide - Model Context Protocol integration for AI assistants
βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
β Documentation βββββΆβ Text Chunking βββββΆβ Embeddings β
β Scraper β β & Processing β β Generation β
βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
β
βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
β User Query βββββΆβ Vector Search ββββββ PostgreSQL + β
β β β & Retrieval β β pgvector β
βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
β β
β βββββββββββββββββββ
βββββββββββββββΆβ GPT-4 RAG β
β Generation β
βββββββββββββββββββ
The project includes comprehensive zsh scripts for easy management:
Complete automated setup with colored output and error handling:
./scripts/setup.zshStart all services with monitoring:
./scripts/start.zsh # Basic startup
./scripts/start.zsh --with-mcp # Include MCP serverStop services with cleanup options:
./scripts/stop.zsh # Stop services
./scripts/stop.zsh --clean-logs # Stop and clean logs
./scripts/stop.zsh --clean-data # Stop and clean database
./scripts/stop.zsh --all # Stop and clean everythingInteractive development environment with hot reloading:
./scripts/dev.zsh # Basic dev environment
./scripts/dev.zsh --with-tests # Include continuous testing
./scripts/dev.zsh --with-mcp # Include MCP server
./scripts/dev.zsh --with-tests --with-mcp # Full development setupFeatures:
- Hot reloading for Python files
- Real-time log monitoring
- Interactive development console
- Service status dashboard
- Continuous testing (optional)
wasmcloud-bot/
βββ server/
β βββ main.py # MCP server entry point
β βββ models.py # Database models
β βββ database.py # Database connection
β βββ embeddings.py # Embedding utilities
β βββ rag.py # RAG pipeline
β βββ scraper.py # Documentation scraper
βββ scripts/
β βββ init_db.py # Database initialization
β βββ ingest_docs.py # Documentation ingestion
β βββ setup.zsh # Complete setup automation
β βββ start.zsh # Service startup management
β βββ stop.zsh # Service shutdown management
β βββ dev.zsh # Development environment
βββ requirements.txt
βββ .env.example
βββ README.md