| --- |
| title: HealthExpert |
| emoji: π₯ |
| colorFrom: blue |
| colorTo: green |
| sdk: docker |
| app_port: 7860 |
| pinned: false |
| --- |
| |
| # HealthExpert π₯ |
|
|
| <div align="center"> |
|
|
| [](https://www.python.org/) |
| [](https://flask.palletsprojects.com/) |
| [](https://crewai.com/) |
| [](LICENSE) |
| [](https://github.com/Sam-max1/healthexpert) |
|
|
| **AI-Powered Hybrid RAG Document Analysis System** |
|
|
| *Intelligent document ingestion, retrieval, and analysis using CrewAI agents with Vector & Graph databases* |
|
|
| [π Quick Start](#quick-start) β’ [π Documentation](#documentation) β’ [ποΈ Architecture](#architecture) β’ [π€ Contributing](#contributing) |
|
|
| </div> |
|
|
| --- |
|
|
| ## π Overview |
|
|
| **HealthExpert** is an enterprise-grade AI document analysis platform combining: |
|
|
| - **π€ CrewAI Multi-Agent System**: Specialized agents for ingestion, verification, and analysis |
| - **π Hybrid RAG Architecture**: Vector DB (ChromaDB + BM25) + Graph DB (Kuzu) for comprehensive retrieval |
| - **π Multi-Format Support**: PDF, DOCX, XLSX, CSV, TXT, and Image files (OCR) |
| - **β‘ Microservice Architecture**: Dedicated LLM generation and embedding servers |
| - **π Web UI**: Real-time streaming responses with source citations |
| - **π Production-Ready**: Error handling, logging, async jobs, and Docker support |
|
|
| ### Key Features |
|
|
| | Feature | Description | |
| |---------|-------------| |
| | **Multi-Agent Processing** | Ingestor, Comprehensive Reader, Gatekeeper, and Analyst agents | |
| | **Advanced Retrieval** | KV-cache optimization, vector + graph search fallbacks | |
| | **Document Support** | 7 file types with automatic format detection | |
| | **Real-time Streaming** | SSE-based streaming responses with source citations | |
| | **Async Processing** | Non-blocking document ingestion with job tracking | |
| | **Admin Dashboard** | Monitor system status, manage documents, view embeddings | |
| | **Docker Ready** | Complete docker-compose setup included | |
|
|
| --- |
|
|
| ## ποΈ Architecture |
|
|
| ### System Design |
|
|
| ``` |
| βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ |
| β Flask Web UI (port 5050) β |
| β Document Ingestion β’ Query β’ Output Rendering β |
| ββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββββββ |
| β |
| ββββββββββββββββββββββΌβββββββββββββββββββββββββββββββββββββββββ |
| β Flask REST API (app.py) β |
| β POST /api/ingest β POST /api/query β GET /api/status β |
| ββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββββββ |
| β |
| ββββββββββββββββββββββΌβββββββββββββββββββββββββββββββββββββββββ |
| β CrewAI Agent Layer (agents/crew.py) β |
| β β’ Ingestor Agent β Document loading & chunking β |
| β β’ Comprehensive Agent β Full-document reasoning (KV cache)β |
| β β’ Gatekeeper Agent β Context verification β |
| β β’ Analyst Agent β Answer synthesis β |
| ββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββββββ |
| β |
| βββββββββββββββββΌββββββββββββββββ |
| β β β |
| ββββββΌβββββ βββββββββΌβββββ ββββββββββΌβββββββ |
| β Pipelineβ β LLM Srvr β β Embed Server β |
| β Data β β :8002 β β :8003 β |
| βProcessingβ βQwen2.5-1.5B-Instruct β β BAAI/bge-small-en-v1.5 β |
| ββββββ¬βββββ βββββββββββββ ββββββββββββββββ |
| β |
| βββ ChromaDB (Vector Store, embedded, BM25 hybrid search) |
| βββ Kuzu (Graph DB) |
| ``` |
|
|
| ### Data Flow: Ingestion Pipeline |
|
|
| ``` |
| User Upload |
| β |
| [Document Loader] β Extract text (PDF, DOCX, XLSX, CSV, TXT, OCR) |
| β |
| [Chunker] β Split into 512-token chunks (64 overlap) |
| β |
| [Embedder] β Generate dense/sparse embeddings (BAAI/bge-small-en-v1.5) |
| β |
| βββββββββββββββββββββββββββββββββββββββββββ |
| β [ChromaDB] Vector Store (embedded) β |
| β Stores: chunks + embeddings + metadata β |
| β Search: BM25 (Dense ANN + BM25 / RRF) β |
| βββββββββββββββββββββββββββββββββββββββββββ |
| β |
| [Entity Extraction] β LLM-powered entity detection |
| β |
| βββββββββββββββββββββββββββββββββββββββββββ |
| β [Kuzu] Graph DB β |
| β Stores: entities + relationships β |
| βββββββββββββββββββββββββββββββββββββββββββ |
| ``` |
|
|
| ### Data Flow: Query Pipeline |
|
|
| ``` |
| User Query |
| β |
| [Comprehensive Agent] β Full-document reasoning (KV cache) |
| β |
| [Context Verification] β Gatekeeper validates groundedness |
| β |
| [Answer Synthesis] β Analyst generates markdown response |
| β |
| [SSE Streaming] β Real-time chunks to UI |
| β |
| User sees answer with source citations |
| ``` |
|
|
| --- |
|
|
| ## π Quick Start |
|
|
| ### Prerequisites |
|
|
| - Python 3.10+ |
| - Docker & Docker Compose (optional) |
| - 8GB+ RAM recommended |
| - CUDA/ROCm support (optional, for GPU acceleration) |
|
|
| ### Installation |
|
|
| #### 1. Clone Repository |
|
|
| ```bash |
| git clone https://github.com/Sam-max1/healthexpert.git |
| cd healthexpert |
| ``` |
|
|
| #### 2. Set Up Python Environment |
|
|
| ```bash |
| # Create virtual environment |
| python -m venv venv |
| source venv/bin/activate # On Windows: venv\Scripts\activate |
| |
| # Install dependencies |
| pip install -r requirements.txt |
| |
| # Set HuggingFace token for private KB document syncing |
| export HF_PRIVATE_TOKEN=$(secret-tool lookup api huggingface) |
| ``` |
|
|
| #### 3. Start Microservices |
|
|
| **Terminal 1 - LLM Generation Server (port 8002):** |
| ```bash |
| python agents/gen_llm.py |
| # Expected output: |
| # * Running on http://127.0.0.1:8002 |
| ``` |
|
|
| **Terminal 2 - Embedding Server (port 8003):** |
| ```bash |
| python agents/embed_llm.py |
| # Expected output: |
| # * Running on http://127.0.0.1:8003 |
| ``` |
|
|
| **Terminal 3 - Main Flask App (port 5050):** |
| ```bash |
| python app.py |
| # Expected output: |
| # * Running on http://127.0.0.1:5050 |
| ``` |
|
|
| #### 4. Access Web UI |
|
|
| Open your browser: **http://localhost:5050** |
|
|
| ### Using Docker Compose |
|
|
| ```bash |
| # Start all services |
| # Ensure HF_PRIVATE_TOKEN is set in your environment or .env file before running |
| docker-compose up -d |
| |
| # View logs |
| docker-compose logs -f |
| |
| # Stop services |
| docker-compose down |
| ``` |
|
|
| ### CLI Usage |
|
|
| ```bash |
| # Ingest a document |
| python healthexpert.py ingest path/to/document.pdf |
| |
| # Query documents |
| python healthexpert.py query "What is the main topic?" |
| |
| # List ingested documents |
| python healthexpert.py list |
| |
| # Check system status |
| python healthexpert.py status |
| |
| # Clear all documents |
| python healthexpert.py clear |
| ``` |
|
|
| --- |
|
|
| ## π Documentation |
|
|
| ### Project Structure |
|
|
| ``` |
| healthexpert/ |
| βββ app.py # Flask REST API |
| βββ config.py # Configuration (env-based) |
| βββ healthexpert.py # CLI interface |
| βββ requirements.txt # Python dependencies |
| βββ docker-compose.yml # Docker setup |
| β |
| βββ agents/ # CrewAI agents |
| β βββ crew.py # Crew orchestration |
| β βββ llm.py # LLM integration |
| β βββ tools.py # Agent tools |
| β βββ gen_llm.py # LLM generation server (port 8002) |
| β βββ embed_llm.py # Embedding server (port 8003) |
| β |
| βββ pipeline/ # Data processing |
| β βββ document_loader.py # Multi-format document loader |
| β βββ chunker.py # Text chunking (512 tokens) |
| β βββ embedder.py # Embedding HTTP client |
| β βββ vector_store.py # ChromaDB + BM25 hybrid search |
| β βββ graph_store.py # Kuzu integration |
| β |
| βββ templates/ # Web UI (HTML) |
| β βββ index.html # Main interface |
| β |
| βββ static/ # Frontend assets |
| β βββ app.js # WebSocket + SSE handling |
| β βββ style.css # UI styling |
| β |
| βββ data/ # Runtime data |
| βββ security.key # Fernet key (local-only) |
| βββ uploads/ # Uploaded documents |
| ``` |
|
|
| ### Environment Configuration |
|
|
| Create `.env` file to override defaults: |
|
|
| ```env |
| # LLM Generation Server (port 8002) |
| LLM_BASE_URL=http://127.0.0.1:8002 |
| HF_PRIVATE_TOKEN=your_huggingface_token_here |
| LLM_MODEL_ID=Qwen/Qwen2.5-1.5B-Instruct |
| LLM_MAX_TOKENS=2048 |
| LLM_TEMPERATURE=0.7 |
| LLM_TOP_P=0.9 |
| LLM_TIMEOUT=600 |
| |
| # Embedding Server (port 8003) |
| EMBED_BASE_URL=http://127.0.0.1:8003 |
| EMBEDDING_MODEL=BAAI/bge-small-en-v1.5 |
| EMBEDDING_BATCH_SIZE=12 |
| EMBEDDING_TIMEOUT=120 |
| |
| # Vector Database (ChromaDB β embedded, no server required) |
| CHROMA_PERSIST_DIR=./data/chroma_db |
| CHROMA_COLLECTION=Document |
| ENCRYPTION_KEY_FILE=./data/security.key |
| |
| # Kuzu |
| KUZU_URI=bolt://localhost:7687 |
| KUZU_USER=kuzu |
| KUZU_PASSWORD=healthexpert |
| |
| # Flask |
| UPLOAD_FOLDER=./uploads |
| SECRET_KEY=your-secret-key-here |
| CHUNK_SIZE=512 |
| CHUNK_OVERLAP=64 |
| ``` |
|
|
| ### API Endpoints |
|
|
| #### Ingestion |
|
|
| **POST /api/ingest** |
| ```bash |
| curl -X POST -F "file=@document.pdf" http://localhost:5050/api/ingest |
| |
| # Response: |
| # { "job_id": "abc-123", "status": "processing" } |
| ``` |
|
|
| #### Query |
|
|
| **POST /api/query** |
| ```bash |
| curl -X POST -H "Content-Type: application/json" \ |
| -d '{"query":"What is the main topic?"}' \ |
| http://localhost:5050/api/query |
| |
| # Returns: Server-Sent Events stream |
| ``` |
|
|
| #### Status |
|
|
| **GET /api/ingest/status/<job_id>** |
| ```bash |
| curl http://localhost:5050/api/ingest/status/abc-123 |
| ``` |
|
|
| --- |
|
|
| ## π§ Development |
|
|
| ### Running Tests |
|
|
| ```bash |
| # Run integration tests |
| python -m pytest HEALTHEXPERT_UNIT_INTEGRATION_TEST.md -v |
| |
| # Run specific agent test |
| python -m pytest agents/test_agents.py -v |
| ``` |
|
|
| ### Code Style |
|
|
| ```bash |
| # Format code |
| black healthexpert/ agents/ pipeline/ |
| |
| # Lint |
| flake8 healthexpert/ agents/ pipeline/ --max-line-length=100 |
| ``` |
|
|
| ### Debugging |
|
|
| Enable debug logging: |
|
|
| ```bash |
| export LOG_LEVEL=DEBUG |
| python app.py |
| ``` |
|
|
| View logs: |
|
|
| ```bash |
| tail -f logs/app.log |
| ``` |
|
|
| --- |
|
|
| ## π€ Contributing |
|
|
| We welcome contributions! Please see [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines. |
|
|
| ### How to Contribute |
|
|
| 1. **Fork** the repository |
| 2. **Create** a feature branch (`git checkout -b feature/amazing-feature`) |
| 3. **Commit** changes (`git commit -m 'Add amazing feature'`) |
| 4. **Push** to branch (`git push origin feature/amazing-feature`) |
| 5. **Open** a Pull Request |
|
|
| ### Development Setup |
|
|
| ```bash |
| # Clone fork |
| git clone https://github.com/YOUR_USERNAME/healthexpert.git |
| |
| # Create development environment |
| python -m venv venv_dev |
| source venv_dev/bin/activate |
| pip install -r requirements.txt |
| |
| # Install dev tools |
| pip install pytest black flake8 |
| |
| # Run tests |
| pytest tests/ |
| ``` |
|
|
| --- |
|
|
| ## π Roadmap |
|
|
| - [x] Multi-agent RAG pipeline |
| - [x] Web UI with streaming responses |
| - [x] Docker containerization |
| - [x] Hybrid vector+graph retrieval |
| - [ ] Advanced metrics dashboard |
| - [ ] Multi-language support |
| - [ ] Fine-tuned domain models |
| - [ ] Enterprise auth (OAuth2, SAML) |
| - [ ] Prompt versioning |
| - [ ] Batch processing API |
|
|
| --- |
|
|
| ## π License |
|
|
| This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details. |
|
|
| --- |
|
|
| ## π¨βπ» Author |
|
|
| **Sam-max1** |
|
|
| <div align="center"> |
|
|
| ### π If you find this project helpful, please consider giving it a star! β |
|
|
| </div> |
|
|
| --- |
|
|
| ## π Acknowledgments |
|
|
| - [CrewAI](https://crewai.com/) - Multi-agent framework |
| - [LangChain](https://langchain.com/) - LLM orchestration |
| - [ChromaDB](https://www.trychroma.com/) - Embedded vector database |
| - [rank-bm25](https://github.com/dorianbrown/rank_bm25) - BM25 for BM25 hybrid search |
| - [Kuzu](https://kuzu.com/) - Graph database |
| - [Qwen](https://qwenlm.github.io/) - LLM models |
| - [BAAI BGE](https://github.com/FlagOpen/FlagEmbedding) - Embedding models |
|
|
| --- |
|
|
| ## π Support |
|
|
| - **Issues**: [GitHub Issues](https://github.com/Sam-max1/healthexpert/issues) |
| - **LinkedIn DM**: [Sam-max1](https://www.linkedin.com/in/sam-max1) |
| - **Documentation**: See [HEALTHEXPERT_ARCHITECTURE_DESIGN.md](HEALTHEXPERT_ARCHITECTURE_DESIGN.md) |
|
|
| --- |
|
|
| <div align="center"> |
|
|
| **Built with β€οΈ for AI-powered document analysis** |
|
|
| </div> |
|
|