Spaces:
Sleeping
Sleeping
| # Quick Start Guide: Intelligent Documentation Crawler & RAG Assistant | |
| ## π Getting Started (5 minutes) | |
| ### Step 1: Prerequisites | |
| - Python 3.10+ (already installed: Python 3.11) | |
| - Ollama running locally with `llama3` model | |
| - All dependencies installed (see `requiements.txt`) | |
| ### Step 2: Start Ollama (in a separate terminal) | |
| ```bash | |
| ollama serve | |
| ``` | |
| Then in another terminal, ensure the model is pulled: | |
| ```bash | |
| ollama pull llama3 | |
| ``` | |
| ### Step 3: Run the Dashboard | |
| ```bash | |
| python ui/gradio-dashboard.py | |
| ``` | |
| Open: `http://localhost:7860` | |
| ### Step 4: Use It! | |
| **Option A: Use the Gradio UI** | |
| 1. Paste URLs in the right sidebar (one per line) | |
| 2. Type your question in the chat | |
| 3. Get instant answers from the crawled/uploaded documents | |
| **Option B: Use the FastAPI Server** | |
| ```bash | |
| python -m src.api | |
| ``` | |
| Then query via curl: | |
| ```bash | |
| curl -X POST http://localhost:8000/query \ | |
| -H "Content-Type: application/json" \ | |
| -d '{ | |
| "question": "What is async/await?", | |
| "urls": ["https://docs.python.org/3/library/asyncio.html"] | |
| }' | |
| ``` | |
| **Option C: Use Python Directly** | |
| ```python | |
| from src.app_enhanced import answer_question | |
| answer = answer_question( | |
| "How do I use decorators?", | |
| urls=["https://docs.python.org"] | |
| ) | |
| print(answer) | |
| ``` | |
| --- | |
| ## π Adding Data Sources | |
| ### Method 1: PDF Files | |
| 1. Create `my_docs/` folder (already exists) | |
| 2. Add your PDF files there | |
| 3. The system will automatically load them on next query | |
| ### Method 2: Website URLs | |
| 1. Paste URLs in the Gradio dashboard, OR | |
| 2. Pass `urls` parameter to `answer_question()`, OR | |
| 3. Use the `/query` API endpoint with `urls` field | |
| ### Method 3: Crawl a Website | |
| ```python | |
| from src.crawler import DocumentationCrawler | |
| from src.app_enhanced import index_crawler_results | |
| # Crawl a documentation site | |
| crawler = DocumentationCrawler( | |
| base_url="https://docs.python.org/3", | |
| max_depth=3, | |
| max_pages=100 | |
| ) | |
| documents = crawler.crawl() | |
| index_crawler_results(documents) | |
| # Now query | |
| from src.app_enhanced import answer_question | |
| answer = answer_question("What's the difference between list and tuple?") | |
| print(answer) | |
| ``` | |
| --- | |
| ## π§ API Endpoints | |
| All endpoints require Ollama running with `llama3` model. | |
| ### `GET /health` | |
| Check if the API is running | |
| ```bash | |
| curl http://localhost:8000/health | |
| ``` | |
| ### `POST /query` | |
| Ask a question (complete response) | |
| ```bash | |
| curl -X POST http://localhost:8000/query \ | |
| -H "Content-Type: application/json" \ | |
| -d '{"question": "What is a context manager?", "urls": ["https://realpython.com"]}' | |
| ``` | |
| ### `POST /query/stream` | |
| Ask a question (streamed response) | |
| ```bash | |
| curl -X POST http://localhost:8000/query/stream \ | |
| -H "Content-Type: application/json" \ | |
| -d '{"question": "Explain generators"}' | |
| ``` | |
| ### `POST /crawl/prepare` | |
| Crawl a website (returns status) | |
| ```bash | |
| curl -X POST http://localhost:8000/crawl/prepare \ | |
| -H "Content-Type: application/json" \ | |
| -d '{ | |
| "base_url": "https://docs.python.org/3", | |
| "max_depth": 2, | |
| "max_pages": 50 | |
| }' | |
| ``` | |
| ### `POST /index/from-crawl` | |
| Crawl and automatically index | |
| ```bash | |
| curl -X POST http://localhost:8000/index/from-crawl \ | |
| -H "Content-Type: application/json" \ | |
| -d '{ | |
| "base_url": "https://docs.python.org/3", | |
| "max_depth": 2 | |
| }' | |
| ``` | |
| --- | |
| ## π Project Structure | |
| ``` | |
| fd/ | |
| βββ src/ # Core application modules | |
| β βββ app_enhanced.py # Enhanced RAG with crawler integration β | |
| β βββ app_hf.py # Hugging Face inference RAG app | |
| β βββ api.py # FastAPI server with streaming β | |
| β βββ crawler.py # Web crawler module β | |
| β βββ config.py # Configuration helpers | |
| β βββ util.py # Utility helpers | |
| β βββ __init__.py # Package entrypoint | |
| βββ ui/ # UI and dashboard scripts | |
| β βββ gradio-dashboard.py # User-friendly UI β | |
| β βββ spaces_app.py # Spaces-compatible UI | |
| β βββ gradio_chatbot_info.txt | |
| βββ tests/ # Test suite | |
| β βββ test_system.py | |
| βββ notebooks/ # Project notebooks | |
| β βββ project_code.ipynb | |
| βββ my_docs/ # PDF storage | |
| βββ chroma_db/ # Persisted vector DB storage | |
| βββ requirements.txt # Dependencies | |
| βββ IMPLEMENTATION_GUIDE.md # Detailed technical guide | |
| βββ README.md # This file | |
| ``` | |
| β = New/Enhanced components | |
| --- | |
| ## π§ͺ Testing | |
| ### Quick Test | |
| ```bash | |
| python tests/test_system.py | |
| ``` | |
| ### Test with Crawler | |
| ```bash | |
| python tests/test_system.py --crawl | |
| ``` | |
| ### Test API | |
| ```bash | |
| # Terminal 1: Start API | |
| python -m src.api | |
| # Terminal 2: Test it | |
| curl http://localhost:8000/health | |
| ``` | |
| --- | |
| ## βοΈ Configuration | |
| ### Crawler Parameters | |
| ```python | |
| DocumentationCrawler( | |
| base_url="https://...", | |
| max_depth=3, # How deep to crawl | |
| delay=0.5, # Politeness delay (seconds) | |
| timeout=10, # Request timeout | |
| max_pages=100 # Stop after this many pages | |
| ) | |
| ``` | |
| ### Text Splitting | |
| Edit in `app_enhanced.py`: | |
| ```python | |
| text_splitter = RecursiveCharacterTextSplitter( | |
| chunk_size=1000, # Characters per chunk | |
| chunk_overlap=200 # Overlap between chunks | |
| ) | |
| ``` | |
| ### Embedding Model | |
| Edit in `app_enhanced.py`: | |
| ```python | |
| hf_embeddings = HuggingFaceEmbeddings( | |
| model_name="sentence-transformers/all-MiniLM-L6-v2" | |
| # Other options: | |
| # - "sentence-transformers/all-mpnet-base-v2" | |
| # - "BAAI/bge-small-en" | |
| ) | |
| ``` | |
| ### LLM Model | |
| Edit in `app_enhanced.py`: | |
| ```python | |
| llm = ChatOllama( | |
| model="llama3", # Change to "llama2" or other available models | |
| temperature=0 # 0 = deterministic, 1 = creative | |
| ) | |
| ``` | |
| --- | |
| ## π Troubleshooting | |
| ### Error: "Ollama connection error" | |
| - Ensure Ollama service is running: `ollama serve` | |
| - Check model exists: `ollama list` | |
| - Pull if needed: `ollama pull llama3` | |
| ### Error: "No documents found" | |
| - Add PDFs to `my_docs/` folder, OR | |
| - Provide URLs via API/dashboard, OR | |
| - Run crawler first to crawl a website | |
| ### Slow First Query | |
| - First query loads embeddings (~30-60 seconds) | |
| - Subsequent queries are cached and faster (~1-5 seconds) | |
| ### Timeout During Crawl | |
| - Increase delay: `delay=1.0` | |
| - Reduce pages: `max_pages=50` | |
| - Check target site is accessible | |
| ### Memory Issues | |
| - ChromaDB runs locally (low overhead) | |
| - Embeddings model cached after first load | |
| - For large crawls, reduce `max_pages` | |
| --- | |
| ## π Performance | |
| Typical latencies (after warmup): | |
| - **Embedding generation**: 5-10ms per chunk | |
| - **Vector search**: 50-100ms | |
| - **LLM inference**: 1-5 seconds | |
| - **Total query time**: 1-10 seconds | |
| --- | |
| ## π Documentation | |
| For more details: | |
| - [Full Implementation Guide](IMPLEMENTATION_GUIDE.md) | |
| - [SRS Specification](srs.md) | |
| - [API Swagger Docs](http://localhost:8000/docs) (when API running) | |
| --- | |
| ## β¨ Features | |
| β Recursive web crawling with rate limiting | |
| β Local PDF loading | |
| β Code-aware text chunking | |
| β Local embeddings (no API key needed) | |
| β Semantic search | |
| β Streaming responses | |
| β FastAPI with Swagger docs | |
| β Gradio user interface | |
| β Multi-source data integration | |
| β Graceful error handling | |
| --- | |
| ## π― Next Steps | |
| 1. **Test with real docs**: Try crawling your target website | |
| 2. **Evaluate quality**: Check answer accuracy and relevance | |
| 3. **Fine-tune**: Adjust chunk size, depth, embedding model | |
| 4. **Deploy**: Use production server (Gunicorn + Uvicorn) | |
| 5. **Monitor**: Log queries and feedback for improvement | |
| --- | |
| **Happy documenting! π** | |