An intelligent chatbot that answers questions about Apache Spark documentation using Retrieval-Augmented Generation (RAG). Built with Claude Sonnet 4.5, sentence-transformers (free embeddings), and ChromaDB.
- Comprehensive Documentation Coverage: Scrapes and indexes the latest Apache Spark documentation
- Intelligent Q&A: Uses RAG pipeline to provide accurate, context-aware answers
- Source Citations: Always provides references to source documentation
- Free Embeddings: Uses sentence-transformers (no embedding API costs)
- Local Vector Storage: ChromaDB for fast, local similarity search
- Beautiful CLI: Interactive chat interface with rich formatting
- Streaming Responses: Real-time response generation
User Question
↓
Query Embedding (sentence-transformers)
↓
Vector Search (ChromaDB)
↓
Context Retrieval (Top-K relevant chunks)
↓
Prompt Construction (Context + Question)
↓
Response Generation (Claude Sonnet 4.5)
↓
Formatted Answer + Sources
- Python 3.8 or higher
- Anthropic API key (for Claude Sonnet 4.5)
- Internet connection (for scraping and API calls)
git clone <repository-url>
cd spark-doc-chatbotpython -m venv venv
# On macOS/Linux:
source venv/bin/activate
# On Windows:
venv\Scripts\activatepip install -r requirements.txtcp .env.example .envEdit .env and add your Anthropic API key:
ANTHROPIC_API_KEY=your_api_key_here
Get your API key from: https://console.anthropic.com/
This scrapes the Spark documentation, creates embeddings, and stores them in ChromaDB:
python setup_index.pyThis process will:
- Scrape the latest Spark documentation (~500 pages)
- Chunk the content into manageable pieces
- Generate embeddings using sentence-transformers
- Store in ChromaDB for fast retrieval
Note: This may take 15-30 minutes depending on your internet connection and CPU.
If you've already scraped the documentation and want to re-index without scraping again:
python setup_index.py --use-cachedpython chatbot.py- "How do I create a DataFrame in PySpark?"
- "What is the difference between RDD and DataFrame?"
- "How do I perform a join operation in Spark SQL?"
- "What are transformations and actions in Spark?"
- "How do I optimize Spark job performance?"
- "How to read CSV files in Spark?"
- "What is lazy evaluation in Spark?"
/exitor/quit- Exit the chatbot/help- Show help message/clear- Clear the screen
spark-doc-chatbot/
├── scraper/
│ ├── __init__.py
│ ├── doc_scraper.py # Web scraping with BeautifulSoup
│ └── chunker.py # Text chunking logic
├── embeddings/
│ ├── __init__.py
│ └── generator.py # Embedding generation (sentence-transformers)
├── vectordb/
│ ├── __init__.py
│ └── chroma_client.py # ChromaDB operations
├── rag/
│ ├── __init__.py
│ ├── retriever.py # Context retrieval
│ ├── generator.py # Response generation (Claude)
│ └── pipeline.py # Main RAG orchestration
├── config.py # Configuration settings
├── setup_index.py # One-time indexing script
├── chatbot.py # Interactive CLI
├── requirements.txt # Python dependencies
├── .env.example # Environment variables template
├── .gitignore
└── README.md
Edit config.py to customize:
- Scraper settings: Number of pages, request delay
- Chunking parameters: Chunk size, overlap
- Embedding model: Default is
all-MiniLM-L6-v2 - RAG parameters: Top-K results, relevance threshold
- Claude settings: Model, temperature, max tokens
- Language Model: Claude Sonnet 4.5 (via Anthropic API)
- Embeddings: sentence-transformers (
all-MiniLM-L6-v2) - FREE - Vector Database: ChromaDB (local, persistent) - FREE
- Web Scraping: BeautifulSoup4 + Requests
- CLI Interface: Rich library
anthropic # Claude API
sentence-transformers # Free embeddings
chromadb # Vector database
beautifulsoup4 # Web scraping
requests # HTTP client
rich # CLI formatting
tiktoken # Token counting
tqdm # Progress bars
- Embeddings: FREE (sentence-transformers runs locally)
- Vector Database: FREE (ChromaDB local storage)
- Web Scraping: FREE
- LLM (Claude API): Pay per use (~$3-5 per million input tokens)
Estimated cost for typical usage: $0.10-0.50 per day depending on query volume.
- Indexing Time: 15-30 minutes (one-time)
- Query Response Time: 2-5 seconds
- Embedding generation: <0.1s
- Vector search: <0.1s
- Claude API call: 2-4s (depends on response length)
- Memory Usage: ~500MB (loaded model + embeddings)
- Disk Usage: ~100MB (ChromaDB + cached data)
Solution: Make sure you've created a .env file and added your API key:
cp .env.example .env
# Edit .env and add your keySolution: Run the indexing script first:
python setup_index.pySolution:
- Check your internet connection
- Increase
request_delayinconfig.pyto avoid rate limiting - Use cached data:
python setup_index.py --use-cached
Solution:
- Reduce
max_pagesinconfig.py - Reduce
batch_sizein embedding generation - Close other applications
Solution:
- Increase
top_kin RAG_CONFIG to retrieve more context - Lower
min_relevance_scoreto include more results - Adjust
temperaturein CLAUDE_CONFIG (lower = more deterministic)
Test individual components:
# Test scraper
python scraper/doc_scraper.py
# Test chunker
python scraper/chunker.py
# Test embeddings
python embeddings/generator.py
# Test ChromaDB
python vectordb/chroma_client.py
# Test RAG pipeline
python rag/pipeline.py- Multiple Spark Versions: Modify scraper to handle version selection
- Web UI: Integrate Streamlit or Gradio
- Advanced Filtering: Add metadata filters in retrieval
- Conversation History: Add chat memory for follow-up questions
- Code Execution: Integrate code interpreter for Spark examples
Contributions are welcome! Please:
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
MIT License - see LICENSE file for details
- Apache Spark documentation: https://spark.apache.org/docs/latest/
- Anthropic Claude: https://www.anthropic.com/
- sentence-transformers: https://www.sbert.net/
- ChromaDB: https://www.trychroma.com/
For issues and questions:
- Open an issue on GitHub
- Check existing issues for solutions
- Review the troubleshooting section
- Support for multiple Spark versions
- Web-based UI (Streamlit)
- Conversation memory
- Export conversation history
- Code execution sandbox
- Fine-tuned embeddings for better accuracy
- Multi-language support
Built with love for the Apache Spark community!