diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000000000000000000000000000000000000..c65cc9992e5b6c7bdee126cdca4618c616dcec05 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,15 @@ +__pycache__/ +*.pyc +*.pyo +*.pyd +*.sqlite3 +.env +.env.* +.git/ +.gitignore +.vscode/ +.idea/ +logs/ +data/ +**/__pycache__/ +**/*.py[cod] diff --git a/.env b/.env new file mode 100644 index 0000000000000000000000000000000000000000..53968d7f958383cb8bf93b0b9da7721d6d87525e --- /dev/null +++ b/.env @@ -0,0 +1,10 @@ +# OpenAI Configuration +OPENAI_API_KEY=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 + +LANGSMITH_API_KEY=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 + +LANGSMITH_PROJECT=medical_chatbot +LANGCHAIN_PROJECT=medical_chatbot + +LANGSMITH_URL=https://api.smith.langchain.com + diff --git a/.env.example b/.env.example new file mode 100644 index 0000000000000000000000000000000000000000..64be77802c8d138c30367dd4f1d84e542bfd2d38 --- /dev/null +++ b/.env.example @@ -0,0 +1,10 @@ +# OpenAI Configuration +OPENAI_API_KEY= +OPENAI_BASE_URL= + +LANGSMITH_API_KEY= + +LANGSMITH_PROJECT= +LANGCHAIN_PROJECT= + +LANGSMITH_URL= \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..686651998f13911625f4029d7d5855c9ff5561fb --- /dev/null +++ b/Dockerfile @@ -0,0 +1,50 @@ +# ======================== +# Stage 1 - Builder +# ======================== +FROM python:3.10-slim AS builder + +# Install build dependencies +RUN apt-get update && apt-get install -y \ + build-essential \ + gcc \ + g++ \ + && rm -rf /var/lib/apt/lists/* + +WORKDIR /app + +# Copy only requirements first (better caching) +COPY requirements.txt . + +# Install dependencies +RUN pip install --no-cache-dir -r requirements.txt + +# ======================== +# Stage 2 - Final Runtime Image +# ======================== +FROM python:3.10-slim + +# Install minimal runtime dependencies +RUN apt-get update && apt-get install -y \ + && rm -rf /var/lib/apt/lists/* + +# Create a non-root user +RUN useradd --create-home --shell /bin/bash appuser +WORKDIR /app + +# Copy installed packages and application code +COPY --from=builder /usr/local/lib/python3.10/site-packages /usr/local/lib/python3.10/site-packages +COPY --from=builder /usr/local/bin /usr/local/bin +COPY . /app + +# Set permissions +RUN chown -R appuser:appuser /app +USER appuser + +# Expose port +EXPOSE 8000 + +# Set the working directory to the backend folder +WORKDIR /app + +# Command to run the FastAPI app +CMD ["sh", "-c", "uvicorn api.app:app --host 0.0.0.0 --port ${PORT:-8000}"] \ No newline at end of file diff --git a/api/__init__.py b/api/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/api/__pycache__/__init__.cpython-311.pyc b/api/__pycache__/__init__.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..cb65a50ab03406298e49d56bebb50494d56d3423 Binary files /dev/null and b/api/__pycache__/__init__.cpython-311.pyc differ diff --git a/api/__pycache__/__init__.cpython-312.pyc b/api/__pycache__/__init__.cpython-312.pyc new file mode 100644 index 0000000000000000000000000000000000000000..35aecc281f21855cd13c4b9cb66e5fb0d7553174 Binary files /dev/null and b/api/__pycache__/__init__.cpython-312.pyc differ diff --git a/api/__pycache__/__init__.cpython-313.pyc b/api/__pycache__/__init__.cpython-313.pyc new file mode 100644 index 0000000000000000000000000000000000000000..406ffdda0358429bff0a993d8f3b37d2d67d7ef1 Binary files /dev/null and b/api/__pycache__/__init__.cpython-313.pyc differ diff --git a/api/__pycache__/app.cpython-311.pyc b/api/__pycache__/app.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..b5db83f969cc4654295c753f59c782046fcdc189 Binary files /dev/null and b/api/__pycache__/app.cpython-311.pyc differ diff --git a/api/__pycache__/app.cpython-312.pyc b/api/__pycache__/app.cpython-312.pyc new file mode 100644 index 0000000000000000000000000000000000000000..6e65776c704a6b88fef1cec90c6cdc36780f2a23 Binary files /dev/null and b/api/__pycache__/app.cpython-312.pyc differ diff --git a/api/__pycache__/app.cpython-313.pyc b/api/__pycache__/app.cpython-313.pyc new file mode 100644 index 0000000000000000000000000000000000000000..d6d8475efba61f55d9f1d7bb5e966c7c5a17eed2 Binary files /dev/null and b/api/__pycache__/app.cpython-313.pyc differ diff --git a/api/__pycache__/exceptions.cpython-311.pyc b/api/__pycache__/exceptions.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..6b743771c507ec3be28d8107f78815ae008622ce Binary files /dev/null and b/api/__pycache__/exceptions.cpython-311.pyc differ diff --git a/api/__pycache__/exceptions.cpython-313.pyc b/api/__pycache__/exceptions.cpython-313.pyc new file mode 100644 index 0000000000000000000000000000000000000000..634c98a53d59a029df6898223c47e13542509df4 Binary files /dev/null and b/api/__pycache__/exceptions.cpython-313.pyc differ diff --git a/api/__pycache__/middleware.cpython-311.pyc b/api/__pycache__/middleware.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..9c25b5d403e926db89ee4b9b5b52366aef81046c Binary files /dev/null and b/api/__pycache__/middleware.cpython-311.pyc differ diff --git a/api/__pycache__/middleware.cpython-313.pyc b/api/__pycache__/middleware.cpython-313.pyc new file mode 100644 index 0000000000000000000000000000000000000000..a0018643be973ae54ec11947f3b6c79d6d71db79 Binary files /dev/null and b/api/__pycache__/middleware.cpython-313.pyc differ diff --git a/api/__pycache__/models.cpython-311.pyc b/api/__pycache__/models.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..60734ec43e0602c57cd89395917fb63ab8909f61 Binary files /dev/null and b/api/__pycache__/models.cpython-311.pyc differ diff --git a/api/__pycache__/models.cpython-313.pyc b/api/__pycache__/models.cpython-313.pyc new file mode 100644 index 0000000000000000000000000000000000000000..4775bdcdb51c9d9f9e80a6aff18b453c96160388 Binary files /dev/null and b/api/__pycache__/models.cpython-313.pyc differ diff --git a/api/app.py b/api/app.py new file mode 100644 index 0000000000000000000000000000000000000000..660a0a8cd5bb341f331c92560c7de86297d29fc3 --- /dev/null +++ b/api/app.py @@ -0,0 +1,105 @@ + +import logging +from contextlib import asynccontextmanager +from fastapi import FastAPI, HTTPException +from fastapi.exceptions import RequestValidationError +from starlette.exceptions import HTTPException as StarletteHTTPException + +# Import routers +from api.routers import medical, health +from api.middleware import ( + ProcessTimeMiddleware, + LoggingMiddleware, + RateLimitMiddleware, + get_cors_middleware_config +) +from fastapi.middleware.cors import CORSMiddleware +from api.exceptions import ( + http_exception_handler, + validation_exception_handler, + general_exception_handler, + starlette_exception_handler +) + +# Configure logging +logging.basicConfig(level=logging.INFO) +logger = logging.getLogger(__name__) + + +@asynccontextmanager +async def lifespan(app: FastAPI): + """Application lifespan management with background initialization""" + # Startup + logger.info("Starting Medical RAG AI Advisor API...") + + # Start background initialization of heavy components + try: + from background_init import start_background_initialization + logger.info("🚀 Starting background initialization of components...") + start_background_initialization() + logger.info("API started successfully (components loading in background)") + except Exception as e: + logger.error(f"Failed to start background initialization: {e}") + logger.info("API started with lazy loading fallback") + + yield + + # Shutdown + logger.info("Shutting down Medical RAG AI Advisor API...") + + +# Create FastAPI application +app = FastAPI( + title="Medical RAG AI Advisor API", + description="Professional API for medical information retrieval and advisory services", + version="1.0.0", + docs_url="/docs", + redoc_url="/redoc", + lifespan=lifespan +) + +# Add middleware +app.add_middleware(CORSMiddleware, **get_cors_middleware_config()) +app.add_middleware(ProcessTimeMiddleware) +app.add_middleware(LoggingMiddleware) +app.add_middleware(RateLimitMiddleware, calls_per_minute=100) # Adjust as needed + +# Add exception handlers +app.add_exception_handler(HTTPException, http_exception_handler) +app.add_exception_handler(RequestValidationError, validation_exception_handler) +app.add_exception_handler(StarletteHTTPException, starlette_exception_handler) +app.add_exception_handler(Exception, general_exception_handler) + +# Include routers +app.include_router(health.router) +app.include_router(medical.router) + +# Root endpoint +@app.get("/") +async def root(): + """Root endpoint with API information""" + return { + "name": "Medical RAG AI Advisor API", + "version": "1.0.0", + "description": "Professional API for medical information retrieval and advisory services", + "docs": "/docs", + "health": "/health", + "endpoints": { + "ask": "/ask", + "ask_stream": "/ask/stream", + "initialization_status": "/health/initialization" + } + } + + + + +if __name__ == "__main__": + import uvicorn + uvicorn.run( + "api.app:app", + host="127.0.0.1", + port=8000, + reload=True, + log_level="info" + ) diff --git a/api/exceptions.py b/api/exceptions.py new file mode 100644 index 0000000000000000000000000000000000000000..95c2516858364cb87243a83fa631e0c5c9f267df --- /dev/null +++ b/api/exceptions.py @@ -0,0 +1,71 @@ +""" +Exception handlers for Medical RAG AI Advisor API +""" +import logging +from datetime import datetime +from fastapi import Request, HTTPException +from fastapi.responses import JSONResponse +from fastapi.exceptions import RequestValidationError +from starlette.exceptions import HTTPException as StarletteHTTPException + +from api.models import ErrorResponse + +logger = logging.getLogger(__name__) + + +async def http_exception_handler(request: Request, exc: HTTPException): + """Handle HTTP exceptions""" + logger.error(f"HTTP Exception: {exc.status_code} - {exc.detail}") + + return JSONResponse( + status_code=exc.status_code, + content=ErrorResponse( + error="HTTP_ERROR", + message=exc.detail, + timestamp=datetime.now().isoformat() + ).dict() + ) + + +async def validation_exception_handler(request: Request, exc: RequestValidationError): + """Handle request validation errors""" + logger.error(f"Validation Error: {exc.errors()}") + + return JSONResponse( + status_code=422, + content=ErrorResponse( + error="VALIDATION_ERROR", + message="Request validation failed", + details={"validation_errors": exc.errors()}, + timestamp=datetime.now().isoformat() + ).dict() + ) + + +async def general_exception_handler(request: Request, exc: Exception): + """Handle general exceptions""" + logger.error(f"Unhandled Exception: {type(exc).__name__} - {str(exc)}") + + return JSONResponse( + status_code=500, + content=ErrorResponse( + error="INTERNAL_SERVER_ERROR", + message="An internal server error occurred", + details={"exception_type": type(exc).__name__}, + timestamp=datetime.now().isoformat() + ).dict() + ) + + +async def starlette_exception_handler(request: Request, exc: StarletteHTTPException): + """Handle Starlette HTTP exceptions""" + logger.error(f"Starlette HTTP Exception: {exc.status_code} - {exc.detail}") + + return JSONResponse( + status_code=exc.status_code, + content=ErrorResponse( + error="HTTP_ERROR", + message=exc.detail, + timestamp=datetime.now().isoformat() + ).dict() + ) diff --git a/api/middleware.py b/api/middleware.py new file mode 100644 index 0000000000000000000000000000000000000000..3c78db9861ae6287c8072dabf24a77dd74f59fd1 --- /dev/null +++ b/api/middleware.py @@ -0,0 +1,100 @@ +""" +Middleware for Medical RAG AI Advisor API +""" +import time +import logging +from typing import Callable, Awaitable +from fastapi import Request, Response, HTTPException +from fastapi.middleware.cors import CORSMiddleware +from starlette.middleware.base import BaseHTTPMiddleware + +logger = logging.getLogger(__name__) + + +class ProcessTimeMiddleware(BaseHTTPMiddleware): + """Middleware to add processing time to response headers""" + + async def dispatch(self, request: Request, call_next: Callable) -> Response: + start_time = time.time() + response = await call_next(request) + process_time = time.time() - start_time + response.headers["X-Process-Time"] = f"{process_time:.4f}" + return response + + +class LoggingMiddleware(BaseHTTPMiddleware): + """Middleware for request/response logging""" + + async def dispatch(self, request: Request, call_next: Callable) -> Response: + start_time = time.time() + + # Log request + logger.info(f"Request: {request.method} {request.url}") + + try: + response = await call_next(request) + process_time = time.time() - start_time + + # Log response + logger.info( + f"Response: {response.status_code} - " + f"Time: {process_time:.4f}s - " + f"Path: {request.url.path}" + ) + + return response + + except Exception as e: + process_time = time.time() - start_time + logger.error( + f"Error: {str(e)} - " + f"Time: {process_time:.4f}s - " + f"Path: {request.url.path}" + ) + raise + + +class RateLimitMiddleware(BaseHTTPMiddleware): + """Simple rate limiting middleware""" + + def __init__(self, app, calls_per_minute: int = 60): + super().__init__(app) + self.calls_per_minute = calls_per_minute + self.client_calls = {} + + async def dispatch(self, request: Request, call_next: Callable) -> Response: + client_ip = request.client.host + current_time = time.time() + + # Clean old entries + self.client_calls = { + ip: calls for ip, calls in self.client_calls.items() + if any(call_time > current_time - 60 for call_time in calls) + } + + # Check rate limit + if client_ip in self.client_calls: + recent_calls = [ + call_time for call_time in self.client_calls[client_ip] + if call_time > current_time - 60 + ] + if len(recent_calls) >= self.calls_per_minute: + raise HTTPException( + status_code=429, + detail="Rate limit exceeded. Please try again later." + ) + self.client_calls[client_ip] = recent_calls + [current_time] + else: + self.client_calls[client_ip] = [current_time] + + return await call_next(request) + + +def get_cors_middleware_config(): + """Get CORS middleware configuration""" + return { + "allow_origins": ["*"], # Configure appropriately for production + "allow_credentials": True, + "allow_methods": ["*"], + "allow_headers": ["*"], + } diff --git a/api/models.py b/api/models.py new file mode 100644 index 0000000000000000000000000000000000000000..7bb69eac05a05b836a0e974aee4c4446fdc687f6 --- /dev/null +++ b/api/models.py @@ -0,0 +1,97 @@ +""" +API Models and Schemas for Medical RAG AI Advisor +""" +from pydantic import BaseModel, Field +from typing import Optional, List, Dict, Any +from enum import Enum + + +class QueryType(str, Enum): + """Types of medical queries supported""" + GENERAL = "general" + DRUG_INTERACTION = "drug_interaction" + SIDE_EFFECTS = "side_effects" + GUIDELINES = "guidelines" + COMPARISON = "comparison" + + +class QueryRequest(BaseModel): + """Request model for medical queries""" + query: str = Field(..., description="Medical question or query", min_length=1) + query_type: Optional[QueryType] = Field(None, description="Type of medical query") + context: Optional[str] = Field(None, description="Additional context for the query") + patient_info: Optional[Dict[str, Any]] = Field(None, description="Patient information if relevant") + + +class QueryResponse(BaseModel): + """Response model for medical queries""" + response: str = Field(..., description="AI-generated medical response") + sources: Optional[List[str]] = Field(None, description="Sources used for the response") + confidence: Optional[float] = Field(None, description="Confidence score of the response") + query_type: Optional[QueryType] = Field(None, description="Detected or specified query type") + processing_time: Optional[float] = Field(None, description="Time taken to process the query") + + +class StreamChunk(BaseModel): + """Model for streaming response chunks""" + chunk: str = Field(..., description="Chunk of the streaming response") + is_final: bool = Field(False, description="Whether this is the final chunk") + + +class SideEffectReport(BaseModel): + """Model for side effect reporting""" + drug_name: str = Field(..., description="Name of the drug") + side_effects: str = Field(..., description="Reported side effects") + patient_age: Optional[int] = Field(None, description="Patient age") + patient_gender: Optional[str] = Field(None, description="Patient gender") + dosage: Optional[str] = Field(None, description="Drug dosage") + duration: Optional[str] = Field(None, description="Duration of treatment") + severity: Optional[str] = Field(None, description="Severity of side effects") + outcome: Optional[str] = Field(None, description="Outcome of the side effects") + additional_details: Optional[str] = Field(None, description="Additional clinical details") + + +class SideEffectResponse(BaseModel): + """Response model for side effect reporting""" + report_id: str = Field(..., description="Unique identifier for the report") + status: str = Field(..., description="Status of the report submission") + message: str = Field(..., description="Confirmation message") + recommendations: Optional[List[str]] = Field(None, description="Clinical recommendations") + + +class ComparisonRequest(BaseModel): + """Request model for provider/treatment comparisons""" + providers: List[str] = Field(..., description="List of providers to compare", min_items=2) + criteria: Optional[List[str]] = Field(None, description="Specific criteria for comparison") + + +class ComparisonResponse(BaseModel): + """Response model for provider/treatment comparisons""" + comparison: str = Field(..., description="Detailed comparison analysis") + summary: Dict[str, Any] = Field(..., description="Summary of key differences") + recommendations: Optional[str] = Field(None, description="Recommendations based on comparison") + + +class InitializationStatus(BaseModel): + """Initialization status response model""" + is_complete: bool = Field(..., description="Whether initialization is complete") + status_message: str = Field(..., description="Current initialization status") + is_successful: bool = Field(..., description="Whether initialization was successful") + error: Optional[str] = Field(None, description="Initialization error if any") + + +class HealthStatus(BaseModel): + """Health check response model""" + status: str = Field(..., description="API health status") + version: str = Field(..., description="API version") + timestamp: str = Field(..., description="Current timestamp") + components: Dict[str, str] = Field(..., description="Status of system components") + initialization: Optional[InitializationStatus] = Field(None, description="Background initialization status") + + +class ErrorResponse(BaseModel): + """Error response model""" + error: str = Field(..., description="Error type") + message: str = Field(..., description="Error message") + details: Optional[Dict[str, Any]] = Field(None, description="Additional error details") + timestamp: str = Field(..., description="Error timestamp") diff --git a/api/routers/__init__.py b/api/routers/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/api/routers/__pycache__/__init__.cpython-311.pyc b/api/routers/__pycache__/__init__.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..b4c5c4f3e349ef4504df4e99e238873942efa62d Binary files /dev/null and b/api/routers/__pycache__/__init__.cpython-311.pyc differ diff --git a/api/routers/__pycache__/__init__.cpython-313.pyc b/api/routers/__pycache__/__init__.cpython-313.pyc new file mode 100644 index 0000000000000000000000000000000000000000..9707ae7d0edf0b0691dabee3d38da574906057ae Binary files /dev/null and b/api/routers/__pycache__/__init__.cpython-313.pyc differ diff --git a/api/routers/__pycache__/health.cpython-311.pyc b/api/routers/__pycache__/health.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..d258144b9ce0dffbd94d5a93dd0136dda14c7d7e Binary files /dev/null and b/api/routers/__pycache__/health.cpython-311.pyc differ diff --git a/api/routers/__pycache__/health.cpython-313.pyc b/api/routers/__pycache__/health.cpython-313.pyc new file mode 100644 index 0000000000000000000000000000000000000000..ce62a444e8a1212d873b8328fbae316652d17bf7 Binary files /dev/null and b/api/routers/__pycache__/health.cpython-313.pyc differ diff --git a/api/routers/__pycache__/medical.cpython-311.pyc b/api/routers/__pycache__/medical.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..5f32b5c0907e6043f4e45aecf1780d13a4b62fd4 Binary files /dev/null and b/api/routers/__pycache__/medical.cpython-311.pyc differ diff --git a/api/routers/__pycache__/medical.cpython-313.pyc b/api/routers/__pycache__/medical.cpython-313.pyc new file mode 100644 index 0000000000000000000000000000000000000000..d587a2de4fb7ff00af53aa1fc680e4a0d6c53a49 Binary files /dev/null and b/api/routers/__pycache__/medical.cpython-313.pyc differ diff --git a/api/routers/health.py b/api/routers/health.py new file mode 100644 index 0000000000000000000000000000000000000000..c3b8741f1239778fe73b81ec9c10ebb8b30a114f --- /dev/null +++ b/api/routers/health.py @@ -0,0 +1,136 @@ +""" +Health Check and System Status Router +""" +from datetime import datetime +from fastapi import APIRouter +import sys +import os + +# Add src to path for imports +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(__file__)))) + +from api.models import HealthStatus, InitializationStatus + +router = APIRouter(prefix="/health", tags=["health"]) + + +@router.get("/", response_model=HealthStatus) +async def health_check(): + """ + Check the health status of the API and its components + """ + components = {} + + # Check agent availability + try: + from agent import safe_run_agent + components["agent"] = "healthy" + except Exception: + components["agent"] = "unhealthy" + + # Check vector store + try: + from vector_store import VectorStore + components["vector_store"] = "healthy" + except Exception: + components["vector_store"] = "unhealthy" + + # Check data loaders + try: + from data_loaders import load_pdf_documents + components["data_loaders"] = "healthy" + except Exception: + components["data_loaders"] = "unhealthy" + + # Check tools + try: + from tools import medical_guidelines_knowledge_tool + components["tools"] = "healthy" + except Exception: + components["tools"] = "unhealthy" + + # Check initialization status + initialization_status = None + try: + from background_init import ( + is_initialization_complete, + get_initialization_status, + is_initialization_successful, + get_initialization_error + ) + + initialization_status = InitializationStatus( + is_complete=is_initialization_complete(), + status_message=get_initialization_status(), + is_successful=is_initialization_successful(), + error=str(get_initialization_error()) if get_initialization_error() else None + ) + except Exception as e: + initialization_status = InitializationStatus( + is_complete=False, + status_message=f"Unable to check initialization status: {str(e)}", + is_successful=False, + error=str(e) + ) + + # Overall status + overall_status = "healthy" if all( + status == "healthy" for status in components.values() + ) else "degraded" + + return HealthStatus( + status=overall_status, + version="1.0.0", + timestamp=datetime.now().isoformat(), + components=components, + initialization=initialization_status + ) + + +@router.get("/ping") +async def ping(): + """ + Simple ping endpoint for basic connectivity check + """ + return {"message": "pong", "timestamp": datetime.now().isoformat()} + + +@router.get("/initialization", response_model=InitializationStatus) +async def get_initialization_status(): + """ + Get the current initialization status of background components + """ + try: + from background_init import ( + is_initialization_complete, + get_initialization_status, + is_initialization_successful, + get_initialization_error + ) + + return InitializationStatus( + is_complete=is_initialization_complete(), + status_message=get_initialization_status(), + is_successful=is_initialization_successful(), + error=str(get_initialization_error()) if get_initialization_error() else None + ) + except Exception as e: + return InitializationStatus( + is_complete=False, + status_message=f"Unable to check initialization status: {str(e)}", + is_successful=False, + error=str(e) + ) + + +@router.get("/version") +async def get_version(): + """ + Get API version information + """ + return { + "version": "1.0.0", + "name": "Medical RAG AI Advisor API", + "description": "Professional API for medical information retrieval and advisory services", + "build_date": "2024-01-01" + } diff --git a/api/routers/medical.py b/api/routers/medical.py new file mode 100644 index 0000000000000000000000000000000000000000..658398d0a715f334b16de13ff7fb3372401c8bac --- /dev/null +++ b/api/routers/medical.py @@ -0,0 +1,58 @@ +""" +Medical Query Router for RAG AI Advisor +""" +import asyncio +from fastapi import APIRouter, HTTPException +from fastapi.responses import StreamingResponse +import sys +import os + +# Add src to path for imports +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(__file__)))) + +from core.agent import safe_run_agent, safe_run_agent_streaming + +router = APIRouter(tags=["medical"]) + + +@router.get("/ask") +async def ask(query: str): + """ + Process a medical query - agent decides which tools to use + """ + try: + response = await safe_run_agent(user_input=query) + return {"response": response} + + except Exception as e: + raise HTTPException( + status_code=500, + detail=f"Error processing medical query: {str(e)}" + ) + + +@router.get("/ask/stream") +async def ask_stream(query: str): + """ + Process a medical query with streaming response - agent decides which tools to use + """ + async def event_stream(): + try: + chunk_buffer = "" + async for chunk in safe_run_agent_streaming(user_input=query): + chunk_buffer += chunk + + # Send chunks in reasonable sizes for smoother streaming + if len(chunk_buffer) >= 10: # Adjust this value as needed + yield chunk_buffer + chunk_buffer = "" + await asyncio.sleep(0.01) # Small delay for smoother streaming + + # Send any remaining content + if chunk_buffer: + yield chunk_buffer + + except Exception as e: + yield f"Error: {str(e)}" + + return StreamingResponse(event_stream(), media_type="text/markdown") diff --git a/api/routers/side_effects.py b/api/routers/side_effects.py new file mode 100644 index 0000000000000000000000000000000000000000..7312163f50b4f46136db1103da8c298d512a272b --- /dev/null +++ b/api/routers/side_effects.py @@ -0,0 +1,165 @@ +""" +Side Effects Reporting Router +""" +import uuid +import time +from datetime import datetime +from fastapi import APIRouter, HTTPException +import sys +import os + +# Add backend and src directories to path for imports +backend_path = os.path.dirname(os.path.dirname(os.path.dirname(__file__))) +src_path = os.path.join(backend_path, 'src') +sys.path.append(backend_path) +sys.path.append(src_path) + +from api.models import SideEffectReport +from tools import side_effect_recording_tool +from github_storage import get_github_storage + +router = APIRouter(prefix="/side-effects", tags=["side-effects"]) + + +@router.post("/report") +async def report_side_effect(report: SideEffectReport): + """ + Submit a side effect report for pharmacovigilance + """ + try: + # Prepare the report text for the side effect tool + report_text = f"Drug: {report.drug_name}, Side effects: {report.side_effects}" + + if report.patient_age: + report_text += f", Patient age: {report.patient_age}" + if report.patient_gender: + report_text += f", Patient gender: {report.patient_gender}" + if report.dosage: + report_text += f", Dosage: {report.dosage}" + if report.duration: + report_text += f", Duration: {report.duration}" + if report.severity: + report_text += f", Severity: {report.severity}" + if report.outcome: + report_text += f", Outcome: {report.outcome}" + if report.additional_details: + report_text += f", Additional details: {report.additional_details}" + + # Process through the existing side effect recording tool + result = side_effect_recording_tool(report_text) + + return {"result": result} + + except Exception as e: + raise HTTPException( + status_code=500, + detail=f"Error processing side effect report: {str(e)}" + ) + + +@router.get("/reports/summary") +async def get_reports_summary(): + """ + Get summary of side effect reports from GitHub repository + """ + try: + import pandas as pd + import os + + # Try to get reports from GitHub first + github_storage = get_github_storage() + reports = github_storage.get_side_effects_reports() + + if not reports: + # Fallback to local file if GitHub fails + csv_path = "side_effects_reports.csv" + + if not os.path.exists(csv_path): + return { + "total_reports": 0, + "message": "No side effect reports found" + } + + df = pd.read_csv(csv_path) + else: + # Convert GitHub reports to DataFrame + df = pd.DataFrame(reports) + + if df.empty: + return { + "total_reports": 0, + "message": "No side effect reports found" + } + + summary = { + "total_reports": len(df), + "unique_drugs": df['drug_name'].nunique() if 'drug_name' in df.columns else 0, + "recent_reports": len(df[df['timestamp'] >= (datetime.now() - pd.Timedelta(days=30)).strftime('%Y-%m-%d')]) if 'timestamp' in df.columns else 0, + "most_reported_drugs": df['drug_name'].value_counts().head(5).to_dict() if 'drug_name' in df.columns else {} + } + + return summary + + except Exception as e: + raise HTTPException( + status_code=500, + detail=f"Error retrieving reports summary: {str(e)}" + ) + + +@router.get("/drug/{drug_name}/reports") +async def get_drug_reports(drug_name: str): + """ + Get side effect reports for a specific drug from GitHub repository + """ + try: + # Try to get reports from GitHub first + github_storage = get_github_storage() + reports = github_storage.get_drug_reports(drug_name) + + if reports: + return { + "drug_name": drug_name, + "total_reports": len(reports), + "reports": reports + } + + # Fallback to local file if GitHub fails or no reports found + import pandas as pd + import os + + csv_path = "side_effects_reports.csv" + + if not os.path.exists(csv_path): + return { + "drug_name": drug_name, + "reports": [], + "message": "No reports found" + } + + df = pd.read_csv(csv_path) + + # Filter reports for the specific drug (case-insensitive) + drug_reports = df[df['drug_name'].str.lower() == drug_name.lower()] + + if drug_reports.empty: + return { + "drug_name": drug_name, + "reports": [], + "message": f"No reports found for {drug_name}" + } + + # Convert to list of dictionaries + local_reports = drug_reports.to_dict('records') + + return { + "drug_name": drug_name, + "total_reports": len(local_reports), + "reports": local_reports + } + + except Exception as e: + raise HTTPException( + status_code=500, + detail=f"Error retrieving drug reports: {str(e)}" + ) diff --git a/core/__init__.py b/core/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/core/__pycache__/__init__.cpython-311.pyc b/core/__pycache__/__init__.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..379cad35e26d4e6777a14aaaba0f423a58f4ce7e Binary files /dev/null and b/core/__pycache__/__init__.cpython-311.pyc differ diff --git a/core/__pycache__/__init__.cpython-313.pyc b/core/__pycache__/__init__.cpython-313.pyc new file mode 100644 index 0000000000000000000000000000000000000000..266d16855a6788bf3f50a1e7ec3b9379d8682ec6 Binary files /dev/null and b/core/__pycache__/__init__.cpython-313.pyc differ diff --git a/core/__pycache__/agent.cpython-311.pyc b/core/__pycache__/agent.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..8814283c0ca313a0c76be9308d33826d0b1497ce Binary files /dev/null and b/core/__pycache__/agent.cpython-311.pyc differ diff --git a/core/__pycache__/agent.cpython-313.pyc b/core/__pycache__/agent.cpython-313.pyc new file mode 100644 index 0000000000000000000000000000000000000000..05ad6b91374a3ab97dedfd749048f629447c6f28 Binary files /dev/null and b/core/__pycache__/agent.cpython-313.pyc differ diff --git a/core/__pycache__/background_init.cpython-311.pyc b/core/__pycache__/background_init.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..15296eee4d06dc12538429fd261db9532fa4e219 Binary files /dev/null and b/core/__pycache__/background_init.cpython-311.pyc differ diff --git a/core/__pycache__/background_init.cpython-313.pyc b/core/__pycache__/background_init.cpython-313.pyc new file mode 100644 index 0000000000000000000000000000000000000000..bcbc141590692b56653434ad483d51609722f58f Binary files /dev/null and b/core/__pycache__/background_init.cpython-313.pyc differ diff --git a/core/__pycache__/config.cpython-311.pyc b/core/__pycache__/config.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..3d0c9b8df08d4d3beebd64b251caea89943af987 Binary files /dev/null and b/core/__pycache__/config.cpython-311.pyc differ diff --git a/core/__pycache__/config.cpython-313.pyc b/core/__pycache__/config.cpython-313.pyc new file mode 100644 index 0000000000000000000000000000000000000000..f07951c63897ddf55238bafc5daa9c746fa48f1e Binary files /dev/null and b/core/__pycache__/config.cpython-313.pyc differ diff --git a/core/__pycache__/data_loaders.cpython-311.pyc b/core/__pycache__/data_loaders.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..ef6cf387a1fe68359a006138a08b511c3751e93d Binary files /dev/null and b/core/__pycache__/data_loaders.cpython-311.pyc differ diff --git a/core/__pycache__/data_loaders.cpython-313.pyc b/core/__pycache__/data_loaders.cpython-313.pyc new file mode 100644 index 0000000000000000000000000000000000000000..0311dd097c40cb341743e854a039ba1b315dc01d Binary files /dev/null and b/core/__pycache__/data_loaders.cpython-313.pyc differ diff --git a/core/__pycache__/github_storage.cpython-311.pyc b/core/__pycache__/github_storage.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..c27904664ff4417ce32494d24b00cd33be314d0a Binary files /dev/null and b/core/__pycache__/github_storage.cpython-311.pyc differ diff --git a/core/__pycache__/github_storage.cpython-313.pyc b/core/__pycache__/github_storage.cpython-313.pyc new file mode 100644 index 0000000000000000000000000000000000000000..69490e0f133618c04d8383ef67e88c56d35c3c37 Binary files /dev/null and b/core/__pycache__/github_storage.cpython-313.pyc differ diff --git a/core/__pycache__/retrievers.cpython-311.pyc b/core/__pycache__/retrievers.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..008f245fa0b4004858ab6d7e814d99c7a9688739 Binary files /dev/null and b/core/__pycache__/retrievers.cpython-311.pyc differ diff --git a/core/__pycache__/retrievers.cpython-313.pyc b/core/__pycache__/retrievers.cpython-313.pyc new file mode 100644 index 0000000000000000000000000000000000000000..ac639079287d0ab1130148b77e04a73b76a42589 Binary files /dev/null and b/core/__pycache__/retrievers.cpython-313.pyc differ diff --git a/core/__pycache__/text_processors.cpython-311.pyc b/core/__pycache__/text_processors.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..e47d86499676b607d58c9e257d5e54a9e84530f6 Binary files /dev/null and b/core/__pycache__/text_processors.cpython-311.pyc differ diff --git a/core/__pycache__/text_processors.cpython-313.pyc b/core/__pycache__/text_processors.cpython-313.pyc new file mode 100644 index 0000000000000000000000000000000000000000..4890a190c140fdd19b4c12a581d7db2aa8d018e9 Binary files /dev/null and b/core/__pycache__/text_processors.cpython-313.pyc differ diff --git a/core/__pycache__/tools.cpython-311.pyc b/core/__pycache__/tools.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..ff13055c50e220faead6810ae666b61f23ecff02 Binary files /dev/null and b/core/__pycache__/tools.cpython-311.pyc differ diff --git a/core/__pycache__/tools.cpython-313.pyc b/core/__pycache__/tools.cpython-313.pyc new file mode 100644 index 0000000000000000000000000000000000000000..6b126a66b3a122a2bbcf4fbe6743a9e1e89df1c1 Binary files /dev/null and b/core/__pycache__/tools.cpython-313.pyc differ diff --git a/core/__pycache__/tracing.cpython-311.pyc b/core/__pycache__/tracing.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..2f637d3c8786a725854e4025ff7de003c187d91e Binary files /dev/null and b/core/__pycache__/tracing.cpython-311.pyc differ diff --git a/core/__pycache__/tracing.cpython-313.pyc b/core/__pycache__/tracing.cpython-313.pyc new file mode 100644 index 0000000000000000000000000000000000000000..ad9dbd9a920b7766f1e891b05b0f35f45d17c6f5 Binary files /dev/null and b/core/__pycache__/tracing.cpython-313.pyc differ diff --git a/core/__pycache__/utils.cpython-311.pyc b/core/__pycache__/utils.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..fc17f8c189e2a8006564fe498cd3def99788b286 Binary files /dev/null and b/core/__pycache__/utils.cpython-311.pyc differ diff --git a/core/__pycache__/utils.cpython-313.pyc b/core/__pycache__/utils.cpython-313.pyc new file mode 100644 index 0000000000000000000000000000000000000000..5afae12e2bdb372c2d2cea441655de90fb33dfea Binary files /dev/null and b/core/__pycache__/utils.cpython-313.pyc differ diff --git a/core/__pycache__/validation.cpython-311.pyc b/core/__pycache__/validation.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..528581f94615200909e18b2067223842b620433b Binary files /dev/null and b/core/__pycache__/validation.cpython-311.pyc differ diff --git a/core/__pycache__/validation.cpython-313.pyc b/core/__pycache__/validation.cpython-313.pyc new file mode 100644 index 0000000000000000000000000000000000000000..e97788a276ce2b690c94dc98b456920d992b9f60 Binary files /dev/null and b/core/__pycache__/validation.cpython-313.pyc differ diff --git a/core/agent.py b/core/agent.py new file mode 100644 index 0000000000000000000000000000000000000000..6aee9debb3bd8b0ca9dcd7e5369e9ff62f5aea1b --- /dev/null +++ b/core/agent.py @@ -0,0 +1,839 @@ +import logging +import traceback +from typing import Any, AsyncGenerator +import asyncio +import requests +import os +from langchain.agents import create_openai_tools_agent, AgentExecutor +from langchain.memory import ConversationBufferWindowMemory +from langchain.prompts import ChatPromptTemplate, MessagesPlaceholder +from langchain.schema import OutputParserException +from langchain.callbacks.base import BaseCallbackHandler +from openai import RateLimitError, APIError + +from .config import get_llm, logger +from .tools import ( + medical_guidelines_knowledge_tool, + compare_providers_tool, + get_current_datetime_tool, + side_effect_recording_tool, + medical_answer_validation_tool, +) + +# LangSmith tracing utilities +from .tracing import traceable, trace, conversation_tracker, log_to_langsmith +from .validation import validate_medical_answer + + +# ============================================================================ +# STREAMING CALLBACK HANDLER +# ============================================================================ + +class StreamingCallbackHandler(BaseCallbackHandler): + """Custom callback handler for streaming responses.""" + + def __init__(self): + self.tokens = [] + self.current_response = "" + + def on_llm_new_token(self, token: str, **kwargs: Any) -> Any: + """Called when a new token is generated.""" + self.tokens.append(token) + self.current_response += token + + def get_response(self) -> str: + """Get the current response.""" + return self.current_response + + def reset(self): + """Reset the handler for a new response.""" + self.tokens = [] + self.current_response = "" + + +# ============================================================================ +# CUSTOM EXCEPTION CLASSES +# ============================================================================ + +class AgentError(Exception): + """Base exception for agent-related errors.""" + pass + + +class ToolExecutionError(AgentError): + """Exception raised when a tool fails to execute.""" + pass + + +class APIConnectionError(AgentError): + """Exception raised when API connections fail.""" + pass + + +class ValidationError(AgentError): + """Exception raised when input validation fails.""" + pass + + +# ============================================================================ +# AGENT CONFIGURATION +# ============================================================================ + +# Available tools for the agent +AVAILABLE_TOOLS = [ + medical_guidelines_knowledge_tool, + compare_providers_tool, + get_current_datetime_tool, + side_effect_recording_tool, + medical_answer_validation_tool, +] + + +# System message template for the agent +SYSTEM_MESSAGE = """ +You are an advanced Medical Advisor Chatbot for healthcare professionals. +Your primary purpose is to answer clinical and medical questions strictly based on authoritative medical guidelines using the tool "medical_guidelines_knowledge_tool". + +**INSTRUCTIONS:** +- Always answer using only the information retrieved from medical guidelines via "medical_guidelines_knowledge_tool". +- **SIDE EFFECT REPORTING**: When a healthcare professional reports an adverse drug reaction, side effect, or medication-related complication, ALWAYS use the "side_effect_recording_tool" first to document the information. Return the tool's response directly to the user without modification. DO NOT use validation or generate additional reports for side effect reporting queries. +- Use the side effect recording tool when the input contains phrases like: "patient experienced", "side effect", "adverse reaction", "drug reaction", "medication caused", "developed after taking", etc. +- When the side effect recording tool requests additional information, present the request exactly as provided by the tool. +- For every answer, you MUST provide detailed citations including: + * Source file name + * Page number + * Provider name + * Specific location (e.g., Table 1, Figure 2, Box 3, Section Header, etc.) + * Type of content (e.g., table, flowchart, bullet point, paragraph, etc.) +- Use this format for citations: + (Source: [file name], Page: [page number], Provider: [provider name], Location: [specific location], Type: [content type]) +- If multiple sources are used, cite each one with its corresponding metadata. +- If a specific provider (NCCN, ASCO, ESMO, etc.) is mentioned in the question, prioritize information from that provider. +- When citing tables or flowcharts: + * Specify the table/figure number if available + * Describe which part of the table/figure contains the information + * Reference any relevant footnotes or legends +- When citing text: + * Specify the section or subsection heading + * Indicate if it's from a bullet point, paragraph, or other format +- If the answer is not found in the retrieved guidelines, respond: "I do not know." +- Never speculate or provide information not present in the guidelines. +- Always respond in English. + +**FORMATTING:** +- Use markdown formatting for clarity: + * Use bullet points for lists + * Use bold for emphasis on key points + * Use tables when summarizing multiple points + +**SAFETY DISCLAIMER:** +Important: For emergencies call emergency services immediately. This is educational information for healthcare professionals, not a substitute for clinical judgment. + +**EMERGENCY PROTOCOL:** +If the question describes emergency symptoms (chest pain, difficulty breathing, severe bleeding, loss of consciousness, etc.), immediately respond: +"This is an emergency! Call emergency services immediately and seek urgent medical help." + +**Language:** +- Always respond in English. +""" + +# Create the prompt template +prompt_template = ChatPromptTemplate.from_messages([ + ("system", SYSTEM_MESSAGE), + MessagesPlaceholder("chat_history"), + ("human", "{input}"), + MessagesPlaceholder("agent_scratchpad"), +]) + +# Initialize the agent with lazy loading +def get_agent(): + """Get agent with lazy loading for faster startup""" + return create_openai_tools_agent( + llm=get_llm(), + tools=AVAILABLE_TOOLS, + prompt=prompt_template, + ) + +# Create agent executor with lazy loading +def get_agent_executor(): + """Get agent executor with lazy loading for faster startup""" + return AgentExecutor( + agent=get_agent(), + tools=AVAILABLE_TOOLS, + verbose=True, + handle_parsing_errors=True, + max_iterations=5, + max_execution_time=90, # tighten a bit to help responsiveness + ) + +# Initialize memory +memory = ConversationBufferWindowMemory( + memory_key="chat_history", + return_messages=True, + max_window_size=10 +) + + +# ============================================================================ +# VALIDATION HELPER FUNCTIONS +# ============================================================================ + +def _should_validate_response(user_input: str, response: str) -> bool: + """ + Determine if a response should be automatically validated. + + Args: + user_input: The user's input + response: The agent's response + + Returns: + bool: True if the response should be validated + """ + # Skip validation for certain types of responses + skip_indicators = [ + "side effect report", + "adverse drug reaction report", + "error:", + "sorry,", + "i don't know", + "i do not know", + "validation report", + "evaluation scores" + ] + + # Skip validation for side effect reporting queries in user input + side_effect_input_indicators = [ + "side effect", "adverse reaction", "adverse event", "drug reaction", + "medication reaction", "patient experienced", "developed after taking", + "caused by medication", "drug-related", "medication-related" + ] + + user_input_lower = user_input.lower() + response_lower = response.lower() + + # Don't validate if user input is about side effect reporting + if any(indicator in user_input_lower for indicator in side_effect_input_indicators): + return False + + # Don't validate if response contains skip indicators + if any(indicator in response_lower for indicator in skip_indicators): + return False + + # Don't validate very short responses + if len(response.strip()) < 50: + return False + + # Validate if response seems to contain medical information + medical_indicators = [ + "treatment", "therapy", "diagnosis", "medication", "drug", "patient", + "clinical", "guideline", "recommendation", "according to", "source:", + "provider:", "page:", "nccn", "asco", "esmo", "nice" + ] + + return any(indicator in response_lower for indicator in medical_indicators) + + +def _perform_automatic_validation(user_input: str, response: str) -> str: + """ + Perform automatic validation and append results to response. + + Args: + user_input: The user's input + response: The agent's response + + Returns: + str: Response with validation results appended + """ + try: + # Import here to avoid circular imports + from .tools import _last_question, _last_documents, _last_user_question + + # Check if we have the necessary context for validation + if not _last_question or not _last_documents: + logger.info("Skipping validation: insufficient context") + return response + + # Perform validation using the original user input instead of tool query + evaluation = validate_medical_answer(user_input, _last_documents, response) + + # Format validation results + report = evaluation.get("validation_report", {}) + + validation_summary = f""" + +--- + +## 🔍 **AUTOMATIC VALIDATION REPORT** + +**Overall Score:** {report.get('Overall_Rating', 'N/A')}/100 + +**Key Metrics:** + +**Accuracy:** {report.get('Accuracy_Rating', 'N/A')}/100 +{report.get('Accuracy_Comment', 'No comment available')} + +**Coherence:** {report.get('Coherence_Rating', 'N/A')}/100 +{report.get('Coherence_Comment', 'No comment available')} + +**Relevance:** {report.get('Relevance_Rating', 'N/A')}/100 +{report.get('Relevance_Comment', 'No comment available')} + +**Completeness:** {report.get('Completeness_Rating', 'N/A')}/100 +{report.get('Completeness_Comment', 'No comment available')} + +**Citations:** {report.get('Citations_Attribution_Rating', 'N/A')}/100 +{report.get('Citations_Attribution_Comment', 'No comment available')} + +**Length:** {report.get('Length_Rating', 'N/A')}/100 +{report.get('Length_Comment', 'No comment available')} + +**Assessment:** {report.get('Final_Summary_and_Improvement_Plan', 'No assessment available')} + +*Validation ID: {evaluation.get('interaction_id', 'N/A')} | Saved to evaluation_results.json* +""" + + return response + validation_summary + + except Exception as e: + logger.error(f"Automatic validation failed: {e}") + return response + + +# ============================================================================ +# STREAMING AGENT FUNCTIONS +# ============================================================================ + +# @traceable(name="run_agent_streaming") +async def run_agent_streaming(user_input: str, max_retries: int = 3) -> AsyncGenerator[str, None]: + """ + Run the agent with streaming support and comprehensive error handling. + + This function processes user input through the agent executor with streaming + capabilities, robust error handling, and automatic retries for recoverable errors. + + Args: + user_input (str): The user's input message to process + max_retries (int, optional): Maximum number of retries for recoverable errors. + Defaults to 3. + + Yields: + str: Chunks of the agent's response as they are generated + + Raises: + None: All exceptions are caught and handled internally + """ + # Input validation + if not user_input or not user_input.strip(): + logger.warning("Empty input received") + yield "Sorry, I didn't receive any questions. Please enter your question or request." + return + + # Store the original user question for validation + from .tools import store_user_question + store_user_question(user_input.strip()) + + retry_count = 0 + last_error = None + current_run_id = None + # Session metadata (increment conversation count) + session_metadata = conversation_tracker.get_session_metadata(increment=True) + + while retry_count <= max_retries: + try: + # Tracing for streaming disabled to avoid duplicate traces. + # We keep tracing only for the AgentExecutor in run_agent(). + current_run_id = None + # Load conversation history from memory + chat_history = memory.load_memory_variables({})["chat_history"] + + logger.info(f"Processing user input (attempt {retry_count + 1}): {user_input[:50]}...") + + # Create streaming callback handler + streaming_handler = StreamingCallbackHandler() + + # Run the agent in a separate thread to avoid blocking + def run_sync(): + return get_agent_executor().invoke( + { + "input": user_input.strip(), + "chat_history": chat_history, + }, + config={"callbacks": [streaming_handler]}, + ) + + # Execute the agent with streaming + full_response = "" + previous_length = 0 + + # Start the agent execution in background + loop = asyncio.get_event_loop() + task = loop.run_in_executor(None, run_sync) + + # Stream the response as it's being generated + while not task.done(): + current_response = streaming_handler.get_response() + + # Yield new tokens if available + if len(current_response) > previous_length: + new_content = current_response[previous_length:] + previous_length = len(current_response) + yield new_content + + # Small delay to prevent overwhelming the client (faster flushing) + await asyncio.sleep(0.03) + + # Get the final result + response = await task + + # Yield any remaining content + final_response = streaming_handler.get_response() + if len(final_response) > previous_length: + yield final_response[previous_length:] + + # If no streaming content was captured, yield the full response + if not final_response and response and "output" in response: + full_output = response["output"] + # Simulate streaming by yielding word by word + words = full_output.split(' ') + for word in words: + yield word + ' ' + await asyncio.sleep(0.05) + final_response = full_output + + # Validate response structure + if not response or "output" not in response: + raise ValidationError("Invalid response format from agent") + + if not response["output"] or not response["output"].strip(): + raise ValidationError("Empty response from agent") + + # Perform automatic validation if appropriate + base_response = response["output"] + if _should_validate_response(user_input, base_response): + logger.info("Performing automatic validation for streaming response...") + try: + validation_content = _perform_automatic_validation(user_input, base_response) + # Extract just the validation part (everything after the original response) + if len(validation_content) > len(base_response): + validation_part = validation_content[len(base_response):] + # Stream the validation part + validation_words = validation_part.split(' ') + for word in validation_words: + yield word + ' ' + await asyncio.sleep(0.02) + except Exception as e: + logger.error(f"Streaming validation failed: {e}") + + # Save conversation context to memory + memory.save_context( + {"input": user_input}, + {"output": response["output"]} + ) + + # Log response metrics to LangSmith + try: + log_to_langsmith( + key="response_metrics", + value={ + "response_length": len(response.get("output", "")), + "attempt": retry_count + 1, + **session_metadata, + }, + run_id=current_run_id, + ) + except Exception: + pass + + logger.info(f"Successfully processed user input: {user_input[:50]}...") + return + + except RateLimitError as e: + retry_count += 1 + last_error = e + wait_time = min(2 ** retry_count, 60) # Exponential backoff, max 60 seconds + + logger.warning( + f"Rate limit exceeded. Retrying in {wait_time} seconds... " + f"(Attempt {retry_count}/{max_retries})" + ) + + if retry_count <= max_retries: + await asyncio.sleep(wait_time) + continue + else: + logger.error("Rate limit exceeded after maximum retries") + yield "Sorry, the system is currently busy. Please try again in a little while." + return + + except APIError as e: + retry_count += 1 + last_error = e + logger.error(f"OpenAI API error: {str(e)}") + + if retry_count <= max_retries: + await asyncio.sleep(2) + continue + else: + yield "Sorry, there was an error connecting to the service. Please try again later." + return + + except requests.exceptions.ConnectionError as e: + retry_count += 1 + last_error = e + logger.error(f"Network connection error: {str(e)}") + + if retry_count <= max_retries: + await asyncio.sleep(3) + continue + else: + yield "Sorry, I can't connect to the service right now. Please check your internet connection and try again." + return + + except requests.exceptions.Timeout as e: + retry_count += 1 + last_error = e + logger.error(f"Request timeout: {str(e)}") + + if retry_count <= max_retries: + await asyncio.sleep(2) + continue + else: + yield "Sorry, the request took longer than expected. Please try again." + return + + except requests.exceptions.RequestException as e: + logger.error(f"Request error: {str(e)}") + yield "Sorry, an error occurred with the request. Please try again." + return + + except OutputParserException as e: + logger.error(f"Output parsing error: {str(e)}") + yield "Sorry, an error occurred while processing the response. Please rephrase your question and try again." + return + + except ValidationError as e: + logger.error(f"Validation error: {str(e)}") + yield "Sorry, an error occurred while validating the data. Please try again." + return + + except ToolExecutionError as e: + logger.error(f"Tool execution error: {str(e)}") + yield "Sorry, an error occurred while executing one of the operations. Please try again or contact technical support." + return + + except Exception as e: + logger.error(f"Unexpected error in run_agent_streaming: {str(e)}") + logger.error(f"Traceback: {traceback.format_exc()}") + # Log error to LangSmith + try: + log_to_langsmith( + key="error_log", + value={ + "error": str(e), + "error_type": type(e).__name__, + **session_metadata, + }, + run_id=current_run_id, + ) + except Exception: + pass + + # For unexpected errors, don't retry + yield "Sorry, an unexpected error occurred. Please try again or contact technical support if the problem persists." + return + + # This should never be reached, but just in case + logger.error(f"Maximum retries exceeded. Last error: {str(last_error)}") + yield "Sorry, I was unable to process your request after several attempts. Please try again later." + + +async def safe_run_agent_streaming(user_input: str) -> AsyncGenerator[str, None]: + """ + Streaming wrapper function with additional safety checks and input validation. + + This function provides an additional layer of safety by validating input parameters, + checking input length constraints, and handling any critical errors that might + occur during streaming agent execution. + + Args: + user_input (str): The user's input message to process + + Yields: + str: Chunks of the agent's response as they are generated + + Raises: + None: All exceptions are caught and handled internally + """ + try: + # Input type validation + if not isinstance(user_input, str): + logger.warning(f"Invalid input type received: {type(user_input)}") + yield "Sorry, the input must be valid text." + return + + # Input length validation + stripped_input = user_input.strip() + + if len(stripped_input) > 1000: + logger.warning(f"Input too long: {len(stripped_input)} characters") + yield "Sorry, the message is too long. Please shorten your question." + return + + if len(stripped_input) == 0: + logger.warning("Empty input after stripping") + yield "Sorry, I didn't receive any questions. Please enter your question or request." + return + + # Stream the response through the main agent function + async for chunk in run_agent_streaming(user_input): + yield chunk + + except Exception as e: + logger.critical(f"Critical error in safe_run_agent_streaming: {str(e)}") + logger.critical(f"Traceback: {traceback.format_exc()}") + yield "Sorry, a critical system error occurred. Please contact technical support immediately." + + +@traceable(name="run_agent") +async def run_agent(user_input: str, max_retries: int = 3) -> str: + """ + Run the agent with comprehensive error handling and retry logic. + + This function processes user input through the agent executor with robust + error handling, automatic retries for recoverable errors, and comprehensive + logging for debugging and monitoring. + + Args: + user_input (str): The user's input message to process + max_retries (int, optional): Maximum number of retries for recoverable errors. + Defaults to 3. + + Returns: + str: The agent's response or an appropriate error message in English + + Raises: + None: All exceptions are caught and handled internally + """ + # Input validation + if not user_input or not user_input.strip(): + logger.warning("Empty input received") + return "Sorry, I didn't receive any questions. Please enter your question or request." + + retry_count = 0 + last_error = None + current_run_id = None + session_metadata = conversation_tracker.get_session_metadata(increment=True) + + while retry_count <= max_retries: + try: + # Load conversation history from memory + chat_history = memory.load_memory_variables({})["chat_history"] + + logger.info(f"Processing user input (attempt {retry_count + 1}): {user_input[:50]}...") + + # Invoke the agent with input and history (synchronous call) + response = get_agent_executor().invoke({ + "input": user_input.strip(), + "chat_history": chat_history + }) + current_run_id = None # This will be handled by LangChain's tracer + + # Validate response structure + if not response or "output" not in response or not isinstance(response["output"], str): + raise ValidationError("Invalid response format from agent") + + if not response["output"] or not response["output"].strip(): + raise ValidationError("Empty response from agent") + + # Save conversation context to memory + memory.save_context( + {"input": user_input}, + {"output": response["output"]} + ) + + # Log response metrics + try: + log_to_langsmith( + key="response_metrics", + value={ + "response_length": len(response.get("output", "")), + "attempt": retry_count + 1, + **session_metadata, + }, + run_id=current_run_id, + ) + except Exception: + pass + + logger.info(f"Successfully processed user input: {user_input[:50]}...") + + # Perform automatic validation if appropriate + final_response = response["output"] + if _should_validate_response(user_input, final_response): + logger.info("Performing automatic validation...") + final_response = _perform_automatic_validation(user_input, final_response) + + return final_response + + except RateLimitError as e: + retry_count += 1 + last_error = e + wait_time = min(2 ** retry_count, 60) # Exponential backoff, max 60 seconds + + logger.warning( + f"Rate limit exceeded. Retrying in {wait_time} seconds... " + f"(Attempt {retry_count}/{max_retries})" + ) + + if retry_count <= max_retries: + await asyncio.sleep(wait_time) + continue + else: + logger.error("Rate limit exceeded after maximum retries") + return "Sorry, the system is currently busy. Please try again in a little while." + + except APIError as e: + retry_count += 1 + last_error = e + logger.error(f"OpenAI API error: {str(e)}") + + if retry_count <= max_retries: + await asyncio.sleep(2) + continue + else: + return "Sorry, there was an error connecting to the service. Please try again later." + + except requests.exceptions.ConnectionError as e: + retry_count += 1 + last_error = e + logger.error(f"Network connection error: {str(e)}") + + if retry_count <= max_retries: + await asyncio.sleep(3) + continue + else: + return "Sorry, I can't connect to the service right now. Please check your internet connection and try again." + + except requests.exceptions.Timeout as e: + retry_count += 1 + last_error = e + logger.error(f"Request timeout: {str(e)}") + + if retry_count <= max_retries: + await asyncio.sleep(2) + continue + else: + return "Sorry, the request took longer than expected. Please try again." + + except requests.exceptions.RequestException as e: + logger.error(f"Request error: {str(e)}") + return "Sorry, an error occurred with the request. Please try again." + + except OutputParserException as e: + logger.error(f"Output parsing error: {str(e)}") + return "Sorry, an error occurred while processing the response. Please rephrase your question and try again." + + except ValidationError as e: + logger.error(f"Validation error: {str(e)}") + return "Sorry, an error occurred while validating the data. Please try again." + + except ToolExecutionError as e: + logger.error(f"Tool execution error: {str(e)}") + return "Sorry, an error occurred while executing one of the operations. Please try again or contact technical support." + + except Exception as e: + logger.error(f"Unexpected error in run_agent: {str(e)}") + logger.error(f"Traceback: {traceback.format_exc()}") + # Log error + try: + log_to_langsmith( + key="error_log", + value={ + "error": str(e), + "error_type": type(e).__name__, + **session_metadata, + }, + run_id=current_run_id, + ) + except Exception: + pass + + # For unexpected errors, don't retry + return "Sorry, an unexpected error occurred. Please try again or contact technical support if the problem persists." + + # This should never be reached, but just in case + logger.error(f"Maximum retries exceeded. Last error: {str(last_error)}") + return "Sorry, I was unable to process your request after several attempts. Please try again later." + + +async def safe_run_agent(user_input: str) -> str: + """ + Wrapper function for run_agent with additional safety checks and input validation. + + This function provides an additional layer of safety by validating input parameters, + checking input length constraints, and handling any critical errors that might + occur during agent execution. + + Args: + user_input (str): The user's input message to process + + Returns: + str: The agent's response or an appropriate error message in English + + Raises: + None: All exceptions are caught and handled internally + """ + try: + # Input type validation + if not isinstance(user_input, str): + logger.warning(f"Invalid input type received: {type(user_input)}") + return "Sorry, the input must be valid text." + + # Input length validation + stripped_input = user_input.strip() + + # if len(stripped_input) > 1000: + # logger.warning(f"Input too long: {len(stripped_input)} characters") + # return "Sorry, the message is too long. Please shorten your question." + + if len(stripped_input) == 0: + logger.warning("Empty input after stripping") + return "Sorry, I didn't receive any questions. Please enter your question or request." + + # Process the input through the main agent function + return await run_agent(user_input) + + except Exception as e: + logger.critical(f"Critical error in safe_run_agent: {str(e)}") + logger.critical(f"Traceback: {traceback.format_exc()}") + return "Sorry, a critical system error occurred. Please contact technical support immediately." + + +def clear_memory() -> None: + """ + Clear the conversation memory. + + This function clears all stored conversation history from memory, + effectively starting a fresh conversation session. + """ + try: + memory.clear() + logger.info("Conversation memory cleared successfully") + except Exception as e: + logger.error(f"Error clearing memory: {str(e)}") + + +def get_memory_summary() -> str: + """ + Get a summary of the current conversation memory. + + Returns: + str: A summary of the conversation history stored in memory + """ + try: + memory_vars = memory.load_memory_variables({}) + return str(memory_vars.get("chat_history", "No conversation history available")) + except Exception as e: + logger.error(f"Error getting memory summary: {str(e)}") + return "Error retrieving memory summary" + diff --git a/core/background_init.py b/core/background_init.py new file mode 100644 index 0000000000000000000000000000000000000000..cc47161c03c83d9f9133d8db6222a57f05d9168a --- /dev/null +++ b/core/background_init.py @@ -0,0 +1,137 @@ +""" +Background initialization system for preloading heavy components during app startup. +This module handles the eager loading of embedding models, retrievers, and chunks +to improve first-question response time. +""" + +import threading +import time +from typing import Optional, Callable +from .config import logger + + +class BackgroundInitializer: + """Manages background initialization of heavy components""" + + def __init__(self): + self._initialization_thread: Optional[threading.Thread] = None + self._initialization_complete = threading.Event() + self._initialization_error: Optional[Exception] = None + self._progress_callback: Optional[Callable[[str, int], None]] = None + self._status = "Not started" + + def set_progress_callback(self, callback: Callable[[str, int], None]): + """Set a callback function to receive progress updates""" + self._progress_callback = callback + + def _update_progress(self, message: str, percentage: int): + """Update progress and call callback if set""" + self._status = message + logger.info(f"🔄 Background Init: {message} ({percentage}%)") + if self._progress_callback: + try: + self._progress_callback(message, percentage) + except Exception as e: + logger.error(f"Progress callback error: {e}") + + def _initialize_components(self): + """Initialize all heavy components in background thread""" + try: + self._update_progress("Starting background initialization...", 0) + + # Step 1: Load embedding model (this is the heaviest component) + self._update_progress("Loading embedding model...", 10) + from .config import get_embedding_model + embedding_model = get_embedding_model() + self._update_progress("Embedding model loaded successfully", 40) + + # Step 2: Initialize retrievers (this will load chunks and create vector store) + self._update_progress("Initializing retrievers and loading chunks...", 50) + from .retrievers import _ensure_initialized + _ensure_initialized() + self._update_progress("Retrievers initialized successfully", 90) + + # Step 3: Warm up LLM (optional, lightweight) + self._update_progress("Warming up LLM...", 95) + from .config import get_llm + llm = get_llm() + self._update_progress("All components initialized successfully", 100) + + logger.info("✅ Background initialization completed successfully") + + except Exception as e: + self._initialization_error = e + logger.error(f"❌ Background initialization failed: {e}") + self._update_progress(f"Initialization failed: {str(e)}", -1) + finally: + self._initialization_complete.set() + + def start_background_initialization(self): + """Start background initialization in a separate thread""" + if self._initialization_thread is not None: + logger.warning("Background initialization already started") + return + + logger.info("🚀 Starting background initialization...") + self._initialization_thread = threading.Thread( + target=self._initialize_components, + name="BackgroundInitializer", + daemon=True + ) + self._initialization_thread.start() + + def is_complete(self) -> bool: + """Check if initialization is complete""" + return self._initialization_complete.is_set() + + def wait_for_completion(self, timeout: Optional[float] = None) -> bool: + """Wait for initialization to complete""" + return self._initialization_complete.wait(timeout) + + def get_status(self) -> str: + """Get current initialization status""" + return self._status + + def get_error(self) -> Optional[Exception]: + """Get initialization error if any""" + return self._initialization_error + + def is_successful(self) -> bool: + """Check if initialization completed successfully""" + return self.is_complete() and self._initialization_error is None + + +# Global initializer instance +_background_initializer = BackgroundInitializer() + + +def start_background_initialization(progress_callback: Optional[Callable[[str, int], None]] = None): + """Start background initialization with optional progress callback""" + if progress_callback: + _background_initializer.set_progress_callback(progress_callback) + _background_initializer.start_background_initialization() + + +def wait_for_initialization(timeout: Optional[float] = None) -> bool: + """Wait for background initialization to complete""" + return _background_initializer.wait_for_completion(timeout) + + +def is_initialization_complete() -> bool: + """Check if background initialization is complete""" + return _background_initializer.is_complete() + + +def get_initialization_status() -> str: + """Get current initialization status""" + return _background_initializer.get_status() + + +def get_initialization_error() -> Optional[Exception]: + """Get initialization error if any""" + return _background_initializer.get_error() + + +def is_initialization_successful() -> bool: + """Check if initialization completed successfully""" + return _background_initializer.is_successful() diff --git a/core/config.py b/core/config.py new file mode 100644 index 0000000000000000000000000000000000000000..fdbbd356817b152bfac00337fc677b1b3cfc27d6 --- /dev/null +++ b/core/config.py @@ -0,0 +1,150 @@ +import os +from pathlib import Path +from langchain_huggingface import HuggingFaceEmbeddings +from langchain_openai import ChatOpenAI +from dotenv import load_dotenv +import logging +from logging.handlers import RotatingFileHandler +from pydantic_settings import BaseSettings, SettingsConfigDict + +# Initialize environment +load_dotenv() + + +# --- Settings (simple, in-file) --- +class Settings(BaseSettings): + model_config = SettingsConfigDict(env_file='.env', env_file_encoding='utf-8', extra='ignore') + + OPENAI_API_KEY: str + OPENAI_BASE_URL: str | None = None + + LOG_LEVEL: str = os.getenv("LOG_LEVEL", "INFO") + DATA_DIR: str = os.getenv("DATA_DIR", "") + LOG_DIR: str = os.getenv("LOG_DIR", "") + + +settings = Settings() + + +# --- File Path Configuration (Cross-platform compatible) --- +PROJECT_ROOT = Path(__file__).parent.parent.absolute() +DATA_DIR = Path(settings.DATA_DIR or (PROJECT_ROOT / "data")) +NEW_DATA = DATA_DIR / "new_data" +CHUNKS_PATH = DATA_DIR / "chunks.pkl" +VECTOR_STORE_DIR = DATA_DIR / "vector_store" +DATA_DIR.mkdir(parents=True, exist_ok=True) +NEW_DATA.mkdir(parents=True, exist_ok=True) +VECTOR_STORE_DIR.mkdir(parents=True, exist_ok=True) + +# Setup logging +LOG_DIR = Path(settings.LOG_DIR or (Path(__file__).parent.parent / "logs")) +LOG_DIR.mkdir(parents=True, exist_ok=True) + +LOG_FILE = LOG_DIR / "app.log" + +# Configure application logger (avoid duplicate handlers) +LOG_LEVEL = settings.LOG_LEVEL.upper() +logger = logging.getLogger("AgenticMedicalRAG") # centralized logger +logger.setLevel(LOG_LEVEL) +logger.propagate = False +if not logger.handlers: + formatter = logging.Formatter( + fmt="%(asctime)s - %(name)s - %(levelname)s - %(message)s" + ) + file_handler = RotatingFileHandler( + LOG_FILE, + maxBytes=1000000, + backupCount=3, + encoding="utf-8" + ) + file_handler.setFormatter(formatter) + stream_handler = logging.StreamHandler() + stream_handler.setFormatter(formatter) + logger.addHandler(file_handler) + logger.addHandler(stream_handler) + + + +# --- LLM Configuration with lazy loading --- +_llm = None + +def get_llm(): + """Get LLM with lazy loading for faster startup""" + global _llm + if _llm is None: + logger.info("Initializing LLM (first time)...") + openai_key = settings.OPENAI_API_KEY + + if not openai_key: + logger.error("OPENAI_API_KEY not found in environment variables") + raise ValueError("OpenAI API key is required. Please set OPENAI_API_KEY environment variable.") + + try: + _llm = ChatOpenAI( + model="gpt-4o", + api_key=openai_key, + base_url=settings.OPENAI_BASE_URL, + temperature=0.0, + max_tokens=2048, + request_timeout=30, # Increased timeout for stability + max_retries=2, + streaming=True, + ) + logger.info("LLM initialized successfully") + except Exception as e: + logger.error(f"Failed to initialize LLM: {e}") + raise + return _llm + +def create_llm(): + """Create LLM with proper error handling and fallbacks""" + return get_llm() + +# Lazy loading - only initialize when actually needed +LLM = None # Will be loaded on first use + +# --- Embedding Model Configuration with lazy loading --- +_embedding_model = None + +def get_embedding_model(): + """Get embedding model with lazy loading for faster startup""" + global _embedding_model + if _embedding_model is None: + logger.info("Loading embedding model (first time)...") + try: + _embedding_model = HuggingFaceEmbeddings( + model_name="abhinand/MedEmbed-base-v0.1", + model_kwargs={'device': 'cpu'}, + encode_kwargs={'normalize_embeddings': True} + ) + logger.info("Embedding model loaded successfully") + except Exception as e: + logger.error(f"Failed to load embedding model: {e}") + raise ValueError("Failed to load embedding model") + return _embedding_model + +# For backward compatibility +def create_embedding_model(): + """Create embedding model with proper error handling""" + return get_embedding_model() + +# Lazy loading - only load when actually needed +EMBEDDING_MODEL = None # Will be loaded on first use + +# Configuration validation +def validate_config(): + """Validate all required configurations""" + required_env_vars = ["OPENAI_API_KEY"] + missing_vars = [var for var in required_env_vars if not getattr(settings, var, None)] + + if missing_vars: + raise ValueError(f"Missing required environment variables: {missing_vars}") + + logger.info("Configuration validation completed") + +# Run validation on import +try: + validate_config() +except Exception as e: + logger.error(f"Configuration validation failed: {e}") + raise e diff --git a/core/data_loaders.py b/core/data_loaders.py new file mode 100644 index 0000000000000000000000000000000000000000..74ee6638548e2b6a55b378794578de2def3a7864 --- /dev/null +++ b/core/data_loaders.py @@ -0,0 +1,126 @@ +# Import required libraries +import pandas as pd +from pathlib import Path +from typing import List +from langchain.schema import Document +from .config import logger +from langchain_pymupdf4llm import PyMuPDF4LLMLoader +from langchain_community.document_loaders.parsers import TesseractBlobParser + + +def load_pdf_documents(pdf_path: Path) -> List[Document]: + """ + Load and process PDF documents from medical guidelines using PyMuPDF4LLMLoader. + Uses Tesseract for image extraction and optimized table extraction for medical documents. + Extracts disease and provider from directory structure. + + Directory structure expected: Data/Disease Name/Provider Name/file.pdf + + Args: + pdf_path: Path to the PDF file + + Returns: + List of Document objects + """ + try: + + # Validate file exists + if not pdf_path.exists(): + raise FileNotFoundError(f"PDF file not found at {pdf_path}") + + # Extract disease and provider from directory structure + path_parts = pdf_path.parts + disease = "unknown" + provider = "unknown" + + if len(path_parts) >= 3: + # Get disease (parent's parent directory) + disease = path_parts[-3] if path_parts[-3].lower() != "data" else path_parts[-2] + # Get provider (parent directory) + provider = path_parts[-2] + + # Initialize PyMuPDF4LLMLoader + loader = PyMuPDF4LLMLoader( + str(pdf_path), + mode="page", + extract_images=True, + images_parser=TesseractBlobParser(), + table_strategy="lines" + ) + + raw_documents = loader.load() + + documents = [] + for idx, doc in enumerate(raw_documents): + if doc.page_content.strip(): + processed_doc = Document( + page_content=doc.page_content, + metadata={ + "source": pdf_path.name, + "disease": disease, + "provider": provider, + "page_number": doc.metadata.get("page", idx + 1) + } + ) + documents.append(processed_doc) + + logger.info(f"Loaded {len(documents)} document pages from PDF - Disease: {disease}, Provider: {provider}") + return documents + + except Exception as e: + logger.error(f"Error loading PDF documents: {str(e)}") + raise + + +def load_markdown_documents(md_path: Path) -> List[Document]: + """ + Load and process Markdown medical guidelines. + Extracts disease and provider from directory structure. + + Directory structure expected: Data/Disease Name/Provider Name/file.md + + Args: + md_path: Path to the Markdown file + + Returns: + List of Document objects (single document split by sections if needed) + """ + try: + # Validate file exists + if not md_path.exists(): + raise FileNotFoundError(f"Markdown file not found at {md_path}") + + # Extract disease and provider from directory structure + path_parts = md_path.parts + disease = "unknown" + provider = "unknown" + + if len(path_parts) >= 3: + # Get disease (parent's parent directory) + disease = path_parts[-3] if path_parts[-3].lower() != "data" else path_parts[-2] + # Get provider (parent directory) + provider = path_parts[-2] + + # Read markdown content + with open(md_path, 'r', encoding='utf-8') as f: + content = f.read() + + # Create document with minimal metadata for RAG + doc = Document( + page_content=content, + metadata={ + "source": md_path.name, + "disease": disease, + "provider": provider, + "page_number": 1 + } + ) + + logger.info(f"Loaded Markdown document - Disease: {disease}, Provider: {provider}") + return [doc] + + except Exception as e: + logger.error(f"Error loading Markdown document: {str(e)}") + raise + + \ No newline at end of file diff --git a/core/github_storage.py b/core/github_storage.py new file mode 100644 index 0000000000000000000000000000000000000000..a2c3cd82a9489d46573439cf7474a92779157421 --- /dev/null +++ b/core/github_storage.py @@ -0,0 +1,388 @@ +""" +GitHub Storage Utility for Medical RAG Advisor +Handles saving side effects reports and validation results to GitHub repository +""" +import os +import json +import csv +import io +import base64 +from datetime import datetime +from typing import Dict, List, Any, Optional +import requests +from .config import logger + + +class GitHubStorage: + """ + Utility class for storing medical data files in GitHub repository + """ + + def __init__(self, repo_url: str = "https://github.com/MoazEldsouky/cloud-data-store.git", + github_token: str = None): + """ + Initialize GitHub storage with repository details + + Args: + repo_url: GitHub repository URL + github_token: GitHub personal access token + """ + self.repo_url = repo_url + self.github_token = github_token or os.getenv("GITHUB_TOKEN", "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") + + # Extract owner and repo name from URL + if "github.com/" in repo_url: + parts = repo_url.replace("https://github.com/", "").replace(".git", "").split("/") + self.owner = parts[0] + self.repo_name = parts[1] + else: + raise ValueError("Invalid GitHub repository URL format") + + self.api_base = f"https://api.github.com/repos/{self.owner}/{self.repo_name}" + self.headers = { + "Authorization": f"token {self.github_token}", + "Accept": "application/vnd.github.v3+json", + "Content-Type": "application/json" + } + + logger.info(f"GitHub storage initialized for {self.owner}/{self.repo_name}") + + def _get_file_sha(self, file_path: str) -> Optional[str]: + """ + Get the SHA of an existing file in the repository + + Args: + file_path: Path to file in repository + + Returns: + SHA string if file exists, None otherwise + """ + try: + url = f"{self.api_base}/contents/{file_path}" + response = requests.get(url, headers=self.headers) + + if response.status_code == 200: + return response.json().get("sha") + elif response.status_code == 404: + return None + else: + logger.error(f"Error getting file SHA: {response.status_code} - {response.text}") + return None + + except Exception as e: + logger.error(f"Exception getting file SHA: {e}") + return None + + def _upload_file(self, file_path: str, content: str, message: str, sha: Optional[str] = None) -> bool: + """ + Upload or update a file in the GitHub repository + + Args: + file_path: Path where file should be stored in repo + content: File content as string + message: Commit message + sha: SHA of existing file (for updates) + + Returns: + True if successful, False otherwise + """ + try: + # Encode content to base64 + content_encoded = base64.b64encode(content.encode('utf-8')).decode('utf-8') + + # Prepare request data + data = { + "message": message, + "content": content_encoded + } + + # Add SHA if updating existing file + if sha: + data["sha"] = sha + + # Make API request + url = f"{self.api_base}/contents/{file_path}" + response = requests.put(url, headers=self.headers, json=data) + + if response.status_code in [200, 201]: + logger.info(f"Successfully uploaded {file_path} to GitHub") + return True + else: + logger.error(f"Failed to upload {file_path}: {response.status_code} - {response.text}") + return False + + except Exception as e: + logger.error(f"Exception uploading file to GitHub: {e}") + return False + + def _get_file_content(self, file_path: str) -> Optional[str]: + """ + Get the content of a file from the GitHub repository + + Args: + file_path: Path to file in repository + + Returns: + File content as string if successful, None otherwise + """ + try: + url = f"{self.api_base}/contents/{file_path}" + response = requests.get(url, headers=self.headers) + + if response.status_code == 200: + content_encoded = response.json().get("content", "") + content = base64.b64decode(content_encoded).decode('utf-8') + return content + elif response.status_code == 404: + return None + else: + logger.error(f"Error getting file content: {response.status_code} - {response.text}") + return None + + except Exception as e: + logger.error(f"Exception getting file content: {e}") + return None + + def save_side_effects_report(self, report_data: Dict[str, Any]) -> bool: + """ + Save a side effects report to GitHub repository as CSV + + Args: + report_data: Dictionary containing side effects report data + + Returns: + True if successful, False otherwise + """ + try: + file_path = "medical_data/side_effects_reports.csv" + + # Get existing file content + existing_content = self._get_file_content(file_path) + + # Define CSV fieldnames + fieldnames = [ + 'timestamp', 'drug_name', 'side_effects', 'patient_age', + 'patient_gender', 'dosage', 'duration', 'severity', + 'outcome', 'additional_details', 'reporter_info', 'raw_input' + ] + + # Create CSV content + output = io.StringIO() + writer = csv.DictWriter(output, fieldnames=fieldnames) + + # If file doesn't exist, write header + if existing_content is None: + writer.writeheader() + csv_content = output.getvalue() + else: + # File exists, append to existing content + csv_content = existing_content + + # Append new row + output = io.StringIO() + writer = csv.DictWriter(output, fieldnames=fieldnames) + writer.writerow(report_data) + new_row = output.getvalue() + + # Combine existing content with new row + final_content = csv_content + new_row + + # Get SHA for update + sha = self._get_file_sha(file_path) + + # Upload file + commit_message = f"Add side effects report for {report_data.get('drug_name', 'unknown drug')} - {report_data.get('timestamp', 'unknown time')}" + + return self._upload_file(file_path, final_content, commit_message, sha) + + except Exception as e: + logger.error(f"Error saving side effects report to GitHub: {e}") + return False + + def save_validation_results(self, evaluation_data: Dict[str, Any]) -> bool: + """ + Save validation results to GitHub repository as JSON with unique ID generation + + Args: + evaluation_data: Dictionary containing evaluation data + + Returns: + True if successful, False otherwise + """ + try: + file_path = "medical_data/evaluation_results.json" + + # Get existing file content + existing_content = self._get_file_content(file_path) + + # Parse existing data or create new list + if existing_content: + try: + evaluations = json.loads(existing_content) + if not isinstance(evaluations, list): + evaluations = [] + except json.JSONDecodeError: + evaluations = [] + else: + evaluations = [] + + # Generate unique interaction ID + existing_ids = set() + for eval_item in evaluations: + existing_id = eval_item.get("interaction_id") + if existing_id: + try: + existing_ids.add(int(existing_id)) + except (ValueError, TypeError): + # If ID is not numeric, add as string + existing_ids.add(existing_id) + + # Find next available numeric ID + next_id = 1 + while next_id in existing_ids: + next_id += 1 + + # Update the evaluation data with unique ID + evaluation_data["interaction_id"] = str(next_id) + logger.info(f"Assigned unique interaction ID: {next_id}") + + # Add new evaluation + evaluations.append(evaluation_data) + + # Convert to JSON string + json_content = json.dumps(evaluations, indent=2, ensure_ascii=False) + + # Get SHA for update + sha = self._get_file_sha(file_path) + + # Upload file + commit_message = f"Add validation results for interaction {evaluation_data.get('interaction_id', 'unknown')} - {evaluation_data.get('timestamp', 'unknown time')}" + + return self._upload_file(file_path, json_content, commit_message, sha) + + except Exception as e: + logger.error(f"Error saving validation results to GitHub: {e}") + return False + + def get_side_effects_reports(self) -> List[Dict[str, Any]]: + """ + Get all side effects reports from GitHub repository + + Returns: + List of side effects reports as dictionaries + """ + try: + file_path = "medical_data/side_effects_reports.csv" + content = self._get_file_content(file_path) + + if not content: + return [] + + # Parse CSV content + csv_reader = csv.DictReader(io.StringIO(content)) + reports = list(csv_reader) + + return reports + + except Exception as e: + logger.error(f"Error getting side effects reports from GitHub: {e}") + return [] + + def get_validation_results(self, limit: int = 10) -> Dict[str, Any]: + """ + Get validation results from GitHub repository + + Args: + limit: Maximum number of recent evaluations to return + + Returns: + Dictionary containing evaluation summary and recent evaluations + """ + try: + file_path = "medical_data/evaluation_results.json" + content = self._get_file_content(file_path) + + if not content: + return {"message": "No evaluations found", "evaluations": []} + + # Parse JSON content + evaluations = json.loads(content) + if not isinstance(evaluations, list): + evaluations = [] + + # Get recent evaluations + recent_evaluations = evaluations[-limit:] if evaluations else [] + + # Calculate average scores + if recent_evaluations: + total_scores = { + "accuracy": 0, + "coherence": 0, + "relevance": 0, + "completeness": 0, + "citations": 0, + "length": 0, + "overall": 0 + } + + count = len(recent_evaluations) + for eval_data in recent_evaluations: + report = eval_data.get("validation_report", {}) + total_scores["accuracy"] += int(report.get("Accuracy_Rating", 0)) + total_scores["coherence"] += int(report.get("Coherence_Rating", 0)) + total_scores["relevance"] += int(report.get("Relevance_Rating", 0)) + total_scores["completeness"] += int(report.get("Completeness_Rating", 0)) + total_scores["citations"] += int(report.get("Citations_Attribution_Rating", 0)) + total_scores["length"] += int(report.get("Length_Rating", 0)) + total_scores["overall"] += int(report.get("Overall_Rating", 0)) + + averages = {key: round(value / count, 1) for key, value in total_scores.items()} + else: + averages = {} + + return { + "total_evaluations": len(evaluations), + "recent_count": len(recent_evaluations), + "average_scores": averages, + "evaluations": recent_evaluations + } + + except Exception as e: + logger.error(f"Error getting validation results from GitHub: {e}") + return {"error": str(e), "evaluations": []} + + def get_drug_reports(self, drug_name: str) -> List[Dict[str, Any]]: + """ + Get side effects reports for a specific drug from GitHub repository + + Args: + drug_name: Name of the drug to filter reports + + Returns: + List of reports for the specified drug + """ + try: + all_reports = self.get_side_effects_reports() + + # Filter reports for the specific drug (case-insensitive) + drug_reports = [ + report for report in all_reports + if report.get('drug_name', '').lower() == drug_name.lower() + ] + + return drug_reports + + except Exception as e: + logger.error(f"Error getting drug reports from GitHub: {e}") + return [] + + +# Global GitHub storage instance +_github_storage = None + +def get_github_storage() -> GitHubStorage: + """Get the global GitHub storage instance with lazy loading.""" + global _github_storage + if _github_storage is None: + _github_storage = GitHubStorage() + return _github_storage diff --git a/core/retrievers.py b/core/retrievers.py new file mode 100644 index 0000000000000000000000000000000000000000..f846936dc8caa585834cd466f21799688b60d5ac --- /dev/null +++ b/core/retrievers.py @@ -0,0 +1,161 @@ +from concurrent.futures import ThreadPoolExecutor + +from . import utils +from langchain_community.retrievers import BM25Retriever +from langchain.retrievers import EnsembleRetriever +from .config import logger +from .tracing import traceable + +# Global variables for lazy loading +_vector_store = None +_company_chunks = None +_vector_retriever = None +_bm25_retriever = None +_hybrid_retriever = None +_initialized = False + +def _ensure_initialized(): + """Initialize retrievers on first use (lazy loading for faster startup)""" + global _vector_store, _company_chunks, _vector_retriever, _bm25_retriever, _hybrid_retriever, _initialized + + if _initialized: + return + + logger.info("🔄 Initializing retrievers (first time use)...") + + # Process any new data and update vector store and chunks cache + try: + logger.info("🔄 Processing new data and updating vector store if needed...") + _vector_store = utils.process_new_data_and_update_vector_store() + if _vector_store is None: + # Fall back to load existing if processing found no new files + _vector_store = utils.load_company_vector_store() + if _vector_store is None: + # As a last resort, create from whatever is already in cache (if any) + logger.info("ℹ️ No vector store found; attempting creation from cached chunks...") + cached_chunks = utils.load_chunks() or [] + if cached_chunks: + _vector_store = utils.create_company_vector_store(cached_chunks) + logger.info("✅ Vector store created from cached chunks") + else: + logger.warning("⚠️ No data available to build a vector store. Retrievers may not function until data is provided.") + except Exception as e: + logger.error(f"Error preparing vector store: {str(e)}") + raise + + # Load merged chunks for BM25 (includes previous + new) + try: + logger.info("📦 Loading chunks cache for BM25 retriever...") + _company_chunks = utils.load_chunks() or [] + if not _company_chunks: + logger.warning("⚠️ No chunks available for BM25 retriever. BM25 will be empty until data is processed.") + except Exception as e: + logger.error(f"Error loading chunks: {str(e)}") + raise + + # Create vector retriever + logger.info("🔍 Creating vector retriever...") + _vector_retriever = _vector_store.as_retriever(search_kwargs={"k": 5}) if _vector_store else None + + # Create BM25 retriever + logger.info("📝 Creating BM25 retriever...") + _bm25_retriever = BM25Retriever.from_documents(_company_chunks) if _company_chunks else None + if _bm25_retriever: + _bm25_retriever.k = 5 + + # Create hybrid retriever + logger.info("🔄 Creating hybrid retriever...") + if _vector_retriever and _bm25_retriever: + _hybrid_retriever = EnsembleRetriever( + retrievers=[_bm25_retriever, _vector_retriever], + weights=[0.2, 0.8] + ) + elif _vector_retriever: + logger.warning("ℹ️ BM25 retriever unavailable; using vector retriever only.") + _hybrid_retriever = _vector_retriever + elif _bm25_retriever: + _hybrid_retriever = _bm25_retriever + else: + raise RuntimeError("Neither vector or BM25 retrievers could be initialized. Provide data under data/new_data and retry.") + + _initialized = True + logger.info("✅ Retrievers initialized successfully.") + + +def initialize_eagerly(): + """Force initialization of retrievers for background loading""" + _ensure_initialized() + + +def is_initialized() -> bool: + """Check if retrievers are already initialized""" + return _initialized + + +# ----------------------------------------------- +# Provider-aware retrieval helper functions +# ----------------------------------------------- +_retrieval_pool = ThreadPoolExecutor(max_workers=4) + + +def _match_provider(doc, provider: str) -> bool: + if not provider: + return True + prov = str(doc.metadata.get("provider", "")).strip().lower() + return prov == provider.strip().lower() + + +@traceable(name="VectorRetriever") +def vector_search(query: str, provider: str | None = None, k: int = 5): + """Search FAISS vector store with optional provider metadata filter.""" + _ensure_initialized() + if not _vector_store: + return [] + try: + if provider: + docs = _vector_store.similarity_search(query, k=k, filter={"provider": provider}) + else: + docs = _vector_store.similarity_search(query, k=k) + # Ensure provider post-filter in case backend filter is lenient + if provider: + docs = [d for d in docs if _match_provider(d, provider)] + return docs + except Exception as e: + logger.error(f"Vector search failed: {e}") + return [] + + +@traceable(name="BM25Retriever") +def bm25_search(query: str, provider: str | None = None, k: int = 5): + """Search BM25 using the global retriever and optionally filter by provider.""" + _ensure_initialized() + try: + if not _bm25_retriever: + return [] + _bm25_retriever.k = max(1, k) + docs = _bm25_retriever.get_relevant_documents(query) or [] + if provider: + docs = [d for d in docs if _match_provider(d, provider)] + return docs[:k] + except Exception as e: + logger.error(f"BM25 search failed: {e}") + return [] + + +def hybrid_search(query: str, provider: str | None = None, k_vector: int = 5, k_bm25: int = 5): + """Combine vector and BM25 results (provider-filtered if provided).""" + _ensure_initialized() # Ensure retrievers are initialized before parallel execution + f_vector = _retrieval_pool.submit(vector_search, query, provider, k_vector) + f_bm25 = _retrieval_pool.submit(bm25_search, query, provider, k_bm25) + + v_docs = f_vector.result() + b_docs = f_bm25.result() + # Merge uniquely by (source, page_number, snippet) + seen = set() + merged = [] + for d in v_docs + b_docs: + key = (d.metadata.get("source"), d.metadata.get("page_number"), d.page_content[:100]) + if key not in seen: + seen.add(key) + merged.append(d) + return merged diff --git a/core/side_effects_github_handler.py b/core/side_effects_github_handler.py new file mode 100644 index 0000000000000000000000000000000000000000..a9b38b8c07c73ac6234943ebd49f2a71f4dd081b --- /dev/null +++ b/core/side_effects_github_handler.py @@ -0,0 +1,184 @@ +""" +GitHub-enabled side effects handler +This module provides GitHub storage functionality for side effects reporting +""" +import os +import csv +from datetime import datetime +from typing import Dict, Any +import pytz +from .github_storage import get_github_storage +from .config import logger + + +def save_side_effect_report_to_github(extracted_data: Dict[str, Any]) -> str: + """ + Save the side effect report to GitHub repository with fallback to local storage. + + Args: + extracted_data: Dictionary containing side effects report data + + Returns: + Confirmation message string + """ + try: + # Ensure all fields have values (use 'NaN' for empty fields) + fieldnames = [ + 'timestamp', 'drug_name', 'side_effects', 'patient_age', + 'patient_gender', 'dosage', 'duration', 'severity', + 'outcome', 'additional_details', 'reporter_info', 'raw_input' + ] + + # Fill missing fields with 'NaN' and ensure proper data types + for field in fieldnames: + value = extracted_data.get(field, '') + if not value or value == '' or not str(value).strip(): + extracted_data[field] = 'NaN' + else: + # Ensure the value is properly formatted + extracted_data[field] = str(value).strip() + + # Save to GitHub repository + github_storage = get_github_storage() + success = github_storage.save_side_effects_report(extracted_data) + + if not success: + # Fallback to local storage if GitHub fails + csv_filename = "side_effects_reports.csv" + csv_path = os.path.join(os.getcwd(), csv_filename) + + file_exists = os.path.exists(csv_path) + + with open(csv_path, 'a', newline='', encoding='utf-8') as csvfile: + writer = csv.DictWriter(csvfile, fieldnames=fieldnames) + + if not file_exists: + writer.writeheader() + + writer.writerow(extracted_data) + + storage_location = f"locally to {csv_filename} (GitHub upload failed)" + logger.warning("GitHub upload failed, saved locally as fallback") + else: + storage_location = "to GitHub cloud repository" + logger.info("Successfully saved side effects report to GitHub") + + # Generate confirmation message + drug_name = extracted_data.get('drug_name', 'NaN') + side_effects = extracted_data.get('side_effects', 'NaN') + report_id = extracted_data['timestamp'].replace(':', '').replace('-', '').replace(' ', '_') + + # Create a summary of provided vs missing information + provided_info = [] + missing_info = [] + + info_fields = { + 'drug_name': 'Drug/Medication', + 'side_effects': 'Side Effects', + 'patient_age': 'Patient Age', + 'patient_gender': 'Patient Gender', + 'dosage': 'Dosage', + 'duration': 'Duration', + 'severity': 'Severity', + 'outcome': 'Outcome' + } + + for field, display_name in info_fields.items(): + value = extracted_data.get(field, 'NaN') + if value and value != 'NaN': + provided_info.append(f"- **{display_name}:** {value}") + else: + missing_info.append(display_name) + + confirmation = f""" +**✅ Adverse Drug Reaction Report Saved** + +**Report ID:** {report_id} + +**Documented Information:** +{chr(10).join(provided_info) if provided_info else '- Basic side effect report recorded'} + +**Pharmacovigilance Status:** Report successfully saved {storage_location} for regulatory review. + +**Clinical Recommendations:** +- Monitor patient for symptom progression +- Consider dose adjustment or alternative therapy if appropriate +- Document in patient medical record +- Report serious reactions to pharmacovigilance authorities + +How can I assist you further with clinical guidance for this case? +""" + + return confirmation.strip() + + except Exception as e: + logger.error(f"Error saving side effect report: {e}") + return f"Error saving side effect report: {str(e)}" + + +def get_side_effects_reports_from_github(): + """ + Get all side effects reports from GitHub repository with local fallback. + + Returns: + List of side effects reports + """ + try: + github_storage = get_github_storage() + reports = github_storage.get_side_effects_reports() + + if reports: + logger.info(f"Retrieved {len(reports)} side effects reports from GitHub") + return reports + + # Fallback to local file + csv_path = "side_effects_reports.csv" + if os.path.exists(csv_path): + import pandas as pd + df = pd.read_csv(csv_path) + reports = df.to_dict('records') + logger.info(f"Retrieved {len(reports)} side effects reports from local file (GitHub fallback)") + return reports + + logger.info("No side effects reports found in GitHub or local storage") + return [] + + except Exception as e: + logger.error(f"Error retrieving side effects reports: {e}") + return [] + + +def get_drug_reports_from_github(drug_name: str): + """ + Get side effects reports for a specific drug from GitHub repository. + + Args: + drug_name: Name of the drug to filter reports + + Returns: + List of reports for the specified drug + """ + try: + github_storage = get_github_storage() + reports = github_storage.get_drug_reports(drug_name) + + if reports: + logger.info(f"Retrieved {len(reports)} reports for {drug_name} from GitHub") + return reports + + # Fallback to local file + csv_path = "side_effects_reports.csv" + if os.path.exists(csv_path): + import pandas as pd + df = pd.read_csv(csv_path) + drug_reports = df[df['drug_name'].str.lower() == drug_name.lower()] + reports = drug_reports.to_dict('records') + logger.info(f"Retrieved {len(reports)} reports for {drug_name} from local file (GitHub fallback)") + return reports + + logger.info(f"No reports found for {drug_name} in GitHub or local storage") + return [] + + except Exception as e: + logger.error(f"Error retrieving drug reports for {drug_name}: {e}") + return [] diff --git a/core/text_processors.py b/core/text_processors.py new file mode 100644 index 0000000000000000000000000000000000000000..eeaa0f2d020dfb24b6e1f568ada8929cf3a72b6d --- /dev/null +++ b/core/text_processors.py @@ -0,0 +1,20 @@ +from langchain.text_splitter import ( + RecursiveCharacterTextSplitter, + MarkdownHeaderTextSplitter +) + +recursive_splitter = RecursiveCharacterTextSplitter( + chunk_size=2000, + chunk_overlap=200, + length_function=len, + separators=["\n\n", "\n", ". ", " ", ""], + ) + + +markdown_splitter = MarkdownHeaderTextSplitter( + headers_to_split_on=[ + ("##", "Header 2"), # Main guideline source (NCCN, ESMO, WHO…) + ("###", "Header 3"), # Subsections (Features, Recommendations, Statistics…) + ], + strip_headers=False, +) diff --git a/core/tools.py b/core/tools.py new file mode 100644 index 0000000000000000000000000000000000000000..70120602cef5b68bce619e3113349d605d62d5e2 --- /dev/null +++ b/core/tools.py @@ -0,0 +1,973 @@ +import os +import re +import csv +from concurrent.futures import ThreadPoolExecutor +from datetime import datetime +from typing import Optional, List + +import pytz +from langchain.schema import Document +from langchain.tools import tool +from .retrievers import hybrid_search, vector_search, bm25_search +from .validation import validate_medical_answer +from .github_storage import get_github_storage + +CANONICAL_PROVIDERS = {"Manus", "ASCO", "NCCN", "ESMO", "NICE"} + +# Global variables to store context for validation +_last_question = None # Stores the tool query +_last_user_question = None # Stores the original user question +_last_documents = None +_last_answer = None + +TOOL_MAX_WORKERS = max(2, min(8, (os.cpu_count() or 4))) +_tool_executor = ThreadPoolExecutor(max_workers=TOOL_MAX_WORKERS) + +def store_user_question(user_question: str): + """Store the original user question for validation purposes.""" + global _last_user_question + _last_user_question = user_question + +# Map lowercase variants and full names to canonical provider codes +_PROVIDER_ALIASES = { + # NCCN + "nccn": "NCCN", + "national comprehensive cancer network": "NCCN", + "nccn guidelines": "NCCN", + # ESMO + "esmo": "ESMO", + "european society for medical oncology": "ESMO", + "esmo guidelines": "ESMO", + # ASCO + "asco": "ASCO", + "american society of clinical oncology": "ASCO", + "asco guidelines": "ASCO", + # NICE + "nice": "NICE", + "national institute for health and care excellence": "NICE", + "nice guidelines": "NICE", + # Manus (custom provider) + "manus": "Manus", + "by manus": "Manus", +} + + +def _normalize_provider_from_text(text: str) -> Optional[str]: + if not text: + return None + t = text.lower() + # Quick direct hits for canonical providers + for canon in CANONICAL_PROVIDERS: + if re.search(rf"\b{re.escape(canon.lower())}\b", t): + return canon + # Alias-based detection + for alias, canon in _PROVIDER_ALIASES.items(): + if alias in t: + return canon + return None + + +def _normalize_provider(provider: Optional[str], query: str) -> Optional[str]: + # If explicit provider given, normalize it first + if provider: + p = provider.strip().lower() + # Exact canonical match + for canon in CANONICAL_PROVIDERS: + if p == canon.lower(): + return canon + # Alias match + if p in _PROVIDER_ALIASES: + return _PROVIDER_ALIASES[p] + # Try to find within text like "according to NCCN guidelines" + norm = _normalize_provider_from_text(provider) + if norm: + return norm + # Fall back to inferring from query text + return _normalize_provider_from_text(query) + + +def clear_text(text: str, max_chars: int = 1200) -> str: + """Reduce token bloat by removing heavy markdown and collapsing whitespace. + - Convert [title](url) -> title (url) + - Remove images ![alt](url) + - Strip code fences/backticks and most markdown emphasis + - Collapse multiple newlines/spaces + - Trim to max_chars + """ + if not text: + return "" + t = text + # Normalize newlines + t = t.replace("\r\n", "\n").replace("\r", "\n") + # Links: keep title and URL + t = re.sub(r"\[([^\]]+)\]\(([^)]+)\)", r"\1 (\2)", t) + # Images: drop entirely + t = re.sub(r"!\[[^\]]*\]\([^)]*\)", "", t) + # Remove headers/quotes markers at line starts + t = re.sub(r"(?m)^[>\s]*#{1,6}\s*", "", t) + # Remove backticks/code fences and emphasis + t = t.replace("```", "").replace("`", "") + t = t.replace("**", "").replace("*", "").replace("_", "") + # Collapse spaces before newlines + t = re.sub(r"[ \t]+\n", "\n", t) + # Collapse multiple newlines and spaces + t = re.sub(r"\n{3,}", "\n\n", t) + t = re.sub(r"[ \t]{2,}", " ", t) + # Trim and truncate + t = t.strip() + if max_chars and len(t) > max_chars: + t = t[:max_chars].rstrip() + " ..." + return t + +def _format_docs_with_citations(docs: List[Document]) -> str: + parts = [] + for i, d in enumerate(docs, start=1): + meta = d.metadata or {} + source = meta.get("source", "unknown") + page = meta.get("page_number", "?") + provider = meta.get("provider", "unknown") + disease = meta.get("disease", "unknown") + snippet = clear_text(d.page_content) + parts.append( + f"Result {i}:\n" + f"Provider: {provider} | Disease: {disease} | Source: {source} | Page: {page}\n" + f"Text:\n{snippet}\n" + ) + return "\n\n".join(parts) if parts else "No results." + + +@tool +def medical_guidelines_knowledge_tool(query: str, provider: Optional[str] = None) -> str: + """ + Retrieve medical guideline knowledge for a query with optional provider filtering. + If provider is provided (e.g., "NCCN", "ASCO", "ESMO", "NICE"), results will be filtered by metadata provider. + Always returns text with full metadata (source file, page number, provider, disease) for each result. + """ + global _last_question, _last_documents + try: + # Store question for validation context + _last_question = query + + # Normalize provider name from either explicit arg or query text + normalized_provider = _normalize_provider(provider, query) + # Use hybrid search by default for quality + docs = hybrid_search(query=query, provider=normalized_provider, k_vector=5, k_bm25=5) + + # Store documents for validation context + _last_documents = [] + for doc in docs: + doc_dict = { + "doc_id": getattr(doc, 'id', f"doc_{len(_last_documents)}"), + "source": doc.metadata.get("source", "unknown"), + "provider": doc.metadata.get("provider", "unknown"), + "page_number": doc.metadata.get("page_number", "unknown"), + "disease": doc.metadata.get("disease", "unknown"), + "snippet": doc.page_content[:500] + "..." if len(doc.page_content) > 500 else doc.page_content, + "content": doc.page_content + } + _last_documents.append(doc_dict) + + return _format_docs_with_citations(docs) + except Exception as e: + return f"Retrieval error: {str(e)}" + + +@tool +def compare_providers_tool(query: str, provider_a: str, provider_b: str) -> str: + """ + Compare guideline answers between two providers (e.g., provider_a="NCCN", provider_b="ESMO"). + Retrieves provider-filtered results independently, then returns a structured text block suited for comparison. + Output includes citations (source file, page number, provider, disease) for each side. + """ + try: + canon_a = _normalize_provider(provider_a, query) or provider_a + canon_b = _normalize_provider(provider_b, query) or provider_b + + a_future = _tool_executor.submit(hybrid_search, query, canon_a, 5, 5) + b_future = _tool_executor.submit(hybrid_search, query, canon_b, 5, 5) + + a_docs = a_future.result() + b_docs = b_future.result() + + format_a_future = _tool_executor.submit(_format_docs_with_citations, a_docs) + format_b_future = _tool_executor.submit(_format_docs_with_citations, b_docs) + + a_text = format_a_future.result() + b_text = format_b_future.result() + + return ( + f"Comparison for query: {query}\n\n" + f"Provider A: {canon_a}\n" + f"{'-'*40}\n" + f"{a_text}\n\n" + f"Provider B: {canon_b}\n" + f"{'-'*40}\n" + f"{b_text}\n" + ) + except Exception as e: + return f"Comparison retrieval error: {str(e)}" + + + +@tool +def get_current_datetime_tool() -> str: + """ + Returns the current date, time, and day of the week for Egypt (Africa/Cairo). + This is the only reliable source for date and time information. Use this tool + whenever a user asks about 'today', 'now', or any other time-sensitive query. + The output is always in English and in standard 12-hour format. + """ + try: + # Define the timezone for Egypt + egypt_tz = pytz.timezone('Africa/Cairo') + + # Get the current time in that timezone + now_egypt = datetime.now(egypt_tz) + + # Manual mapping to ensure English output regardless of system locale + days_en = { + 0: "Monday", 1: "Tuesday", 2: "Wednesday", 3: "Thursday", + 4: "Friday", 5: "Saturday", 6: "Sunday" + } + months_en = { + 1: "January", 2: "February", 3: "March", 4: "April", + 5: "May", 6: "June", 7: "July", 8: "August", + 9: "September", 10: "October", 11: "November", 12: "December" + } + + # Get English names using manual mapping + day_name = days_en[now_egypt.weekday()] + month_name = months_en[now_egypt.month] + day = now_egypt.day + year = now_egypt.year + + # Format time manually to avoid locale issues + hour = now_egypt.hour + minute = now_egypt.minute + + # Convert to 12-hour format + if hour == 0: + hour_12 = 12 + period = "AM" + elif hour < 12: + hour_12 = hour + period = "AM" + elif hour == 12: + hour_12 = 12 + period = "PM" + else: + hour_12 = hour - 12 + period = "PM" + + time_str = f"{hour_12:02d}:{minute:02d} {period}" + + # Create the final string + return f"Current date and time in Egypt: {day_name}, {month_name} {day}, {year} at {time_str}" + + except Exception as e: + return f"Error getting current datetime: {str(e)}" + + +@tool +def side_effect_recording_tool(user_input: str) -> str: + """ + Detects when a doctor reports or mentions discovering a side effect related to a drug. + First asks for missing critical information (drug name, side effects) and optional details + (patient_age, patient_gender, dosage, duration, severity). If user cannot provide optional + information, saves the report with NaN values for unknown data. + + This tool should be used when the input contains: + - Reports of adverse drug reactions or side effects + - Patient experiencing unexpected symptoms after medication + - Drug-related complications or adverse events + - Medical professionals reporting medication issues + + Args: + user_input (str): The doctor's input describing the side effect or adverse reaction + + Returns: + str: Interactive form for collecting missing information or confirmation of data recording + """ + try: + # Define keywords that indicate side effect reporting + side_effect_keywords = [ + 'side effect', 'adverse reaction', 'adverse event', 'drug reaction', + 'medication reaction', 'allergic reaction', 'complication', 'toxicity', + 'intolerance', 'hypersensitivity', 'contraindication', 'withdrawal', + 'overdose', 'poisoning', 'drug-induced', 'medication-induced', + 'experienced after taking', 'developed after', 'caused by medication', + 'drug-related', 'medication-related', 'pharmaceutical reaction', + # Add more comprehensive problem/symptom keywords + 'kidney problems', 'liver problems', 'heart problems', 'breathing problems', + 'skin problems', 'stomach problems', 'nausea', 'vomiting', 'diarrhea', + 'headache', 'dizziness', 'fatigue', 'weakness', 'rash', 'swelling', + 'pain', 'fever', 'cough', 'infection', 'bleeding', 'bruising', + 'has these', 'has serious', 'causes', 'resulted in', 'led to', + 'problems with', 'issues with', 'complications from' + ] + + input_lower = user_input.lower().strip() + + # Check for special commands first + if input_lower in ['save report', 'save', 'submit report', 'submit']: + # Create minimal data for saving + extracted_data = _extract_side_effect_data(user_input) + return _save_side_effect_report(extracted_data) + + if input_lower in ['cancel', 'cancel report', 'abort']: + return "**Side Effect Report Cancelled**\n\nThe adverse drug reaction report has been cancelled and no data was saved." + + # Check if this is a follow-up with additional information or user saying they can't provide info + if _is_followup_response(user_input): + # For follow-up responses, we need to get the base data from somewhere + # Since we don't have session state, treat this as a new report + extracted_data = _extract_side_effect_data(user_input) + return _process_followup_response(user_input, extracted_data) + + # Check if input contains side effect reporting indicators + contains_side_effect = any(keyword in input_lower for keyword in side_effect_keywords) + + if not contains_side_effect: + return "This input does not appear to contain a side effect report. If you are reporting an adverse drug reaction, please include specific details about the medication and symptoms." + + # Extract information using pattern matching and keyword analysis + extracted_data = _extract_side_effect_data(user_input) + + # Check if we have the critical information (drug name and side effects) + missing_critical = _identify_missing_information(extracted_data) + + if missing_critical: + # Missing critical info, ask for it first + return _generate_information_request(extracted_data, missing_critical) + else: + # Have critical info, now ask for optional information + missing_optional = _identify_missing_optional_information(extracted_data) + if missing_optional: + return _generate_optional_information_request(extracted_data, missing_optional) + else: + # Have all available info, save the report + return _save_side_effect_report(extracted_data) + + except Exception as e: + return f"Error processing side effect report: {str(e)}. Please ensure your report includes drug name and symptoms." + + +def _is_followup_response(user_input: str) -> bool: + """Check if the input appears to be a follow-up response with additional information.""" + followup_indicators = [ + 'patient age:', 'age:', 'gender:', 'dosage:', 'dose:', 'duration:', + 'severity:', 'outcome:', 'additional:', 'reporter:', 'notes:', + 'male', 'female', 'years old', 'mg', 'ml', 'tablets', 'capsules', + 'mild', 'moderate', 'severe', 'recovered', 'ongoing', 'hospitalized', + # Add indicators for when user can't provide info + "can't provide", "cannot provide", "don't have", "do not have", + "not available", "unavailable", "missing", "no information", + "just save", "save them", "save it", "save anyway", "will not provide", + "won't provide", "don't know", "unknown", "not sure" + ] + input_lower = user_input.lower() + return any(indicator in input_lower for indicator in followup_indicators) + + +def _process_followup_response(user_input: str, base_data: dict) -> str: + """Process follow-up response and update the extracted data.""" + + # Check if user is indicating they can't provide information + cant_provide_indicators = [ + "can't provide", "cannot provide", "don't have", "do not have", + "not available", "unknown", "unavailable", "missing", "no information", + "will not provide", "won't provide", "save anyway", "just save" + ] + + input_lower = user_input.lower() + if any(indicator in input_lower for indicator in cant_provide_indicators): + # User can't provide additional info, save with what we have + return _save_side_effect_report(base_data) + + # Extract additional information from the follow-up + additional_data = _extract_side_effect_data(user_input) + + # Merge with base data, prioritizing new information + merged_data = base_data.copy() + for key, value in additional_data.items(): + if value and value != 'NaN' and str(value).strip(): + merged_data[key] = value + + # Check if there are still critical missing fields (only drug_name and side_effects are truly critical) + critical_missing = [] + truly_critical_fields = ['drug_name', 'side_effects'] + + for field in truly_critical_fields: + value = merged_data.get(field, '') + if not value or value == 'NaN' or not str(value).strip(): + critical_missing.append(field) + + # If critical information is missing, ask for it + if critical_missing: + return _generate_information_request(merged_data, [(field, field.replace('_', ' ').title()) for field in critical_missing]) + + # Always save automatically after processing follow-up information + # This ensures we save after any follow-up response, whether complete or partial + return _save_side_effect_report(merged_data) + + +def _identify_missing_information(extracted_data: dict) -> list: + """Identify which critical information is missing from the extracted data.""" + missing = [] + + # Only truly critical fields - drug name and side effects + critical_fields = { + 'drug_name': 'Drug/Medication Name', + 'side_effects': 'Side Effects/Symptoms' + } + + for field, display_name in critical_fields.items(): + value = extracted_data.get(field, '') + if not value or value == 'NaN' or not value.strip(): + missing.append((field, display_name)) + + return missing + + +def _identify_missing_optional_information(extracted_data: dict) -> list: + """Identify which optional information is missing from the extracted data.""" + missing = [] + + # Optional fields that we should ask for + optional_fields = { + 'patient_age': 'Patient Age', + 'patient_gender': 'Patient Gender', + 'dosage': 'Medication Dosage', + 'duration': 'Treatment Duration', + 'severity': 'Severity Level' + } + + for field, display_name in optional_fields.items(): + value = extracted_data.get(field, '') + if not value or value == 'NaN' or not value.strip(): + missing.append((field, display_name)) + + return missing + + +# Remove this function as we no longer ask for optional information + + +def _generate_information_request(extracted_data: dict, missing_info: list) -> str: + """Generate a medical-professional request for missing critical information.""" + + # Only ask for truly critical missing information + critical_missing = [] + for field, display_name in missing_info: + if field in ['drug_name', 'side_effects']: + critical_missing.append((field, display_name)) + + if not critical_missing: + # No critical info missing, save the report + return _save_side_effect_report(extracted_data) + + # Create a concise request for only critical missing information + response = "**Adverse Drug Reaction Report**\n\n" + + if any(field == 'drug_name' for field, _ in critical_missing): + response += "Please specify the **medication/drug name** involved in this adverse reaction.\n\n" + + if any(field == 'side_effects' for field, _ in critical_missing): + response += "Please describe the **side effects or symptoms** experienced.\n\n" + + response += "**Note**: All other details (age, gender, dosage, etc.) are optional. If you cannot provide them, I'll save the report with the available information." + + return response.strip() + + +def _generate_optional_information_request(extracted_data: dict, missing_optional: list) -> str: + """Generate a request for optional information that would enhance the side effect report.""" + + # Show what we already have + response = "**Adverse Drug Reaction Report**\n\n" + response += "**Recorded Information:**\n" + + if extracted_data.get('drug_name') and extracted_data['drug_name'] != 'NaN': + response += f"- **Drug:** {extracted_data['drug_name']}\n" + + if extracted_data.get('side_effects') and extracted_data['side_effects'] != 'NaN': + response += f"- **Side Effects:** {extracted_data['side_effects']}\n" + + response += "\n**Additional Information (Optional):**\n" + response += "To enhance this report, please provide any of the following details if available:\n\n" + + for field, display_name in missing_optional: + if field == 'patient_age': + response += "- **Patient Age:** (e.g., 45 years old)\n" + elif field == 'patient_gender': + response += "- **Patient Gender:** (Male/Female)\n" + elif field == 'dosage': + response += "- **Dosage:** (e.g., 10mg daily, 2 tablets)\n" + elif field == 'duration': + response += "- **Duration:** (e.g., 3 months, 2 weeks)\n" + elif field == 'severity': + response += "- **Severity:** (Mild/Moderate/Severe)\n" + + response += "\n**Note:** If you don't have this information or cannot provide it, just reply with \"I don't have that information\" or \"save anyway\" and I'll save the report with the available data." + + return response.strip() + + +def _save_side_effect_report(extracted_data: dict) -> str: + """Save the side effect report to CSV file.""" + try: + # Ensure all fields have values (use 'NaN' for empty fields) + fieldnames = [ + 'timestamp', 'drug_name', 'side_effects', 'patient_age', + 'patient_gender', 'dosage', 'duration', 'severity', + 'outcome', 'additional_details', 'reporter_info', 'raw_input' + ] + + # Fill missing fields with 'NaN' and ensure proper data types + for field in fieldnames: + value = extracted_data.get(field, '') + if not value or value == '' or not str(value).strip(): + extracted_data[field] = 'NaN' + else: + # Ensure the value is properly formatted + extracted_data[field] = str(value).strip() + + # Save to GitHub repository + + + github_storage = get_github_storage() + + + success = github_storage.save_side_effects_report(extracted_data) + + + + + + if not success: + + + # Fallback to local storage if GitHub fails + + + csv_filename = "side_effects_reports.csv" + + + csv_path = os.path.join(os.getcwd(), csv_filename) + + + + + + file_exists = os.path.exists(csv_path) + + + + + + with open(csv_path, 'a', newline='', encoding='utf-8') as csvfile: + + + writer = csv.DictWriter(csvfile, fieldnames=fieldnames) + + + + + + if not file_exists: + + + writer.writeheader() + + + + + + writer.writerow(extracted_data) + + + + + + storage_location = "locally to side_effects_reports.csv (GitHub upload failed)" + + + else: + + + storage_location = "to GitHub cloud repository" + + + +# Generate confirmation message + drug_name = extracted_data.get('drug_name', 'NaN') + side_effects = extracted_data.get('side_effects', 'NaN') + report_id = extracted_data['timestamp'].replace(':', '').replace('-', '').replace(' ', '_') + + # Create a summary of provided vs missing information + provided_info = [] + missing_info = [] + + info_fields = { + 'drug_name': 'Drug/Medication', + 'side_effects': 'Side Effects', + 'patient_age': 'Patient Age', + 'patient_gender': 'Patient Gender', + 'dosage': 'Dosage', + 'duration': 'Duration', + 'severity': 'Severity', + 'outcome': 'Outcome' + } + + for field, display_name in info_fields.items(): + value = extracted_data.get(field, 'NaN') + if value and value != 'NaN': + provided_info.append(f"- **{display_name}:** {value}") + else: + missing_info.append(display_name) + + confirmation = f""" +**✅ Adverse Drug Reaction Report Saved** + +**Report ID:** {report_id} + +**Documented Information:** +{chr(10).join(provided_info) if provided_info else '- Basic side effect report recorded'} + +**Pharmacovigilance Status:** Report successfully saved {storage_location} for regulatory review. + +**Clinical Recommendations:** +- Monitor patient for symptom progression +- Consider dose adjustment or alternative therapy if appropriate +- Document in patient medical record +- Report serious reactions to pharmacovigilance authorities + +How can I assist you further with clinical guidance for this case? +""" + + return confirmation.strip() + + except Exception as e: + return f"Error saving side effect report: {str(e)}" + + +def _extract_side_effect_data_with_llm(user_input: str) -> dict: + """ + Extract structured data from side effect report text using LLM-based extraction. + + Args: + user_input (str): Raw input text containing side effect report + + Returns: + dict: Structured data extracted from the input + """ + from langchain.llms import OpenAI + from langchain.prompts import PromptTemplate + import json + + # Get current timestamp + egypt_tz = pytz.timezone('Africa/Cairo') + current_time = datetime.now(egypt_tz).strftime('%Y-%m-%d %H:%M:%S') + + # Initialize extracted data with defaults + extracted_data = { + 'timestamp': current_time, + 'drug_name': 'NaN', + 'side_effects': 'NaN', + 'patient_age': 'NaN', + 'patient_gender': 'NaN', + 'dosage': 'NaN', + 'duration': 'NaN', + 'severity': 'NaN', + 'outcome': 'NaN', + 'additional_details': 'NaN', + 'reporter_info': 'NaN', + 'raw_input': user_input[:500] # Limit raw input length + } + + # Create extraction prompt + extraction_prompt = PromptTemplate( + input_variables=["user_input"], + template="""Extract medical side effect information from the following text. Return ONLY a JSON object with these exact fields: + +{ + "drug_name": "name of the medication/drug mentioned", + "side_effects": "list of side effects or symptoms described", + "patient_age": "patient's age if mentioned", + "patient_gender": "Male or Female if mentioned", + "dosage": "medication dosage if mentioned", + "duration": "treatment duration if mentioned (e.g., '3 months', '2 weeks')", + "severity": "mild, moderate, or severe if mentioned", + "outcome": "current status like ongoing, resolved, recovered if mentioned" +} + +IMPORTANT RULES: +1. If any information is not found or unclear, use "NaN" as the value +2. For duration, look for phrases like "Treatment duration: 3 months", "for 2 weeks", "over 6 months", etc. +3. Extract exact values as mentioned in the text +4. Return ONLY the JSON object, no other text + +Text to analyze: +{user_input} + +JSON:""" + ) + + try: + # Try to use LLM extraction if available + try: + # This would use the actual LLM - for now we'll use a fallback approach + # llm = OpenAI(temperature=0) + # prompt = extraction_prompt.format(user_input=user_input) + # response = llm(prompt) + # extracted_json = json.loads(response.strip()) + + # Fallback to improved regex-based extraction with better duration handling + extracted_json = _extract_with_improved_regex(user_input) + + except Exception: + # Fallback to improved regex extraction + extracted_json = _extract_with_improved_regex(user_input) + + # Update extracted_data with LLM results, keeping NaN for empty values + for key, value in extracted_json.items(): + if key in extracted_data and value and str(value).strip() and str(value).strip().lower() != 'nan': + extracted_data[key] = str(value).strip() + + except Exception as e: + # If LLM extraction fails, use improved regex fallback + extracted_json = _extract_with_improved_regex(user_input) + for key, value in extracted_json.items(): + if key in extracted_data and value and str(value).strip() and str(value).strip().lower() != 'nan': + extracted_data[key] = str(value).strip() + + return extracted_data + + +def _extract_with_improved_regex(user_input: str) -> dict: + """ + Improved regex-based extraction with better duration handling. + """ + extracted = { + 'drug_name': 'NaN', + 'side_effects': 'NaN', + 'patient_age': 'NaN', + 'patient_gender': 'NaN', + 'dosage': 'NaN', + 'duration': 'NaN', + 'severity': 'NaN', + 'outcome': 'NaN' + } + + input_lower = user_input.lower() + + # Extract drug names with improved patterns + drug_patterns = [ + r'\b(afinitor|cisplatin|afatinib|imatinib|dasatinib|nilotinib|bosutinib|ponatinib|bevacizumab|cetuximab|trastuzumab)\b', + r'(?:found that|that)\s+([A-Za-z]{4,20})\s+(?:has|have)', + r'([A-Za-z]{4,20})\s+(?:has|have)\s+(?:these\s+)?(?:side\s+effects?|adverse\s+effects?)', + r'(?:taking|prescribed|given|on)\s+([A-Za-z][A-Za-z0-9\s\-]{2,20}?)(?:\s+(?:mg|mcg|g|ml)|\s+for|\.|,)', + r'(?:side effects?|adverse effects?)\s+(?:of|from)\s+([A-Za-z][A-Za-z0-9\s\-]{2,20}?)(?:\s|,|\.|;)' + ] + + for pattern in drug_patterns: + matches = re.findall(pattern, user_input, re.IGNORECASE) + if matches: + drug_name = matches[0].strip() + if len(drug_name) > 2 and not drug_name.lower() in ['that', 'these', 'those', 'found', 'have']: + extracted['drug_name'] = drug_name + break + + # Extract side effects + symptom_patterns = [ + r'(?:side effects?|symptoms?|adverse effects?)\s*[:\-]?\s*([^.!?]+?)(?:\.|!|\?|patient|$)', + r'(?:has|have)\s+(?:these\s+)?(?:side effects?[:\s]+)?([A-Za-z][^.!?]*?)(?:\.|!|\?|patient|$)', + r'(?:experienced|developed|suffered|had)\s+([^.!?]+?)(?:\.|!|\?|after|following|$)' + ] + + for pattern in symptom_patterns: + matches = re.findall(pattern, user_input, re.IGNORECASE) + if matches: + symptoms = matches[0].strip() + if len(symptoms) > 3: + extracted['side_effects'] = symptoms + break + + # Extract patient age with better patterns + age_patterns = [ + r'patient\'?s?\s+age\s*[:\-]?\s*(\d{1,3})', + r'age\s*[:\-]?\s*(\d{1,3})', + r'(\d{1,3})\s*(?:years?\s+old|y/?o)', + r'aged\s+(\d{1,3})' + ] + + for pattern in age_patterns: + matches = re.findall(pattern, user_input, re.IGNORECASE) + if matches: + age = int(matches[0]) + if 0 <= age <= 120: + extracted['patient_age'] = str(age) + break + + # Extract patient gender + if re.search(r'\b(?:male|man|boy|gentleman|he|his|him)\b', input_lower): + extracted['patient_gender'] = 'Male' + elif re.search(r'\b(?:female|woman|girl|lady|she|her)\b', input_lower): + extracted['patient_gender'] = 'Female' + + # Extract dosage + dosage_patterns = [ + r'(?:medication\s+)?dosage\s*[:\-]?\s*([\d\.]+\s*(?:mg|mcg|g|ml|units?|tablets?|capsules?))', + r'dosage\s*[:\-]?\s*([\d\.]+\s*ml)', + r'(\d+(?:\.\d+)?\s*(?:mg|mcg|g|ml|units?|tablets?|capsules?))' + ] + + for pattern in dosage_patterns: + matches = re.findall(pattern, user_input, re.IGNORECASE) + if matches: + extracted['dosage'] = matches[0].strip() + break + + # Extract duration with improved patterns + duration_patterns = [ + r'treatment\s+duration\s*[:\-]?\s*(\d+\s*(?:days?|weeks?|months?|years?))', + r'duration\s*[:\-]?\s*(\d+\s*(?:days?|weeks?|months?|years?))', + r'(?:for|over|during)\s+(\d+\s*(?:days?|weeks?|months?|years?))', + r'(\d+\s*(?:days?|weeks?|months?|years?))\s+(?:of\s+)?(?:treatment|therapy)', + r'(?:lasted|continuing for|ongoing for)\s+(\d+\s*(?:days?|weeks?|months?|years?))' + ] + + for pattern in duration_patterns: + matches = re.findall(pattern, user_input, re.IGNORECASE) + if matches: + extracted['duration'] = matches[0].strip() + break + + # Extract severity + severity_keywords = { + 'mild': ['mild', 'slight', 'minor', 'light'], + 'moderate': ['moderate', 'medium', 'noticeable'], + 'severe': ['severe', 'serious', 'major', 'significant', 'intense', 'extreme'] + } + + for severity, keywords in severity_keywords.items(): + if any(keyword in input_lower for keyword in keywords): + extracted['severity'] = severity.capitalize() + break + + # Extract outcome + outcome_keywords = { + 'recovered': ['recovered', 'resolved', 'better', 'improved'], + 'ongoing': ['ongoing', 'continuing', 'persistent', 'current status: ongoing'], + 'worsened': ['worsened', 'deteriorated', 'worse'], + 'hospitalized': ['hospitalized', 'admitted', 'emergency'] + } + + for outcome, keywords in outcome_keywords.items(): + if any(keyword in input_lower for keyword in keywords): + extracted['outcome'] = outcome.capitalize() + break + + return extracted + + +def _extract_side_effect_data(user_input: str) -> dict: + """ + Extract structured data from side effect report text. + + Args: + user_input (str): Raw input text containing side effect report + + Returns: + dict: Structured data extracted from the input + """ + # Use the new LLM-based extraction + return _extract_side_effect_data_with_llm(user_input) + + +@tool +def medical_answer_validation_tool( + question: Optional[str] = None, + retrieved_documents: Optional[List] = None, + generated_answer: Optional[str] = None +) -> str: + """ + Validate a medical answer using the comprehensive validation system. + + This tool evaluates medical responses across 6 criteria: Accuracy, Coherence, + Relevance, Completeness, Citations/Attribution, and Length. + + Args: + question: The original medical question (optional - uses stored context if not provided) + retrieved_documents: List of documents used for the answer (optional - uses stored context) + generated_answer: The AI-generated answer to validate (optional - uses stored context) + + Returns: + str: Formatted validation report with scores and improvement recommendations + """ + global _last_question, _last_documents, _last_answer, _last_user_question + + try: + # Use provided parameters or fall back to stored context + # Prefer the original user question over the tool query + eval_question = question or _last_user_question or _last_question + eval_documents = retrieved_documents or _last_documents or [] + eval_answer = generated_answer or _last_answer + + # Validate that we have the required information + if not eval_question: + return "Error: No question available for validation. Please provide a question or ensure medical_guidelines_knowledge_tool was used first." + + if not eval_answer: + return "Error: No answer available for validation. Please provide an answer to validate." + + if not eval_documents: + return "Warning: No retrieved documents available for validation. Validation will proceed with limited context." + + # Store the answer for future reference + if generated_answer: + _last_answer = generated_answer + + # Perform validation + evaluation = validate_medical_answer(eval_question, eval_documents, eval_answer) + + # Format the validation report for display + report = evaluation.get("validation_report", {}) + + formatted_report = f""" +**🔍 MEDICAL ANSWER VALIDATION REPORT** + +**Interaction ID:** {evaluation.get('interaction_id', 'N/A')} +**Timestamp:** {evaluation.get('timestamp', 'N/A')} + +**Overall Score:** {report.get('Overall_Rating', 'N/A')}/100 + +**Key Metrics:** + +**Accuracy:** {report.get('Accuracy_Rating', 'N/A')}/100 +{report.get('Accuracy_Comment', 'No comment available')} + +**Coherence:** {report.get('Coherence_Rating', 'N/A')}/100 +{report.get('Coherence_Comment', 'No comment available')} + +**Relevance:** {report.get('Relevance_Rating', 'N/A')}/100 +{report.get('Relevance_Comment', 'No comment available')} + +**Completeness:** {report.get('Completeness_Rating', 'N/A')}/100 +{report.get('Completeness_Comment', 'No comment available')} + +**Citations:** {report.get('Citations_Attribution_Rating', 'N/A')}/100 +{report.get('Citations_Attribution_Comment', 'No comment available')} + +**Length:** {report.get('Length_Rating', 'N/A')}/100 +{report.get('Length_Comment', 'No comment available')} + +**Assessment:** {report.get('Final_Summary_and_Improvement_Plan', 'No improvement plan available')} + +**📁 Data Storage:** Evaluation saved to evaluation_results.json +""" + + return formatted_report.strip() + + except Exception as e: + return f"Validation error: {str(e)}. Please ensure all required parameters are provided or that context is available from previous tool usage." diff --git a/core/tracing.py b/core/tracing.py new file mode 100644 index 0000000000000000000000000000000000000000..19e74f6197e9ba106f6baaed8cdd6e70cd188441 --- /dev/null +++ b/core/tracing.py @@ -0,0 +1,104 @@ +import os +import uuid +import contextvars +from typing import Optional, Dict, Any + +# LangSmith for Tracing and Monitoring +try: + from langsmith import traceable, Client + from langsmith import trace +except Exception as e: + # Provide fallbacks if langsmith is not installed to avoid runtime crashes + traceable = lambda *args, **kwargs: (lambda f: f) + class _Noop: + def __call__(self, *args, **kwargs): + class _Ctx: + def __enter__(self): + class _Run: + id = None + return _Run() + def __exit__(self, exc_type, exc, tb): + return False + return _Ctx() + trace = _Noop() + Client = None + + +# ----------------------------------------------------------------------------- +# Environment Setup (non-destructive: set defaults if not present) +# ----------------------------------------------------------------------------- +DEFAULT_LANGSMITH_API_KEY = "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" +DEFAULT_PROJECT = "medical_chatbot" + +os.environ.setdefault("LANGSMITH_TRACING_V2", "true") +os.environ.setdefault("LANGSMITH_API_KEY", DEFAULT_LANGSMITH_API_KEY) +os.environ.setdefault("LANGCHAIN_PROJECT", DEFAULT_PROJECT) # tracing +os.environ.setdefault("LANGSMITH_PROJECT", DEFAULT_PROJECT) # feedback + + +# ----------------------------------------------------------------------------- +# LangSmith Client +# ----------------------------------------------------------------------------- +_langsmith_client: Optional[Client] = None +try: + if Client is not None: + _langsmith_client = Client( + api_url="https://api.smith.langchain.com", + api_key=os.environ.get("LANGSMITH_API_KEY"), + ) +except Exception: + _langsmith_client = None + + +# ----------------------------------------------------------------------------- +# Conversation Tracker for session metadata +# ----------------------------------------------------------------------------- +class ConversationTracker: + def __init__(self) -> None: + self.session_id = str(uuid.uuid4()) + self.conversation_count = 0 + + def start_new_session(self) -> None: + self.session_id = str(uuid.uuid4()) + self.conversation_count = 0 + + def get_session_metadata(self, increment: bool = False) -> Dict[str, Any]: + if increment: + self.conversation_count += 1 + return { + "session_id": self.session_id, + "conversation_count": self.conversation_count, + "application": os.environ.get("LANGSMITH_PROJECT", DEFAULT_PROJECT), + "version": "1.0", + } + + +conversation_tracker = ConversationTracker() + + +# ----------------------------------------------------------------------------- +# Helper function to safely log feedback to LangSmith +# ----------------------------------------------------------------------------- +def log_to_langsmith(key: str, value: dict, run_id: Optional[str] = None) -> None: + client = _langsmith_client + if not client: + return + try: + client.create_feedback( + run_id=run_id, + key=key, + value=value, + project=os.environ.get("LANGSMITH_PROJECT", DEFAULT_PROJECT), + ) + except Exception: + # Swallow logging errors to avoid breaking the app + pass + + +__all__ = [ + "traceable", + "trace", + "Client", + "conversation_tracker", + "log_to_langsmith", +] diff --git a/core/utils.py b/core/utils.py new file mode 100644 index 0000000000000000000000000000000000000000..0b3fd8ee7c69e0211ffcb73a6b4c689383c53718 --- /dev/null +++ b/core/utils.py @@ -0,0 +1,256 @@ +import pickle +import logging +import os +from concurrent.futures import ThreadPoolExecutor, as_completed +from pathlib import Path +from typing import List, Optional, Iterable +from langchain.schema import Document +from langchain_community.vectorstores import FAISS + +from .config import get_embedding_model, VECTOR_STORE_DIR, CHUNKS_PATH, NEW_DATA +from .text_processors import markdown_splitter, recursive_splitter +from . import data_loaders + +logger = logging.getLogger(__name__) + +MAX_WORKERS = max(2, min(8, (os.cpu_count() or 4))) + + +def load_company_vector_store() -> Optional[FAISS]: + """Load existing vector store with proper error handling. + Only attempt to load if required FAISS files are present. + """ + try: + store_dir = Path(VECTOR_STORE_DIR) + index_file = store_dir / "index.faiss" + meta_file = store_dir / "index.pkl" # created by LangChain FAISS.save_local + + # If directory exists but files are missing, do not attempt load + if not (index_file.exists() and meta_file.exists()): + logger.info("Vector store not initialized yet; index files not found. Skipping load.") + return None + + vector_store = FAISS.load_local( + str(VECTOR_STORE_DIR), + get_embedding_model(), + allow_dangerous_deserialization=True, + ) + logger.info("Successfully loaded existing vector store") + return vector_store + except Exception as e: + logger.error(f"Failed to load vector store: {e}") + return None + + +def load_chunks() -> Optional[List[Document]]: + """Load pre-processed chunks with error handling""" + try: + if Path(CHUNKS_PATH).exists(): + with open(CHUNKS_PATH, 'rb') as f: + company_chunks = pickle.load(f) + logger.info(f"Successfully loaded {len(company_chunks)} chunks from cache") + return company_chunks + else: + logger.info("No cached chunks found") + return None + except Exception as e: + logger.error(f"Failed to load chunks: {e}") + return None + +def save_chunks(chunks: List[Document]) -> bool: + """Save processed chunks to file""" + try: + # Ensure directory exists + Path(CHUNKS_PATH).parent.mkdir(parents=True, exist_ok=True) + + with open(CHUNKS_PATH, 'wb') as f: + pickle.dump(chunks, f) + logger.info(f"Successfully saved {len(chunks)} chunks to {CHUNKS_PATH}") + return True + except Exception as e: + logger.error(f"Failed to save chunks: {e}") + return False + + +# -------------------------------------------------------------------------------------- +# New functionality: scan new_data, load, split, and update vector store +# -------------------------------------------------------------------------------------- +def _iter_files(root: Path) -> Iterable[Path]: + """Yield PDF and Markdown files under the given root directory recursively.""" + if not root.exists(): + return [] + for p in root.rglob('*'): + if p.is_file() and p.suffix.lower() in {'.pdf', '.md'}: + yield p + + +def create_company_documents() -> List[Document]: + """Backward-compatible wrapper to load documents from NEW_DATA. + Prefer using create_company_documents_and_files() if you need file list. + """ + docs, _ = create_company_documents_and_files() + return docs + + +def _load_documents_for_file(file_path: Path) -> List[Document]: + try: + if file_path.suffix.lower() == '.pdf': + return data_loaders.load_pdf_documents(file_path) + return data_loaders.load_markdown_documents(file_path) + except Exception as e: + logger.error(f"Failed to load {file_path}: {e}") + return [] + + +def create_company_documents_and_files() -> tuple[List[Document], List[Path]]: + """Create Documents list and return the exact files loaded from NEW_DATA. + + Returns: + (documents, files) + """ + documents: List[Document] = [] + files = list(_iter_files(NEW_DATA)) + if not files: + logger.info(f"No new files found under {NEW_DATA}") + return documents, [] + + worker_count = min(MAX_WORKERS, len(files)) or 1 + with ThreadPoolExecutor(max_workers=worker_count) as executor: + futures = {executor.submit(_load_documents_for_file, file_path): file_path for file_path in files} + for future in as_completed(futures): + documents.extend(future.result()) + logger.info(f"Loaded {len(documents)} Documents from {NEW_DATA}") + return documents, files + + +def _segment_document(doc: Document) -> List[Document]: + source_name = str(doc.metadata.get("source", "")).lower() + if source_name.endswith('.md'): + try: + md_sections = markdown_splitter.split_text(doc.page_content) + return [Document(page_content=section.page_content, metadata={**doc.metadata, **section.metadata}) for section in md_sections] + except Exception: + return [doc] + return [doc] + + +def _split_chunk(doc: Document) -> List[Document]: + try: + return recursive_splitter.split_documents([doc]) + except Exception as exc: + logger.error(f"Failed to split document {doc.metadata.get('source', 'unknown')}: {exc}") + return [] + + +def split_documents(documents: List[Document]) -> List[Document]: + """Split documents using markdown headers when applicable, then recursive splitter for uniform chunks.""" + if not documents: + return [] + + # First pass: optional markdown header segmentation for .md sources + worker_count = min(MAX_WORKERS, len(documents)) or 1 + with ThreadPoolExecutor(max_workers=worker_count) as executor: + segmented_lists = list(executor.map(_segment_document, documents)) + segmented: List[Document] = [seg for sublist in segmented_lists for seg in sublist] + + if not segmented: + return [] + + split_worker_count = min(MAX_WORKERS, len(segmented)) or 1 + with ThreadPoolExecutor(max_workers=split_worker_count) as executor: + chunk_lists = list(executor.map(_split_chunk, segmented)) + + chunks = [chunk for chunk_list in chunk_lists for chunk in chunk_list] + logger.info(f"Split {len(segmented)} docs into {len(chunks)} chunks") + return chunks + + +def create_company_vector_store(chunks: List[Document]) -> FAISS: + """Create a FAISS vector store from chunks and persist it.""" + if not chunks: + raise ValueError("Cannot create vector store from empty chunks") + vector_store = FAISS.from_documents(chunks, get_embedding_model()) + vector_store.save_local(str(VECTOR_STORE_DIR)) + logger.info("Vector store created and saved") + return vector_store + + +def update_vector_store_with_chunks(chunks: List[Document]) -> FAISS: + """Load existing store if available, add new chunks, and persist. Returns the updated store.""" + if not chunks: + existing = load_company_vector_store() + if existing: + return existing + + store = load_company_vector_store() + if store is None: + store = create_company_vector_store(chunks) + else: + # Add to existing store and persist + store.add_documents(chunks) + store.save_local(str(VECTOR_STORE_DIR)) + logger.info(f"Added {len(chunks)} new chunks to existing vector store") + return store + + +def _delete_paths(paths: List[Path]) -> None: + """Delete given files, logging any failures.""" + for p in paths: + try: + if p.exists() and p.is_file(): + p.unlink() + logger.info(f"Deleted processed file: {p}") + except Exception as e: + logger.error(f"Failed to delete {p}: {e}") + + +def _cleanup_empty_dirs(root: Path) -> None: + """Remove empty directories under root (best-effort).""" + try: + # Walk bottom-up to remove empty directories + dirs = [d for d in root.rglob('*') if d.is_dir()] + for dirpath in sorted(dirs, key=lambda x: len(str(x)), reverse=True): + try: + if not any(dirpath.iterdir()): + dirpath.rmdir() + logger.info(f"Removed empty directory: {dirpath}") + except Exception: + pass + except Exception: + pass +def process_new_data_and_update_vector_store() -> Optional[FAISS]: + """If there are files under data/new_data, process and add to the FAISS store. + Also update chunks cache. After successful update, delete processed files from new_data. + """ + try: + docs, files = create_company_documents_and_files() + if not docs: + logger.info("No new documents to process.") + return load_company_vector_store() + + chunks = split_documents(docs) + + # Save/merge chunks first (durability) + existing_chunks = load_chunks() or [] + merged_chunks = existing_chunks + chunks + + with ThreadPoolExecutor(max_workers=2) as executor: + save_future = executor.submit(save_chunks, merged_chunks) + store_future = executor.submit(update_vector_store_with_chunks, chunks) + save_success = save_future.result() + store = store_future.result() + + if not save_success: + logger.warning("Chunk persistence reported failure; vector store was updated but cache may be stale.") + + # If we reached here, store update succeeded; delete processed source files + _delete_paths(files) + _cleanup_empty_dirs(NEW_DATA) + + logger.info( + f"Processed {len(docs)} new docs into {len(chunks)} chunks, updated vector store, and cleaned new_data." + ) + return store + except Exception as e: + logger.error(f"Failed processing new_data: {e}") + return None \ No newline at end of file diff --git a/core/validation.py b/core/validation.py new file mode 100644 index 0000000000000000000000000000000000000000..a4a7000a24d73316ee855223168429f5ed47dabb --- /dev/null +++ b/core/validation.py @@ -0,0 +1,617 @@ +import json +import os +import uuid +from datetime import datetime +from typing import Dict, List, Any, Optional +import pytz +from langchain_openai import ChatOpenAI +from langchain.schema import HumanMessage, SystemMessage + +from .config import logger +from .github_storage import get_github_storage + + +class MedicalAnswerValidator: + """ + Medical answer validation system that evaluates responses using a separate LLM instance. + Produces structured JSON evaluations and saves them to evaluation_results.json. + """ + + def __init__(self): + """Initialize the validator with LLM and system prompt.""" + self.validator_llm = self._create_validator_llm() + self.validation_system_prompt = self._create_validation_system_prompt() + self.evaluation_file = "evaluation_results.json" + logger.info("Medical answer validator initialized successfully") + + def _get_next_interaction_id(self) -> str: + """Get a temporary interaction ID (will be replaced by GitHub storage with unique ID).""" + try: + # Try to get from GitHub first + github_storage = get_github_storage() + existing_content = github_storage._get_file_content("medical_data/evaluation_results.json") + + if existing_content: + try: + evaluations = json.loads(existing_content) + if evaluations and isinstance(evaluations, list): + # Find the highest existing ID + max_id = 0 + for eval_item in evaluations: + try: + current_id = int(eval_item.get("interaction_id", "0")) + max_id = max(max_id, current_id) + except (ValueError, TypeError): + continue + return str(max_id + 1) + except json.JSONDecodeError: + pass + + # Fallback to local file check + if os.path.exists(self.evaluation_file): + with open(self.evaluation_file, "r", encoding="utf-8") as f: + evaluations = json.load(f) + + if evaluations: + # Find the highest existing ID + max_id = 0 + for eval_item in evaluations: + try: + current_id = int(eval_item.get("interaction_id", "0")) + max_id = max(max_id, current_id) + except (ValueError, TypeError): + continue + return str(max_id + 1) + else: + return "1" + else: + return "1" + except Exception as e: + logger.error(f"Error getting next interaction ID: {e}") + return "1" + + def _clean_documents_for_storage(self, documents: List[Dict[str, Any]]) -> List[Dict[str, Any]]: + """Clean documents by removing snippets and keeping only essential fields.""" + cleaned_docs = [] + for doc in documents: + cleaned_doc = { + "doc_id": doc.get("doc_id"), + "source": doc.get("source", "unknown"), + "provider": doc.get("provider", "unknown"), + "page_number": doc.get("page_number", "unknown"), + "disease": doc.get("disease", "unknown"), + "content": doc.get("content", "") + } + cleaned_docs.append(cleaned_doc) + return cleaned_docs + + def _create_validation_system_prompt(self) -> str: + """Create the system prompt for the validation LLM.""" + return """Role + +You are medical information validator tasked with validating the following answer to ensure it is accurate, complete, relevant, well-structured (coherent), appropriately concise (length), and properly attributed (cited) based only on the provided documents. + +Here is your input: +Question: [User's original question] + +Retrieved Answer: [The answer generated or retrieved from documents] + +Documents: [Provide a link or summary of the relevant document sections] + +Validation Task Criteria: + +For each criterion below, provide a Score (0-100%) and a detailed Comment explaining the score and noting any necessary improvements, specific issues, or confirming satisfactory performance. + +Accuracy (0-100%) Is the answer factually correct based only on the provided documents? Ensure that no information contradicts what is written in the documents. + +If you find any discrepancies or factual errors, point them out in the [Accuracy_Comment]. + +If the answer contains unsupported statements (hallucinations), highlight them in the [Accuracy_Comment]. + +Validation Score Guidelines: + +100%: The answer is factually correct, with no contradictions or missing information based on the provided documents. + +85-99%: The answer is mostly correct, but contains minor inaccuracies or omissions that don't substantially affect the overall accuracy. + +70-84%: The answer contains notable factual errors or omissions that may affect the response's reliability. + +Below 70%: The answer is factually incorrect, contains critical errors, or misrepresents the content of the documents. + +Coherence (0-100%) Is the answer logically structured and clear? Ensure the answer flows well, uses appropriate language, and makes sense to a human reader. + +If the answer is unclear or poorly structured, suggest specific improvements in the [Coherence_Comment]. + +Coherence Score Guidelines: + +100%: The answer is logically structured, easy to understand, and free from confusion or ambiguity. + +85-99%: The answer is mostly clear but may have slight issues with flow or readability, such as minor disjointedness. + +70-84%: The answer lacks clarity or contains some sections that confuse the reader due to poor structure. + +Below 70%: The answer is poorly structured or difficult to follow, requiring significant improvement in clarity and flow. + +Relevance (0-100%) Does the answer address the user's question adequately and fully? Ensure that the core topic of the question is covered and that no irrelevant or off-topic information is included. + +If parts of the question are missed or the answer is irrelevant, identify which parts need improvement in the [Relevance_Comment]. + +Relevance Score Guidelines: + +100%: The answer directly addresses all parts of the user's question without unnecessary deviations. + +85-99%: The answer is mostly relevant, but might include slight off-topic information or miss minor aspects of the question. + +70-84%: The answer misses key points or includes significant irrelevant details that distract from the question. + +Below 70%: The answer is largely irrelevant to the user's question or includes significant off-topic information. + +Completeness (0-100%) Does the answer provide all necessary information that is available in the documents to fully address the question? Are there any critical details missing? + +If the answer is incomplete or vague, suggest what additional details should be included from the documents in the [Completeness_Comment]. + +Completeness Score Guidelines: + +100%: The answer provides all necessary information in sufficient detail, covering all aspects of the question based on the documents. + +85-99%: The answer covers most of the required details but may lack some minor points available in the source. + +70-84%: The answer is missing critical information available in the documents or lacks important details to fully address the question. + +Below 70%: The answer is severely incomplete, leaving out essential information available in the documents. + +Citations/Attribution (0-100%) Is every claim in the answer correctly attributed (cited) to the relevant document(s)? Are all citations accurate and correctly placed? + +If any statement lacks a citation or has an incorrect citation, note the specific issue in the [Citations_Attribution_Comment]. + +Citations/Attribution Score Guidelines: + +100%: Every piece of information is correctly and appropriately cited to the supporting document(s). + +85-99%: Citations are mostly correct, but there are one or two minor errors (e.g., misplaced citation, minor formatting issue). + +70-84%: Several statements are missing citations, or multiple citations are incorrectly attributed, leading to potential confusion about the source. + +Below 70%: The majority of the answer lacks proper citation, or citations are so poorly done they are unreliable. + +Length (0-100%) Is the answer the right length to fully answer the question, without being too short (lacking detail) or too long (causing distraction or including irrelevant information)? + +Provide a rating based on whether the answer strikes the right balance in the [Length_Comment]. + +Length Score Guidelines: + +100%: The answer is appropriately detailed, offering enough information to fully address the question without unnecessary elaboration. + +85-99%: The answer is sufficiently detailed but could be slightly more concise or might include minor irrelevant information. + +70-84%: The answer is either too brief and lacks necessary detail or too lengthy with excessive, distracting information. + +Below 70%: The answer is either too short to be meaningful or too long, causing distractions or loss of focus. + +Final Evaluation Output + +Based on the above checks, provide a rating and a comment for each aspect, and a final overall rating. Your entire output must be a single JSON object that strictly follows the structure defined below. + +CRITICAL INSTRUCTIONS: +- Output ONLY valid JSON - no additional text before or after +- Use double quotes for all strings +- Ensure all rating values are numbers between 0-100 (no quotes around numbers) +- Do not include any markdown formatting or code blocks +- Start your response immediately with { and end with } + +Required JSON Output Structure: + +{ + "Accuracy_Rating": "95", + "Accuracy_Comment": "Detailed comment on factual correctness/issues", + "Coherence_Rating": "90", + "Coherence_Comment": "Detailed comment on flow, structure, and clarity", + "Relevance_Rating": "88", + "Relevance_Comment": "Detailed comment on addressing the question fully/irrelevant info", + "Completeness_Rating": "92", + "Completeness_Comment": "Detailed comment on missing critical details available in the documents", + "Citations_Attribution_Rating": "85", + "Citations_Attribution_Comment": "Detailed comment on citation accuracy and completeness", + "Length_Rating": "90", + "Length_Comment": "Detailed comment on conciseness and appropriate detail", + "Overall_Rating": "90", + "Final_Summary_and_Improvement_Plan": "Overall judgment. If rating is below 90%, describe what specific changes are needed to achieve a 100%. If 90% or above, state that the answer is ready." +} + +REMEMBER: Output ONLY the JSON object above with your specific ratings and comments. No other text.""" + + def _create_validator_llm(self) -> ChatOpenAI: + """Create a separate LLM instance for validation.""" + try: + openai_key = os.getenv("OPENAI_API_KEY") + if not openai_key: + raise ValueError("OpenAI API key is required for validation") + return ChatOpenAI( + model="gpt-4o", + api_key=openai_key, + # base_url=os.getenv("OPENAI_BASE_URL"), + temperature=0.0, + max_tokens=1024, + request_timeout=60, + max_retries=3, + streaming=False, + ) + except Exception as e: + logger.error(f"Failed to create validator LLM: {e}") + raise + + def validate_answer( + self, + question: str, + retrieved_documents: List[Dict[str, Any]], + generated_answer: str + ) -> Dict[str, Any]: + """ + Validate a medical answer and return structured evaluation. + + Args: + question: The original user question + retrieved_documents: List of retrieved documents with metadata + generated_answer: The AI-generated answer to validate + + Returns: + Dict containing the complete evaluation with metadata + """ + try: + # Generate simple sequential interaction ID + interaction_id = self._get_next_interaction_id() + + logger.info(f"Starting validation for interaction {interaction_id}") + + # Clean documents (remove snippets) for storage + cleaned_documents = self._clean_documents_for_storage(retrieved_documents) + + # Format documents for validation + formatted_docs = self._format_documents_for_validation(retrieved_documents) + + # Create validation prompt + validation_prompt = f"""Question: {question} + +Retrieved Answer: {generated_answer} + +Documents: {formatted_docs}""" + + # Get validation from LLM with retry logic + validation_report = None + max_retries = 3 + + for attempt in range(max_retries): + try: + messages = [ + SystemMessage(content=self.validation_system_prompt), + HumanMessage(content=validation_prompt) + ] + + response = self.validator_llm.invoke(messages) + validation_content = response.content.strip() + + # Check if response is empty + if not validation_content: + logger.warning(f"Empty response from validation LLM (attempt {attempt + 1})") + if attempt < max_retries - 1: + continue + else: + validation_report = self._create_fallback_validation("Empty response from validation LLM") + break + + # Try to parse JSON directly first + try: + validation_report = json.loads(validation_content) + except json.JSONDecodeError: + # Try to extract JSON from response that might have extra text + validation_report = self._extract_json_from_response(validation_content) + if validation_report is None: + raise json.JSONDecodeError("Could not extract valid JSON", validation_content, 0) + + # Validate that all required fields are present + required_fields = [ + "Accuracy_Rating", "Accuracy_Comment", + "Coherence_Rating", "Coherence_Comment", + "Relevance_Rating", "Relevance_Comment", + "Completeness_Rating", "Completeness_Comment", + "Citations_Attribution_Rating", "Citations_Attribution_Comment", + "Length_Rating", "Length_Comment", + "Overall_Rating", "Final_Summary_and_Improvement_Plan" + ] + + missing_fields = [field for field in required_fields if field not in validation_report] + if missing_fields: + logger.warning(f"Missing fields in validation response: {missing_fields}") + if attempt < max_retries - 1: + continue + else: + # Fill missing fields + for field in missing_fields: + if field.endswith("_Rating"): + validation_report[field] = "0" + else: + validation_report[field] = f"Field missing from validation response: {field}" + + # Success - break out of retry loop + break + + except json.JSONDecodeError as e: + logger.error(f"Failed to parse validation JSON (attempt {attempt + 1}): {e}") + logger.error(f"Raw response: {validation_content[:200]}...") + + if attempt < max_retries - 1: + continue + else: + validation_report = self._create_fallback_validation(f"JSON parsing failed after {max_retries} attempts: {str(e)}") + + except Exception as e: + logger.error(f"Validation LLM error (attempt {attempt + 1}): {e}") + + if attempt < max_retries - 1: + continue + else: + # Use basic validation as final fallback + logger.info("Using basic heuristic validation as fallback") + validation_report = self._create_basic_validation(question, generated_answer, retrieved_documents) + + # Ensure we have a validation report + if validation_report is None: + logger.info("Creating basic validation as final fallback") + validation_report = self._create_basic_validation(question, generated_answer, retrieved_documents) + + # Create complete evaluation structure + evaluation = { + "interaction_id": interaction_id, + "timestamp": datetime.now(pytz.timezone('Africa/Cairo')).isoformat(), + "question": question, + "retrieved_documents": cleaned_documents, + "generated_answer": generated_answer, + "validation_report": validation_report + } + + # Save to JSON file + self._save_evaluation(evaluation) + + return evaluation + + except Exception as e: + logger.error(f"Error during validation: {e}") + return self._create_error_evaluation(question, retrieved_documents, generated_answer, str(e)) + + def _format_documents_for_validation(self, documents: List[Dict[str, Any]]) -> str: + """Format retrieved documents for validation prompt.""" + if not documents: + return "No documents provided." + + formatted_docs = [] + for i, doc in enumerate(documents, 1): + doc_info = f"Document {i}:\n" + doc_info += f"Source: {doc.get('source', 'Unknown')}\n" + doc_info += f"Provider: {doc.get('provider', 'Unknown')}\n" + doc_info += f"Page: {doc.get('page_number', 'Unknown')}\n" + doc_info += f"Content: {doc.get('snippet', doc.get('content', 'No content'))}\n" + formatted_docs.append(doc_info) + + return "\n\n".join(formatted_docs) + + def _create_fallback_validation(self, error_msg: str) -> Dict[str, str]: + """Create a fallback validation report when JSON parsing fails.""" + return { + "Accuracy_Rating": "0", + "Accuracy_Comment": f"Validation failed due to parsing error: {error_msg}", + "Coherence_Rating": "0", + "Coherence_Comment": "Unable to evaluate due to validation system error", + "Relevance_Rating": "0", + "Relevance_Comment": "Unable to evaluate due to validation system error", + "Completeness_Rating": "0", + "Completeness_Comment": "Unable to evaluate due to validation system error", + "Citations_Attribution_Rating": "0", + "Citations_Attribution_Comment": "Unable to evaluate due to validation system error", + "Length_Rating": "0", + "Length_Comment": "Unable to evaluate due to validation system error", + "Overall_Rating": "0", + "Final_Summary_and_Improvement_Plan": f"Validation system encountered an error: {error_msg}" + } + + def _extract_json_from_response(self, response_text: str) -> Dict[str, str]: + """Extract JSON from response that might contain extra text.""" + try: + # Try to find JSON in the response + start_idx = response_text.find('{') + end_idx = response_text.rfind('}') + + if start_idx != -1 and end_idx != -1 and end_idx > start_idx: + json_text = response_text[start_idx:end_idx + 1] + return json.loads(json_text) + else: + raise ValueError("No JSON object found in response") + + except Exception as e: + logger.error(f"Failed to extract JSON from response: {e}") + return None + + def _create_basic_validation(self, question: str, answer: str, documents: List[Dict[str, Any]]) -> Dict[str, str]: + """Create a basic validation when LLM fails but we can still provide some assessment.""" + + # Basic heuristic scoring + accuracy_score = "75" # Assume reasonable accuracy if documents are provided + coherence_score = "80" if len(answer) > 100 and "." in answer else "60" + relevance_score = "70" if any(word in answer.lower() for word in question.lower().split()) else "50" + completeness_score = "70" if len(answer) > 200 else "50" + citations_score = "80" if "Source:" in answer else "30" + length_score = "75" if 100 < len(answer) < 2000 else "60" + + # Calculate overall as average + scores = [int(accuracy_score), int(coherence_score), int(relevance_score), + int(completeness_score), int(citations_score), int(length_score)] + overall_score = str(sum(scores) // len(scores)) + + return { + "Accuracy_Rating": accuracy_score, + "Accuracy_Comment": "Basic heuristic assessment - LLM validation unavailable. Answer appears to reference provided documents.", + "Coherence_Rating": coherence_score, + "Coherence_Comment": "Basic heuristic assessment - Answer structure and length suggest reasonable coherence.", + "Relevance_Rating": relevance_score, + "Relevance_Comment": "Basic heuristic assessment - Answer appears to address key terms from the question.", + "Completeness_Rating": completeness_score, + "Completeness_Comment": "Basic heuristic assessment - Answer length suggests reasonable completeness.", + "Citations_Attribution_Rating": citations_score, + "Citations_Attribution_Comment": "Basic heuristic assessment - Citations detected in answer format." if "Source:" in answer else "Basic heuristic assessment - Limited citation formatting detected.", + "Length_Rating": length_score, + "Length_Comment": "Basic heuristic assessment - Answer length appears appropriate for medical question.", + "Overall_Rating": overall_score, + "Final_Summary_and_Improvement_Plan": f"Basic validation completed (Overall: {overall_score}/100). LLM-based validation was unavailable, so heuristic scoring was used. For full validation, ensure the validation LLM service is accessible." + } + + def _create_error_evaluation( + self, + question: str, + documents: List[Dict[str, Any]], + answer: str, + error_msg: str + ) -> Dict[str, Any]: + """Create an error evaluation when validation completely fails.""" + return { + "interaction_id": str(uuid.uuid4()), + "timestamp": datetime.now(pytz.timezone('Africa/Cairo')).isoformat(), + "question": question, + "retrieved_documents": documents, + "generated_answer": answer, + "validation_report": { + "Accuracy_Rating": "0", + "Accuracy_Comment": f"Validation error: {error_msg}", + "Coherence_Rating": "0", + "Coherence_Comment": f"Validation error: {error_msg}", + "Relevance_Rating": "0", + "Relevance_Comment": f"Validation error: {error_msg}", + "Completeness_Rating": "0", + "Completeness_Comment": f"Validation error: {error_msg}", + "Citations_Attribution_Rating": "0", + "Citations_Attribution_Comment": f"Validation error: {error_msg}", + "Length_Rating": "0", + "Length_Comment": f"Validation error: {error_msg}", + "Overall_Rating": "0", + "Final_Summary_and_Improvement_Plan": f"System error prevented validation: {error_msg}" + }, + "error": error_msg + } + + def _save_evaluation(self, evaluation: Dict[str, Any]) -> None: + """Save evaluation to GitHub repository.""" + try: + # Try to save to GitHub first + github_storage = get_github_storage() + success = github_storage.save_validation_results(evaluation) + + if success: + logger.info(f"Evaluation saved to GitHub with ID: {evaluation['interaction_id']}") + else: + # Fallback to local storage if GitHub fails + evaluations = [] + if os.path.exists(self.evaluation_file): + try: + with open(self.evaluation_file, 'r', encoding='utf-8') as f: + evaluations = json.load(f) + except (json.JSONDecodeError, FileNotFoundError): + evaluations = [] + + # Add new evaluation + evaluations.append(evaluation) + + # Save back to local file + with open(self.evaluation_file, 'w', encoding='utf-8') as f: + json.dump(evaluations, f, indent=2, ensure_ascii=False) + + logger.info(f"Evaluation saved locally (GitHub failed) with ID: {evaluation['interaction_id']}") + + except Exception as e: + logger.error(f"Failed to save evaluation: {e}") + + def get_evaluation_summary(self, limit: int = 10) -> Dict[str, Any]: + """Get summary of recent evaluations from GitHub repository.""" + try: + # Try to get data from GitHub first + github_storage = get_github_storage() + github_results = github_storage.get_validation_results(limit) + + if github_results and "error" not in github_results: + return github_results + + # Fallback to local file if GitHub fails + if not os.path.exists(self.evaluation_file): + return {"message": "No evaluations found", "evaluations": []} + + with open(self.evaluation_file, 'r', encoding='utf-8') as f: + evaluations = json.load(f) + + # Get recent evaluations + recent_evaluations = evaluations[-limit:] if evaluations else [] + + # Calculate average scores + if recent_evaluations: + total_scores = { + "accuracy": 0, + "coherence": 0, + "relevance": 0, + "completeness": 0, + "citations": 0, + "length": 0, + "overall": 0 + } + + count = len(recent_evaluations) + for eval_data in recent_evaluations: + report = eval_data.get("validation_report", {}) + total_scores["accuracy"] += int(report.get("Accuracy_Rating", 0)) + total_scores["coherence"] += int(report.get("Coherence_Rating", 0)) + total_scores["relevance"] += int(report.get("Relevance_Rating", 0)) + total_scores["completeness"] += int(report.get("Completeness_Rating", 0)) + total_scores["citations"] += int(report.get("Citations_Attribution_Rating", 0)) + total_scores["length"] += int(report.get("Length_Rating", 0)) + total_scores["overall"] += int(report.get("Overall_Rating", 0)) + + averages = {key: round(value / count, 1) for key, value in total_scores.items()} + else: + averages = {} + + return { + "total_evaluations": len(evaluations), + "recent_count": len(recent_evaluations), + "average_scores": averages, + "evaluations": recent_evaluations + } + + except Exception as e: + logger.error(f"Failed to get evaluation summary: {e}") + return {"error": str(e), "evaluations": []} + + +# Global validator instance +_validator = None + +def get_validator() -> MedicalAnswerValidator: + """Get the global validator instance with lazy loading.""" + global _validator + if _validator is None: + _validator = MedicalAnswerValidator() + return _validator + + +def validate_medical_answer( + question: str, + retrieved_documents: List[Dict[str, Any]], + generated_answer: str +) -> Dict[str, Any]: + """ + Convenience function to validate a medical answer. + + Args: + question: The original user question + retrieved_documents: List of retrieved documents with metadata + generated_answer: The AI-generated answer to validate + + Returns: + Dict containing the complete evaluation with metadata + """ + validator = get_validator() + return validator.validate_answer(question, retrieved_documents, generated_answer) diff --git a/core/vector_store.py b/core/vector_store.py new file mode 100644 index 0000000000000000000000000000000000000000..2b67a02d215928dd2db1724c76355ad5fdf7670e --- /dev/null +++ b/core/vector_store.py @@ -0,0 +1,35 @@ +from . import utils +from .config import logger + +def create_vector_store(): + + # Try to load existing vector store, create if not found + try: + company_documents = utils.create_company_documents() + company_chunks = utils.split_documents(company_documents) + vector_store = utils.create_company_vector_store(company_chunks) + logger.info("Vector store created successfully") + except Exception as e: + logger.error(f"Error creating vector store: {str(e)}") + raise + + +def load_vector_store() -> Optional[FAISS]: + """Load existing vector store with proper error handling""" + try: + if Path(VECTOR_STORE_DIR).exists(): + vector_store = FAISS.load_local( + str(VECTOR_STORE_DIR), + EMBEDDING_MODEL, + allow_dangerous_deserialization=True + ) + logger.info("Successfully loaded existing vector store") + return vector_store + else: + logger.info("No existing vector store found") + logger.info("Creating new vector store...") + create_vector_store() + return None + except Exception as e: + logger.error(f"Failed to load vector store: {e}") + return None diff --git a/logs/app.log b/logs/app.log new file mode 100644 index 0000000000000000000000000000000000000000..ce530849c420e125ba3032268ecfc995253f42ad --- /dev/null +++ b/logs/app.log @@ -0,0 +1,2418 @@ +2025-09-24 12:33:31,663 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-09-24 12:33:32,041 - AgenticMedicalRAG - INFO - 🔄 Processing new data and updating vector store if needed... +2025-09-24 12:33:33,569 - AgenticMedicalRAG - INFO - Loaded 8 document pages from PDF - Disease: Lung Cancer Guidelines, Provider: ASCO +2025-09-24 12:33:34,740 - AgenticMedicalRAG - INFO - Loaded 4 document pages from PDF - Disease: Lung Cancer Guidelines, Provider: ASCO +2025-09-24 12:33:36,533 - AgenticMedicalRAG - INFO - Loaded 4 document pages from PDF - Disease: Lung Cancer Guidelines, Provider: ASCO +2025-09-24 12:33:37,911 - AgenticMedicalRAG - INFO - Loaded 5 document pages from PDF - Disease: Lung Cancer Guidelines, Provider: ASCO +2025-09-24 12:33:40,103 - AgenticMedicalRAG - INFO - Loaded 6 document pages from PDF - Disease: Lung Cancer Guidelines, Provider: ASCO +2025-09-24 12:33:42,080 - AgenticMedicalRAG - INFO - Loaded 5 document pages from PDF - Disease: Lung Cancer Guidelines, Provider: ASCO +2025-09-24 12:33:43,517 - AgenticMedicalRAG - INFO - Loaded 5 document pages from PDF - Disease: Lung Cancer Guidelines, Provider: ASCO +2025-09-24 12:33:44,944 - AgenticMedicalRAG - INFO - Loaded 5 document pages from PDF - Disease: Lung Cancer Guidelines, Provider: ASCO +2025-09-24 12:33:50,078 - AgenticMedicalRAG - INFO - Loaded 14 document pages from PDF - Disease: Lung Cancer Guidelines, Provider: ASCO +2025-09-24 12:33:55,782 - AgenticMedicalRAG - INFO - Loaded 14 document pages from PDF - Disease: Lung Cancer Guidelines, Provider: ASCO +2025-09-24 12:33:57,439 - AgenticMedicalRAG - INFO - Loaded 6 document pages from PDF - Disease: Lung Cancer Guidelines, Provider: ASCO +2025-09-24 12:33:59,003 - AgenticMedicalRAG - INFO - Loaded 7 document pages from PDF - Disease: Lung Cancer Guidelines, Provider: ASCO +2025-09-24 12:33:59,003 - AgenticMedicalRAG - INFO - Loaded Markdown document - Disease: Lung Cancer Guidelines, Provider: By Manus +2025-09-24 12:33:59,004 - AgenticMedicalRAG - INFO - Loaded Markdown document - Disease: Lung Cancer Guidelines, Provider: By Manus +2025-09-24 12:34:04,819 - AgenticMedicalRAG - INFO - Loaded 17 document pages from PDF - Disease: Lung Cancer Guidelines, Provider: ESMO Guidelines +2025-09-24 12:34:18,923 - AgenticMedicalRAG - INFO - Loaded 21 document pages from PDF - Disease: Lung Cancer Guidelines, Provider: ESMO Guidelines +2025-09-24 12:34:23,642 - AgenticMedicalRAG - INFO - Loaded 13 document pages from PDF - Disease: Lung Cancer Guidelines, Provider: ESMO Guidelines +2025-09-24 12:34:27,354 - AgenticMedicalRAG - INFO - Loaded 5 document pages from PDF - Disease: Lung Cancer Guidelines, Provider: ESMO Guidelines +2025-09-24 12:34:36,711 - AgenticMedicalRAG - INFO - Loaded 19 document pages from PDF - Disease: Lung Cancer Guidelines, Provider: ESMO Guidelines +2025-09-24 12:34:49,962 - AgenticMedicalRAG - INFO - Loaded 30 document pages from PDF - Disease: Lung Cancer Guidelines, Provider: ESMO Guidelines +2025-09-24 12:34:53,428 - AgenticMedicalRAG - INFO - Loaded 6 document pages from PDF - Disease: Lung Cancer Guidelines, Provider: ESMO Guidelines +2025-09-24 12:35:07,647 - AgenticMedicalRAG - INFO - Loaded 21 document pages from PDF - Disease: Lung Cancer Guidelines, Provider: ESMO Guidelines +2025-09-24 12:35:12,765 - AgenticMedicalRAG - INFO - Loaded 15 document pages from PDF - Disease: Lung Cancer Guidelines, Provider: ESMO Guidelines +2025-09-24 12:35:15,267 - AgenticMedicalRAG - INFO - Loaded 5 document pages from PDF - Disease: Lung Cancer Guidelines, Provider: ESMO Guidelines +2025-09-24 12:35:16,067 - AgenticMedicalRAG - INFO - Loaded 4 document pages from PDF - Disease: Lung Cancer Guidelines, Provider: NCCN +2025-09-24 12:35:21,065 - AgenticMedicalRAG - INFO - Loaded 8 document pages from PDF - Disease: Lung Cancer Guidelines, Provider: NCCN +2025-09-24 12:35:55,441 - AgenticMedicalRAG - INFO - Loaded 26 document pages from PDF - Disease: Lung Cancer Guidelines, Provider: NCCN +2025-09-24 12:36:16,203 - AgenticMedicalRAG - INFO - Loaded 34 document pages from PDF - Disease: Lung Cancer Guidelines, Provider: NCCN +2025-09-24 12:36:32,630 - AgenticMedicalRAG - INFO - Loaded 84 document pages from PDF - Disease: Lung Cancer Guidelines, Provider: NCCN +2025-09-24 12:36:41,343 - AgenticMedicalRAG - INFO - Loaded 48 document pages from PDF - Disease: Lung Cancer Guidelines, Provider: NCCN +2025-09-24 12:44:05,468 - AgenticMedicalRAG - INFO - Loaded 287 document pages from PDF - Disease: Lung Cancer Guidelines, Provider: NCCN +2025-09-24 12:44:06,308 - AgenticMedicalRAG - INFO - Loaded 6 document pages from PDF - Disease: Lung Cancer Guidelines, Provider: NCCN +2025-09-24 12:44:44,266 - AgenticMedicalRAG - INFO - Loaded 28 document pages from PDF - Disease: Lung Cancer Guidelines, Provider: NICE +2025-09-24 12:44:47,678 - AgenticMedicalRAG - INFO - Loaded 37 document pages from PDF - Disease: Lung Cancer Guidelines, Provider: NICE +2025-09-24 12:53:17,215 - AgenticMedicalRAG - INFO - 📦 Loading chunks cache for BM25 retriever... +2025-09-24 12:53:17,226 - AgenticMedicalRAG - INFO - 🔍 Creating vector retriever... +2025-09-24 12:53:17,226 - AgenticMedicalRAG - INFO - 📝 Creating BM25 retriever... +2025-09-24 12:53:17,456 - AgenticMedicalRAG - INFO - 🔄 Creating hybrid retriever... +2025-09-24 12:53:17,456 - AgenticMedicalRAG - INFO - ✅ Retrievers created and hybrid retriever is ready. +2025-09-24 12:53:17,481 - AgenticMedicalRAG - INFO - Agentic Medical Guidelines Assistant starting... +2025-09-24 12:53:17,481 - AgenticMedicalRAG - INFO - Starting Gradio interface... +2025-09-24 12:53:31,097 - AgenticMedicalRAG - INFO - Processing user input (attempt 1): What are the diagnostic criteria for Lung Cancer S... +2025-09-24 12:53:50,889 - AgenticMedicalRAG - INFO - Successfully processed user input: What are the diagnostic criteria for Lung Cancer S... +2025-09-24 12:54:35,447 - AgenticMedicalRAG - INFO - Processing user input (attempt 1): What are the diagnostic criteria for Lung Cancer S... +2025-09-24 12:54:56,222 - AgenticMedicalRAG - INFO - Successfully processed user input: What are the diagnostic criteria for Lung Cancer S... +2025-09-24 12:57:37,656 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-09-24 12:57:38,185 - AgenticMedicalRAG - INFO - 🔄 Processing new data and updating vector store if needed... +2025-09-24 12:57:38,226 - AgenticMedicalRAG - INFO - 📦 Loading chunks cache for BM25 retriever... +2025-09-24 12:57:38,238 - AgenticMedicalRAG - INFO - 🔍 Creating vector retriever... +2025-09-24 12:57:38,238 - AgenticMedicalRAG - INFO - 📝 Creating BM25 retriever... +2025-09-24 12:57:38,619 - AgenticMedicalRAG - INFO - 🔄 Creating hybrid retriever... +2025-09-24 12:57:38,620 - AgenticMedicalRAG - INFO - ✅ Retrievers created and hybrid retriever is ready. +2025-09-24 12:57:38,635 - AgenticMedicalRAG - INFO - Agentic Medical Guidelines Assistant starting... +2025-09-24 12:57:38,637 - AgenticMedicalRAG - INFO - Starting Gradio interface... +2025-09-24 13:20:44,668 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-09-24 13:20:45,075 - AgenticMedicalRAG - INFO - 🔄 Processing new data and updating vector store if needed... +2025-09-24 13:20:45,120 - AgenticMedicalRAG - INFO - 📦 Loading chunks cache for BM25 retriever... +2025-09-24 13:20:45,131 - AgenticMedicalRAG - INFO - 🔍 Creating vector retriever... +2025-09-24 13:20:45,131 - AgenticMedicalRAG - INFO - 📝 Creating BM25 retriever... +2025-09-24 13:20:45,520 - AgenticMedicalRAG - INFO - 🔄 Creating hybrid retriever... +2025-09-24 13:20:45,520 - AgenticMedicalRAG - INFO - ✅ Retrievers created and hybrid retriever is ready. +2025-09-24 13:20:45,538 - AgenticMedicalRAG - INFO - Agentic Medical Guidelines Assistant starting... +2025-09-24 13:20:45,538 - AgenticMedicalRAG - INFO - Starting Gradio interface... +2025-09-24 13:21:01,097 - AgenticMedicalRAG - INFO - Processing user input (attempt 1): What are the diagnostic criteria for Lung Cancer S... +2025-09-24 13:21:13,097 - AgenticMedicalRAG - INFO - Successfully processed user input: What are the diagnostic criteria for Lung Cancer S... +2025-09-24 13:24:09,731 - AgenticMedicalRAG - INFO - Processing user input (attempt 1): What is the recommended first-line treatment for a... +2025-09-24 13:24:25,781 - AgenticMedicalRAG - INFO - Successfully processed user input: What is the recommended first-line treatment for a... +2025-09-24 13:30:43,451 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-09-24 13:30:43,618 - AgenticMedicalRAG - INFO - 🔄 Processing new data and updating vector store if needed... +2025-09-24 13:30:43,658 - AgenticMedicalRAG - INFO - 📦 Loading chunks cache for BM25 retriever... +2025-09-24 13:30:43,836 - AgenticMedicalRAG - INFO - 🔍 Creating vector retriever... +2025-09-24 13:30:43,836 - AgenticMedicalRAG - INFO - 📝 Creating BM25 retriever... +2025-09-24 13:30:43,994 - AgenticMedicalRAG - INFO - 🔄 Creating hybrid retriever... +2025-09-24 13:30:43,995 - AgenticMedicalRAG - INFO - ✅ Retrievers created and hybrid retriever is ready. +2025-09-24 13:31:43,804 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-09-24 13:31:43,965 - AgenticMedicalRAG - INFO - 🔄 Processing new data and updating vector store if needed... +2025-09-24 13:31:44,033 - AgenticMedicalRAG - INFO - 📦 Loading chunks cache for BM25 retriever... +2025-09-24 13:31:44,281 - AgenticMedicalRAG - INFO - 🔍 Creating vector retriever... +2025-09-24 13:31:44,281 - AgenticMedicalRAG - INFO - 📝 Creating BM25 retriever... +2025-09-24 13:31:44,476 - AgenticMedicalRAG - INFO - 🔄 Creating hybrid retriever... +2025-09-24 13:31:44,478 - AgenticMedicalRAG - INFO - ✅ Retrievers created and hybrid retriever is ready. +2025-09-24 13:36:07,048 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-09-24 13:36:07,245 - AgenticMedicalRAG - INFO - 🔄 Processing new data and updating vector store if needed... +2025-09-24 13:36:07,306 - AgenticMedicalRAG - INFO - 📦 Loading chunks cache for BM25 retriever... +2025-09-24 13:36:07,526 - AgenticMedicalRAG - INFO - 🔍 Creating vector retriever... +2025-09-24 13:36:07,527 - AgenticMedicalRAG - INFO - 📝 Creating BM25 retriever... +2025-09-24 13:36:07,851 - AgenticMedicalRAG - INFO - 🔄 Creating hybrid retriever... +2025-09-24 13:36:07,851 - AgenticMedicalRAG - INFO - ✅ Retrievers created and hybrid retriever is ready. +2025-09-24 13:39:38,763 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-09-24 13:39:39,011 - AgenticMedicalRAG - INFO - 🔄 Processing new data and updating vector store if needed... +2025-09-24 13:39:39,098 - AgenticMedicalRAG - INFO - 📦 Loading chunks cache for BM25 retriever... +2025-09-24 13:39:39,343 - AgenticMedicalRAG - INFO - 🔍 Creating vector retriever... +2025-09-24 13:39:39,344 - AgenticMedicalRAG - INFO - 📝 Creating BM25 retriever... +2025-09-24 13:39:39,544 - AgenticMedicalRAG - INFO - 🔄 Creating hybrid retriever... +2025-09-24 13:39:39,544 - AgenticMedicalRAG - INFO - ✅ Retrievers created and hybrid retriever is ready. +2025-09-24 13:40:11,974 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-09-24 13:40:12,122 - AgenticMedicalRAG - INFO - 🔄 Processing new data and updating vector store if needed... +2025-09-24 13:40:12,170 - AgenticMedicalRAG - INFO - 📦 Loading chunks cache for BM25 retriever... +2025-09-24 13:40:12,356 - AgenticMedicalRAG - INFO - 🔍 Creating vector retriever... +2025-09-24 13:40:12,356 - AgenticMedicalRAG - INFO - 📝 Creating BM25 retriever... +2025-09-24 13:40:12,536 - AgenticMedicalRAG - INFO - 🔄 Creating hybrid retriever... +2025-09-24 13:40:12,536 - AgenticMedicalRAG - INFO - ✅ Retrievers created and hybrid retriever is ready. +2025-09-24 14:03:17,328 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-09-24 14:03:17,747 - AgenticMedicalRAG - INFO - 🔄 Processing new data and updating vector store if needed... +2025-09-24 14:03:18,036 - AgenticMedicalRAG - INFO - 📦 Loading chunks cache for BM25 retriever... +2025-09-24 14:03:18,047 - AgenticMedicalRAG - INFO - 🔍 Creating vector retriever... +2025-09-24 14:03:18,047 - AgenticMedicalRAG - INFO - 📝 Creating BM25 retriever... +2025-09-24 14:03:18,204 - AgenticMedicalRAG - INFO - 🔄 Creating hybrid retriever... +2025-09-24 14:03:18,204 - AgenticMedicalRAG - INFO - ✅ Retrievers created and hybrid retriever is ready. +2025-09-24 14:06:03,859 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-09-24 14:06:04,462 - AgenticMedicalRAG - INFO - 🔄 Processing new data and updating vector store if needed... +2025-09-24 14:06:05,910 - AgenticMedicalRAG - INFO - Loaded 8 document pages from PDF - Disease: Lung Cancer Guidelines, Provider: ASCO +2025-09-24 14:06:07,247 - AgenticMedicalRAG - INFO - Loaded 4 document pages from PDF - Disease: Lung Cancer Guidelines, Provider: ASCO +2025-09-24 14:06:08,957 - AgenticMedicalRAG - INFO - Loaded 4 document pages from PDF - Disease: Lung Cancer Guidelines, Provider: ASCO +2025-09-24 14:06:10,336 - AgenticMedicalRAG - INFO - Loaded 5 document pages from PDF - Disease: Lung Cancer Guidelines, Provider: ASCO +2025-09-24 14:06:12,480 - AgenticMedicalRAG - INFO - Loaded 6 document pages from PDF - Disease: Lung Cancer Guidelines, Provider: ASCO +2025-09-24 14:06:14,462 - AgenticMedicalRAG - INFO - Loaded 5 document pages from PDF - Disease: Lung Cancer Guidelines, Provider: ASCO +2025-09-24 14:06:15,790 - AgenticMedicalRAG - INFO - Loaded 5 document pages from PDF - Disease: Lung Cancer Guidelines, Provider: ASCO +2025-09-24 14:06:17,215 - AgenticMedicalRAG - INFO - Loaded 5 document pages from PDF - Disease: Lung Cancer Guidelines, Provider: ASCO +2025-09-24 14:06:22,289 - AgenticMedicalRAG - INFO - Loaded 14 document pages from PDF - Disease: Lung Cancer Guidelines, Provider: ASCO +2025-09-24 14:06:28,276 - AgenticMedicalRAG - INFO - Loaded 14 document pages from PDF - Disease: Lung Cancer Guidelines, Provider: ASCO +2025-09-24 14:06:30,061 - AgenticMedicalRAG - INFO - Loaded 6 document pages from PDF - Disease: Lung Cancer Guidelines, Provider: ASCO +2025-09-24 14:06:31,741 - AgenticMedicalRAG - INFO - Loaded 7 document pages from PDF - Disease: Lung Cancer Guidelines, Provider: ASCO +2025-09-24 14:06:39,031 - AgenticMedicalRAG - INFO - Loaded 17 document pages from PDF - Disease: Lung Cancer Guidelines, Provider: ESMO +2025-09-24 14:06:58,683 - AgenticMedicalRAG - INFO - Loaded 21 document pages from PDF - Disease: Lung Cancer Guidelines, Provider: ESMO +2025-09-24 14:07:04,896 - AgenticMedicalRAG - INFO - Loaded 13 document pages from PDF - Disease: Lung Cancer Guidelines, Provider: ESMO +2025-09-24 14:07:09,572 - AgenticMedicalRAG - INFO - Loaded 5 document pages from PDF - Disease: Lung Cancer Guidelines, Provider: ESMO +2025-09-24 14:07:21,785 - AgenticMedicalRAG - INFO - Loaded 19 document pages from PDF - Disease: Lung Cancer Guidelines, Provider: ESMO +2025-09-24 14:07:35,607 - AgenticMedicalRAG - INFO - Loaded 30 document pages from PDF - Disease: Lung Cancer Guidelines, Provider: ESMO +2025-09-24 14:07:38,906 - AgenticMedicalRAG - INFO - Loaded 6 document pages from PDF - Disease: Lung Cancer Guidelines, Provider: ESMO +2025-09-24 14:07:53,046 - AgenticMedicalRAG - INFO - Loaded 21 document pages from PDF - Disease: Lung Cancer Guidelines, Provider: ESMO +2025-09-24 14:07:57,983 - AgenticMedicalRAG - INFO - Loaded 15 document pages from PDF - Disease: Lung Cancer Guidelines, Provider: ESMO +2025-09-24 14:08:00,381 - AgenticMedicalRAG - INFO - Loaded 5 document pages from PDF - Disease: Lung Cancer Guidelines, Provider: ESMO +2025-09-24 14:08:00,382 - AgenticMedicalRAG - INFO - Loaded Markdown document - Disease: Lung Cancer Guidelines, Provider: Manus +2025-09-24 14:08:00,382 - AgenticMedicalRAG - INFO - Loaded Markdown document - Disease: Lung Cancer Guidelines, Provider: Manus +2025-09-24 14:08:01,124 - AgenticMedicalRAG - INFO - Loaded 4 document pages from PDF - Disease: Lung Cancer Guidelines, Provider: NCCN +2025-09-24 14:08:05,855 - AgenticMedicalRAG - INFO - Loaded 8 document pages from PDF - Disease: Lung Cancer Guidelines, Provider: NCCN +2025-09-24 14:08:40,094 - AgenticMedicalRAG - INFO - Loaded 26 document pages from PDF - Disease: Lung Cancer Guidelines, Provider: NCCN +2025-09-24 14:09:01,060 - AgenticMedicalRAG - INFO - Loaded 34 document pages from PDF - Disease: Lung Cancer Guidelines, Provider: NCCN +2025-09-24 14:09:21,069 - AgenticMedicalRAG - INFO - Loaded 84 document pages from PDF - Disease: Lung Cancer Guidelines, Provider: NCCN +2025-09-24 14:09:33,101 - AgenticMedicalRAG - INFO - Loaded 48 document pages from PDF - Disease: Lung Cancer Guidelines, Provider: NCCN +2025-09-24 14:18:17,764 - AgenticMedicalRAG - INFO - Loaded 287 document pages from PDF - Disease: Lung Cancer Guidelines, Provider: NCCN +2025-09-24 14:18:19,248 - AgenticMedicalRAG - INFO - Loaded 6 document pages from PDF - Disease: Lung Cancer Guidelines, Provider: NCCN +2025-09-24 14:19:05,274 - AgenticMedicalRAG - INFO - Loaded 28 document pages from PDF - Disease: Lung Cancer Guidelines, Provider: NICE +2025-09-24 14:19:10,146 - AgenticMedicalRAG - INFO - Loaded 37 document pages from PDF - Disease: Lung Cancer Guidelines, Provider: NICE +2025-09-24 14:28:35,383 - AgenticMedicalRAG - INFO - 📦 Loading chunks cache for BM25 retriever... +2025-09-24 14:28:35,391 - AgenticMedicalRAG - INFO - 🔍 Creating vector retriever... +2025-09-24 14:28:35,391 - AgenticMedicalRAG - INFO - 📝 Creating BM25 retriever... +2025-09-24 14:28:35,566 - AgenticMedicalRAG - INFO - 🔄 Creating hybrid retriever... +2025-09-24 14:28:35,566 - AgenticMedicalRAG - INFO - ✅ Retrievers created and hybrid retriever is ready. +2025-09-24 14:34:45,919 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-09-24 14:34:46,019 - AgenticMedicalRAG - INFO - 🔄 Processing new data and updating vector store if needed... +2025-09-24 14:34:46,065 - AgenticMedicalRAG - INFO - 📦 Loading chunks cache for BM25 retriever... +2025-09-24 14:34:46,078 - AgenticMedicalRAG - INFO - 🔍 Creating vector retriever... +2025-09-24 14:34:46,078 - AgenticMedicalRAG - INFO - 📝 Creating BM25 retriever... +2025-09-24 14:34:46,238 - AgenticMedicalRAG - INFO - 🔄 Creating hybrid retriever... +2025-09-24 14:34:46,238 - AgenticMedicalRAG - INFO - ✅ Retrievers created and hybrid retriever is ready. +2025-09-24 14:35:02,380 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-09-24 14:35:02,459 - AgenticMedicalRAG - INFO - 🔄 Processing new data and updating vector store if needed... +2025-09-24 14:35:02,501 - AgenticMedicalRAG - INFO - 📦 Loading chunks cache for BM25 retriever... +2025-09-24 14:35:02,512 - AgenticMedicalRAG - INFO - 🔍 Creating vector retriever... +2025-09-24 14:35:02,512 - AgenticMedicalRAG - INFO - 📝 Creating BM25 retriever... +2025-09-24 14:35:02,665 - AgenticMedicalRAG - INFO - 🔄 Creating hybrid retriever... +2025-09-24 14:35:02,666 - AgenticMedicalRAG - INFO - ✅ Retrievers created and hybrid retriever is ready. +2025-09-24 15:28:04,375 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-09-24 15:28:05,020 - AgenticMedicalRAG - INFO - 🔄 Processing new data and updating vector store if needed... +2025-09-24 15:28:05,111 - AgenticMedicalRAG - INFO - 📦 Loading chunks cache for BM25 retriever... +2025-09-24 15:28:05,120 - AgenticMedicalRAG - INFO - 🔍 Creating vector retriever... +2025-09-24 15:28:05,121 - AgenticMedicalRAG - INFO - 📝 Creating BM25 retriever... +2025-09-24 15:28:05,486 - AgenticMedicalRAG - INFO - 🔄 Creating hybrid retriever... +2025-09-24 15:28:05,486 - AgenticMedicalRAG - INFO - ✅ Retrievers created and hybrid retriever is ready. +2025-09-24 15:28:05,509 - AgenticMedicalRAG - INFO - Agentic Medical Guidelines Assistant starting... +2025-09-24 15:28:05,509 - AgenticMedicalRAG - INFO - Starting Gradio interface... +2025-09-24 15:28:48,253 - AgenticMedicalRAG - INFO - Processing user input (attempt 1): What is the recommended first-line treatment for a... +2025-09-24 15:29:09,300 - AgenticMedicalRAG - INFO - Successfully processed user input: What is the recommended first-line treatment for a... +2025-09-24 15:29:31,597 - AgenticMedicalRAG - INFO - Processing user input (attempt 1): How should stage III NSCLC with EGFR mutations be ... +2025-09-24 15:29:53,586 - AgenticMedicalRAG - INFO - Successfully processed user input: How should stage III NSCLC with EGFR mutations be ... +2025-09-24 15:29:56,004 - AgenticMedicalRAG - INFO - Processing user input (attempt 1): What is the role of durvalumab in stage III NSCLC ... +2025-09-24 15:30:21,791 - AgenticMedicalRAG - INFO - Successfully processed user input: What is the role of durvalumab in stage III NSCLC ... +2025-09-24 15:37:04,732 - AgenticMedicalRAG - INFO - Processing user input (attempt 1): What are the differences in stage III NSCLC with E... +2025-09-24 15:37:07,666 - AgenticMedicalRAG - ERROR - OpenAI API error: Error code: 413 - {'error': {'code': 'tokens_limit_reached', 'message': 'Request body too large for gpt-4o model. Max size: 8000 tokens.', 'details': 'Request body too large for gpt-4o model. Max size: 8000 tokens.'}} +2025-09-24 15:37:09,667 - AgenticMedicalRAG - INFO - Processing user input (attempt 2): What are the differences in stage III NSCLC with E... +2025-09-24 15:37:12,091 - AgenticMedicalRAG - ERROR - OpenAI API error: Error code: 413 - {'error': {'code': 'tokens_limit_reached', 'message': 'Request body too large for gpt-4o model. Max size: 8000 tokens.', 'details': 'Request body too large for gpt-4o model. Max size: 8000 tokens.'}} +2025-09-24 15:37:14,092 - AgenticMedicalRAG - INFO - Processing user input (attempt 3): What are the differences in stage III NSCLC with E... +2025-09-24 15:37:16,221 - AgenticMedicalRAG - ERROR - OpenAI API error: Error code: 413 - {'error': {'code': 'tokens_limit_reached', 'message': 'Request body too large for gpt-4o model. Max size: 8000 tokens.', 'details': 'Request body too large for gpt-4o model. Max size: 8000 tokens.'}} +2025-09-24 15:37:18,221 - AgenticMedicalRAG - INFO - Processing user input (attempt 4): What are the differences in stage III NSCLC with E... +2025-09-24 15:37:20,035 - AgenticMedicalRAG - ERROR - OpenAI API error: Error code: 413 - {'error': {'code': 'tokens_limit_reached', 'message': 'Request body too large for gpt-4o model. Max size: 8000 tokens.', 'details': 'Request body too large for gpt-4o model. Max size: 8000 tokens.'}} +2025-09-25 10:55:35,848 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-09-25 10:55:36,837 - AgenticMedicalRAG - INFO - 🔄 Processing new data and updating vector store if needed... +2025-09-25 10:55:36,997 - AgenticMedicalRAG - INFO - 📦 Loading chunks cache for BM25 retriever... +2025-09-25 10:55:37,016 - AgenticMedicalRAG - INFO - 🔍 Creating vector retriever... +2025-09-25 10:55:37,018 - AgenticMedicalRAG - INFO - 📝 Creating BM25 retriever... +2025-09-25 10:55:37,679 - AgenticMedicalRAG - INFO - 🔄 Creating hybrid retriever... +2025-09-25 10:55:37,681 - AgenticMedicalRAG - INFO - ✅ Retrievers created and hybrid retriever is ready. +2025-09-25 10:55:37,758 - AgenticMedicalRAG - INFO - Agentic Medical Guidelines Assistant starting... +2025-09-25 10:55:37,758 - AgenticMedicalRAG - INFO - Starting Gradio interface... +2025-09-25 10:56:20,804 - AgenticMedicalRAG - INFO - Processing user input (attempt 1): What is the recommended first-line treatment for a... +2025-09-25 10:57:12,813 - AgenticMedicalRAG - INFO - Successfully processed user input: What is the recommended first-line treatment for a... +2025-09-25 11:03:25,974 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-09-25 11:03:26,156 - AgenticMedicalRAG - INFO - 🔄 Processing new data and updating vector store if needed... +2025-09-25 11:03:26,226 - AgenticMedicalRAG - INFO - 📦 Loading chunks cache for BM25 retriever... +2025-09-25 11:03:26,474 - AgenticMedicalRAG - INFO - 🔍 Creating vector retriever... +2025-09-25 11:03:26,475 - AgenticMedicalRAG - INFO - 📝 Creating BM25 retriever... +2025-09-25 11:03:26,718 - AgenticMedicalRAG - INFO - 🔄 Creating hybrid retriever... +2025-09-25 11:03:26,719 - AgenticMedicalRAG - INFO - ✅ Retrievers created and hybrid retriever is ready. +2025-09-25 11:44:26,455 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-09-25 11:44:26,797 - AgenticMedicalRAG - ERROR - Failed to import required modules: cannot import name 'medical_guidelines_knowledge_tool' from 'tools' (C:\Users\moaze\AppData\Roaming\Python\Python313\site-packages\tools\__init__.py) +2025-09-25 11:44:47,804 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-09-25 11:44:48,265 - AgenticMedicalRAG - INFO - 🔄 Processing new data and updating vector store if needed... +2025-09-25 11:44:48,315 - AgenticMedicalRAG - INFO - 📦 Loading chunks cache for BM25 retriever... +2025-09-25 11:44:48,327 - AgenticMedicalRAG - INFO - 🔍 Creating vector retriever... +2025-09-25 11:44:48,327 - AgenticMedicalRAG - INFO - 📝 Creating BM25 retriever... +2025-09-25 11:44:48,704 - AgenticMedicalRAG - INFO - 🔄 Creating hybrid retriever... +2025-09-25 11:44:48,704 - AgenticMedicalRAG - INFO - ✅ Retrievers created and hybrid retriever is ready. +2025-09-25 11:44:48,727 - AgenticMedicalRAG - INFO - Agentic Medical Guidelines Assistant starting... +2025-09-25 11:44:48,727 - AgenticMedicalRAG - INFO - Starting Gradio interface... +2025-09-25 11:45:23,905 - AgenticMedicalRAG - INFO - Processing user input (attempt 1): How should stage III NSCLC with EGFR mutations be ... +2025-09-25 11:46:12,625 - AgenticMedicalRAG - INFO - Successfully processed user input: How should stage III NSCLC with EGFR mutations be ... +2025-09-25 11:46:51,625 - AgenticMedicalRAG - INFO - Processing user input (attempt 1): What is the role of PD-L1 testing in the managemen... +2025-09-25 11:47:40,839 - AgenticMedicalRAG - INFO - Successfully processed user input: What is the role of PD-L1 testing in the managemen... +2025-09-25 11:55:51,664 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-09-25 11:55:52,071 - AgenticMedicalRAG - INFO - 🔄 Processing new data and updating vector store if needed... +2025-09-25 11:55:52,120 - AgenticMedicalRAG - INFO - 📦 Loading chunks cache for BM25 retriever... +2025-09-25 11:55:52,130 - AgenticMedicalRAG - INFO - 🔍 Creating vector retriever... +2025-09-25 11:55:52,130 - AgenticMedicalRAG - INFO - 📝 Creating BM25 retriever... +2025-09-25 11:55:52,515 - AgenticMedicalRAG - INFO - 🔄 Creating hybrid retriever... +2025-09-25 11:55:52,515 - AgenticMedicalRAG - INFO - ✅ Retrievers created and hybrid retriever is ready. +2025-09-25 11:55:52,533 - AgenticMedicalRAG - INFO - Agentic Medical Guidelines Assistant starting... +2025-09-25 11:55:52,534 - AgenticMedicalRAG - INFO - Starting Gradio interface... +2025-09-25 11:56:22,086 - AgenticMedicalRAG - INFO - Processing user input (attempt 1): What is the expected survival benefit of durvaluma... +2025-09-25 11:56:34,087 - AgenticMedicalRAG - INFO - Successfully processed user input: What is the expected survival benefit of durvaluma... +2025-09-25 11:57:17,093 - AgenticMedicalRAG - INFO - Processing user input (attempt 1): How should stage III NSCLC with EGFR mutations be ... +2025-09-25 11:57:29,006 - AgenticMedicalRAG - INFO - Successfully processed user input: How should stage III NSCLC with EGFR mutations be ... +2025-09-25 12:08:15,798 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-09-25 12:08:16,635 - AgenticMedicalRAG - INFO - 🔄 Processing new data and updating vector store if needed... +2025-09-25 12:08:16,708 - AgenticMedicalRAG - INFO - 📦 Loading chunks cache for BM25 retriever... +2025-09-25 12:08:16,733 - AgenticMedicalRAG - INFO - 🔍 Creating vector retriever... +2025-09-25 12:08:16,733 - AgenticMedicalRAG - INFO - 📝 Creating BM25 retriever... +2025-09-25 12:08:17,439 - AgenticMedicalRAG - INFO - 🔄 Creating hybrid retriever... +2025-09-25 12:08:17,439 - AgenticMedicalRAG - INFO - ✅ Retrievers created and hybrid retriever is ready. +2025-09-25 12:08:17,467 - AgenticMedicalRAG - INFO - Agentic Medical Guidelines Assistant starting... +2025-09-25 12:08:17,467 - AgenticMedicalRAG - INFO - Starting Gradio interface... +2025-09-25 12:09:21,041 - AgenticMedicalRAG - INFO - Processing user input (attempt 1): How should stage III NSCLC with EGFR mutations be ... +2025-09-25 12:09:34,174 - AgenticMedicalRAG - INFO - Successfully processed user input: How should stage III NSCLC with EGFR mutations be ... +2025-09-25 12:33:19,691 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-09-25 12:33:20,134 - AgenticMedicalRAG - INFO - 🔄 Processing new data and updating vector store if needed... +2025-09-25 12:33:20,177 - AgenticMedicalRAG - INFO - 📦 Loading chunks cache for BM25 retriever... +2025-09-25 12:33:20,188 - AgenticMedicalRAG - INFO - 🔍 Creating vector retriever... +2025-09-25 12:33:20,188 - AgenticMedicalRAG - INFO - 📝 Creating BM25 retriever... +2025-09-25 12:33:20,550 - AgenticMedicalRAG - INFO - 🔄 Creating hybrid retriever... +2025-09-25 12:33:20,551 - AgenticMedicalRAG - INFO - ✅ Retrievers created and hybrid retriever is ready. +2025-09-25 12:33:20,563 - AgenticMedicalRAG - INFO - Agentic Medical Guidelines Assistant starting... +2025-09-25 12:33:20,563 - AgenticMedicalRAG - INFO - Starting Gradio interface... +2025-09-25 12:38:42,020 - AgenticMedicalRAG - INFO - Processing user input (attempt 1): What is the recommended first-line treatment for a... +2025-09-25 12:38:47,424 - AgenticMedicalRAG - INFO - Successfully processed user input: What is the recommended first-line treatment for a... +2025-09-25 12:39:30,232 - AgenticMedicalRAG - INFO - Processing user input (attempt 1): How should stage III NSCLC with EGFR mutations be ... +2025-09-25 12:39:33,410 - AgenticMedicalRAG - INFO - Successfully processed user input: How should stage III NSCLC with EGFR mutations be ... +2025-09-25 12:40:25,958 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-09-25 12:40:26,441 - AgenticMedicalRAG - INFO - 🔄 Processing new data and updating vector store if needed... +2025-09-25 12:40:26,483 - AgenticMedicalRAG - INFO - 📦 Loading chunks cache for BM25 retriever... +2025-09-25 12:40:26,496 - AgenticMedicalRAG - INFO - 🔍 Creating vector retriever... +2025-09-25 12:40:26,497 - AgenticMedicalRAG - INFO - 📝 Creating BM25 retriever... +2025-09-25 12:40:26,865 - AgenticMedicalRAG - INFO - 🔄 Creating hybrid retriever... +2025-09-25 12:40:26,865 - AgenticMedicalRAG - INFO - ✅ Retrievers created and hybrid retriever is ready. +2025-09-25 12:40:26,875 - AgenticMedicalRAG - INFO - Agentic Medical Guidelines Assistant starting... +2025-09-25 12:40:26,875 - AgenticMedicalRAG - INFO - Starting Gradio interface... +2025-09-25 12:40:43,498 - AgenticMedicalRAG - INFO - Processing user input (attempt 1): What is the recommended first-line treatment for a... +2025-09-25 12:40:52,880 - AgenticMedicalRAG - INFO - Successfully processed user input: What is the recommended first-line treatment for a... +2025-09-25 13:24:01,123 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-09-25 13:24:02,325 - AgenticMedicalRAG - INFO - 🔄 Processing new data and updating vector store if needed... +2025-09-25 13:24:02,404 - AgenticMedicalRAG - INFO - 📦 Loading chunks cache for BM25 retriever... +2025-09-25 13:24:02,427 - AgenticMedicalRAG - INFO - 🔍 Creating vector retriever... +2025-09-25 13:24:02,427 - AgenticMedicalRAG - INFO - 📝 Creating BM25 retriever... +2025-09-25 13:24:03,004 - AgenticMedicalRAG - INFO - 🔄 Creating hybrid retriever... +2025-09-25 13:24:03,005 - AgenticMedicalRAG - INFO - ✅ Retrievers created and hybrid retriever is ready. +2025-09-25 13:24:03,028 - AgenticMedicalRAG - INFO - Agentic Medical Guidelines Assistant starting... +2025-09-25 13:24:03,030 - AgenticMedicalRAG - INFO - Starting Gradio interface... +2025-09-25 13:25:50,875 - AgenticMedicalRAG - INFO - Processing user input (attempt 1): What is the expected survival benefit of durvaluma... +2025-09-25 13:25:55,987 - AgenticMedicalRAG - INFO - Successfully processed user input: What is the expected survival benefit of durvaluma... +2025-09-25 13:29:32,984 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-09-25 13:29:33,427 - AgenticMedicalRAG - INFO - 🔄 Processing new data and updating vector store if needed... +2025-09-25 13:29:33,473 - AgenticMedicalRAG - INFO - 📦 Loading chunks cache for BM25 retriever... +2025-09-25 13:29:33,483 - AgenticMedicalRAG - INFO - 🔍 Creating vector retriever... +2025-09-25 13:29:33,485 - AgenticMedicalRAG - INFO - 📝 Creating BM25 retriever... +2025-09-25 13:29:33,859 - AgenticMedicalRAG - INFO - 🔄 Creating hybrid retriever... +2025-09-25 13:29:33,860 - AgenticMedicalRAG - INFO - ✅ Retrievers created and hybrid retriever is ready. +2025-09-25 13:29:33,874 - AgenticMedicalRAG - INFO - Agentic Medical Guidelines Assistant starting... +2025-09-25 13:29:33,874 - AgenticMedicalRAG - INFO - Starting Gradio interface... +2025-09-25 13:29:47,561 - AgenticMedicalRAG - INFO - Processing user input (attempt 1): What is the expected survival benefit of durvaluma... +2025-09-25 13:29:55,342 - AgenticMedicalRAG - INFO - Successfully processed user input: What is the expected survival benefit of durvaluma... +2025-09-25 14:35:48,177 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-09-25 14:35:48,992 - AgenticMedicalRAG - INFO - 🔄 Processing new data and updating vector store if needed... +2025-09-25 14:35:49,075 - AgenticMedicalRAG - INFO - 📦 Loading chunks cache for BM25 retriever... +2025-09-25 14:35:49,093 - AgenticMedicalRAG - INFO - 🔍 Creating vector retriever... +2025-09-25 14:35:49,094 - AgenticMedicalRAG - INFO - 📝 Creating BM25 retriever... +2025-09-25 14:35:49,761 - AgenticMedicalRAG - INFO - 🔄 Creating hybrid retriever... +2025-09-25 14:35:49,762 - AgenticMedicalRAG - INFO - ✅ Retrievers created and hybrid retriever is ready. +2025-09-25 14:35:49,781 - AgenticMedicalRAG - INFO - Agentic Medical Guidelines Assistant starting... +2025-09-25 14:35:49,781 - AgenticMedicalRAG - INFO - Starting Gradio interface... +2025-09-25 14:36:56,115 - AgenticMedicalRAG - INFO - Processing user input (attempt 1): What is the expected survival benefit of durvaluma... +2025-09-25 14:37:02,607 - AgenticMedicalRAG - INFO - Successfully processed user input: What is the expected survival benefit of durvaluma... +2025-09-25 14:49:27,524 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-09-25 14:49:28,493 - AgenticMedicalRAG - INFO - 🔄 Processing new data and updating vector store if needed... +2025-09-25 14:49:28,587 - AgenticMedicalRAG - INFO - 📦 Loading chunks cache for BM25 retriever... +2025-09-25 14:49:28,611 - AgenticMedicalRAG - INFO - 🔍 Creating vector retriever... +2025-09-25 14:49:28,612 - AgenticMedicalRAG - INFO - 📝 Creating BM25 retriever... +2025-09-25 14:49:29,294 - AgenticMedicalRAG - INFO - 🔄 Creating hybrid retriever... +2025-09-25 14:49:29,295 - AgenticMedicalRAG - INFO - ✅ Retrievers created and hybrid retriever is ready. +2025-09-25 14:49:29,325 - AgenticMedicalRAG - INFO - Agentic Medical Guidelines Assistant starting... +2025-09-25 14:49:29,326 - AgenticMedicalRAG - INFO - Starting Gradio interface... +2025-09-25 14:54:24,150 - AgenticMedicalRAG - INFO - Processing user input (attempt 1): What is the expected survival benefit of durvaluma... +2025-09-25 14:54:34,887 - AgenticMedicalRAG - INFO - Successfully processed user input: What is the expected survival benefit of durvaluma... +2025-09-25 19:59:01,611 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-09-25 19:59:02,224 - AgenticMedicalRAG - INFO - 🔄 Processing new data and updating vector store if needed... +2025-09-25 19:59:02,280 - AgenticMedicalRAG - INFO - 📦 Loading chunks cache for BM25 retriever... +2025-09-25 19:59:02,291 - AgenticMedicalRAG - INFO - 🔍 Creating vector retriever... +2025-09-25 19:59:02,292 - AgenticMedicalRAG - INFO - 📝 Creating BM25 retriever... +2025-09-25 19:59:02,670 - AgenticMedicalRAG - INFO - 🔄 Creating hybrid retriever... +2025-09-25 19:59:02,670 - AgenticMedicalRAG - INFO - ✅ Retrievers created and hybrid retriever is ready. +2025-09-25 19:59:02,683 - AgenticMedicalRAG - INFO - Agentic Medical Guidelines Assistant starting... +2025-09-25 19:59:02,683 - AgenticMedicalRAG - INFO - Starting Gradio interface... +2025-09-25 19:59:50,665 - AgenticMedicalRAG - INFO - Processing user input (attempt 1): What is the recommended first-line treatment for a... +2025-09-25 20:00:00,245 - AgenticMedicalRAG - INFO - Successfully processed user input: What is the recommended first-line treatment for a... +2025-09-25 20:09:12,523 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-09-25 20:09:12,977 - AgenticMedicalRAG - INFO - 🔄 Processing new data and updating vector store if needed... +2025-09-25 20:09:13,031 - AgenticMedicalRAG - INFO - 📦 Loading chunks cache for BM25 retriever... +2025-09-25 20:09:13,048 - AgenticMedicalRAG - INFO - 🔍 Creating vector retriever... +2025-09-25 20:09:13,049 - AgenticMedicalRAG - INFO - 📝 Creating BM25 retriever... +2025-09-25 20:09:13,418 - AgenticMedicalRAG - INFO - 🔄 Creating hybrid retriever... +2025-09-25 20:09:13,419 - AgenticMedicalRAG - INFO - ✅ Retrievers created and hybrid retriever is ready. +2025-09-25 20:09:13,423 - AgenticMedicalRAG - ERROR - Failed to import required modules: cannot import name 'agent_trace' from 'tracing' (D:\Work\Agentic-Medical-RAG-AI-Advisor\src\tracing.py) +2025-09-25 20:37:56,521 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-09-25 20:37:56,964 - AgenticMedicalRAG - INFO - 🔄 Processing new data and updating vector store if needed... +2025-09-25 20:37:57,017 - AgenticMedicalRAG - INFO - 📦 Loading chunks cache for BM25 retriever... +2025-09-25 20:37:57,028 - AgenticMedicalRAG - INFO - 🔍 Creating vector retriever... +2025-09-25 20:37:57,028 - AgenticMedicalRAG - INFO - 📝 Creating BM25 retriever... +2025-09-25 20:37:57,396 - AgenticMedicalRAG - INFO - 🔄 Creating hybrid retriever... +2025-09-25 20:37:57,397 - AgenticMedicalRAG - INFO - ✅ Retrievers created and hybrid retriever is ready. +2025-09-25 20:37:57,409 - AgenticMedicalRAG - INFO - Agentic Medical Guidelines Assistant starting... +2025-09-25 20:37:57,409 - AgenticMedicalRAG - INFO - Starting Gradio interface... +2025-09-25 20:38:19,731 - AgenticMedicalRAG - INFO - Processing user input (attempt 1): What is the recommended first-line treatment for a... +2025-09-25 20:38:36,017 - AgenticMedicalRAG - INFO - Successfully processed user input: What is the recommended first-line treatment for a... +2025-09-25 20:41:14,481 - AgenticMedicalRAG - INFO - Processing user input (attempt 1): How should stage III NSCLC with EGFR mutations be ... +2025-09-25 20:41:27,289 - AgenticMedicalRAG - INFO - Successfully processed user input: How should stage III NSCLC with EGFR mutations be ... +2025-09-26 17:36:44,230 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-09-26 17:36:45,307 - AgenticMedicalRAG - INFO - 🔄 Processing new data and updating vector store if needed... +2025-09-26 17:36:45,484 - AgenticMedicalRAG - INFO - 📦 Loading chunks cache for BM25 retriever... +2025-09-26 17:36:45,532 - AgenticMedicalRAG - INFO - 🔍 Creating vector retriever... +2025-09-26 17:36:45,533 - AgenticMedicalRAG - INFO - 📝 Creating BM25 retriever... +2025-09-26 17:36:46,223 - AgenticMedicalRAG - INFO - 🔄 Creating hybrid retriever... +2025-09-26 17:36:46,224 - AgenticMedicalRAG - INFO - ✅ Retrievers created and hybrid retriever is ready. +2025-09-26 17:36:46,287 - AgenticMedicalRAG - INFO - Agentic Medical Guidelines Assistant starting... +2025-09-26 17:36:46,287 - AgenticMedicalRAG - INFO - Starting Gradio interface... +2025-09-26 17:37:26,909 - AgenticMedicalRAG - INFO - Processing user input (attempt 1): What is the role of PD-L1 testing in the managemen... +2025-09-26 17:37:39,735 - AgenticMedicalRAG - INFO - Successfully processed user input: What is the role of PD-L1 testing in the managemen... +2025-09-26 18:46:50,328 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-09-26 18:46:50,959 - AgenticMedicalRAG - INFO - 🔄 Processing new data and updating vector store if needed... +2025-09-26 18:46:51,040 - AgenticMedicalRAG - INFO - 📦 Loading chunks cache for BM25 retriever... +2025-09-26 18:46:51,072 - AgenticMedicalRAG - INFO - 🔍 Creating vector retriever... +2025-09-26 18:46:51,072 - AgenticMedicalRAG - INFO - 📝 Creating BM25 retriever... +2025-09-26 18:46:51,473 - AgenticMedicalRAG - INFO - 🔄 Creating hybrid retriever... +2025-09-26 18:46:51,473 - AgenticMedicalRAG - INFO - ✅ Retrievers created and hybrid retriever is ready. +2025-09-26 18:46:51,485 - AgenticMedicalRAG - INFO - Agentic Medical Guidelines Assistant starting... +2025-09-26 18:46:51,486 - AgenticMedicalRAG - INFO - Starting Gradio interface... +2025-09-26 18:47:13,691 - AgenticMedicalRAG - INFO - Processing user input (attempt 1): answer these questions +1. What is the recommended... +2025-09-26 18:47:22,877 - AgenticMedicalRAG - ERROR - OpenAI API error: Error code: 413 - {'error': {'code': 'tokens_limit_reached', 'message': 'Request body too large for gpt-4o model. Max size: 8000 tokens.', 'details': 'Request body too large for gpt-4o model. Max size: 8000 tokens.'}} +2025-09-26 18:47:24,879 - AgenticMedicalRAG - INFO - Processing user input (attempt 2): answer these questions +1. What is the recommended... +2025-09-26 18:47:33,464 - AgenticMedicalRAG - ERROR - OpenAI API error: Error code: 413 - {'error': {'code': 'tokens_limit_reached', 'message': 'Request body too large for gpt-4o model. Max size: 8000 tokens.', 'details': 'Request body too large for gpt-4o model. Max size: 8000 tokens.'}} +2025-09-26 18:47:35,466 - AgenticMedicalRAG - INFO - Processing user input (attempt 3): answer these questions +1. What is the recommended... +2025-09-26 18:47:42,377 - AgenticMedicalRAG - ERROR - OpenAI API error: Error code: 413 - {'error': {'code': 'tokens_limit_reached', 'message': 'Request body too large for gpt-4o model. Max size: 8000 tokens.', 'details': 'Request body too large for gpt-4o model. Max size: 8000 tokens.'}} +2025-09-26 18:47:44,377 - AgenticMedicalRAG - INFO - Processing user input (attempt 4): answer these questions +1. What is the recommended... +2025-09-26 18:47:51,259 - AgenticMedicalRAG - ERROR - OpenAI API error: Error code: 413 - {'error': {'code': 'tokens_limit_reached', 'message': 'Request body too large for gpt-4o model. Max size: 8000 tokens.', 'details': 'Request body too large for gpt-4o model. Max size: 8000 tokens.'}} +2025-09-26 19:23:03,535 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-09-26 19:23:04,707 - AgenticMedicalRAG - INFO - 🔄 Processing new data and updating vector store if needed... +2025-09-26 19:23:04,800 - AgenticMedicalRAG - INFO - 📦 Loading chunks cache for BM25 retriever... +2025-09-26 19:23:04,829 - AgenticMedicalRAG - INFO - 🔍 Creating vector retriever... +2025-09-26 19:23:04,831 - AgenticMedicalRAG - INFO - 📝 Creating BM25 retriever... +2025-09-26 19:23:05,538 - AgenticMedicalRAG - INFO - 🔄 Creating hybrid retriever... +2025-09-26 19:23:05,538 - AgenticMedicalRAG - INFO - ✅ Retrievers created and hybrid retriever is ready. +2025-09-26 19:23:05,574 - AgenticMedicalRAG - INFO - Agentic Medical Guidelines Assistant starting... +2025-09-26 19:23:05,575 - AgenticMedicalRAG - INFO - Starting Gradio interface... +2025-09-26 19:23:38,484 - AgenticMedicalRAG - INFO - Processing user input (attempt 1): answer these questions +1. What is the recommended... +2025-09-26 19:23:48,753 - AgenticMedicalRAG - ERROR - OpenAI API error: Error code: 413 - {'error': {'code': 'tokens_limit_reached', 'message': 'Request body too large for gpt-4o model. Max size: 8000 tokens.', 'details': 'Request body too large for gpt-4o model. Max size: 8000 tokens.'}} +2025-09-26 19:23:50,755 - AgenticMedicalRAG - INFO - Processing user input (attempt 2): answer these questions +1. What is the recommended... +2025-09-26 19:23:59,896 - AgenticMedicalRAG - ERROR - OpenAI API error: Error code: 413 - {'error': {'code': 'tokens_limit_reached', 'message': 'Request body too large for gpt-4o model. Max size: 8000 tokens.', 'details': 'Request body too large for gpt-4o model. Max size: 8000 tokens.'}} +2025-09-26 19:24:01,899 - AgenticMedicalRAG - INFO - Processing user input (attempt 3): answer these questions +1. What is the recommended... +2025-09-26 19:24:13,219 - AgenticMedicalRAG - ERROR - OpenAI API error: Error code: 413 - {'error': {'code': 'tokens_limit_reached', 'message': 'Request body too large for gpt-4o model. Max size: 8000 tokens.', 'details': 'Request body too large for gpt-4o model. Max size: 8000 tokens.'}} +2025-09-26 19:24:15,220 - AgenticMedicalRAG - INFO - Processing user input (attempt 4): answer these questions +1. What is the recommended... +2025-09-26 19:24:25,729 - AgenticMedicalRAG - ERROR - OpenAI API error: Error code: 413 - {'error': {'code': 'tokens_limit_reached', 'message': 'Request body too large for gpt-4o model. Max size: 8000 tokens.', 'details': 'Request body too large for gpt-4o model. Max size: 8000 tokens.'}} +2025-09-26 19:46:48,701 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-09-26 19:46:49,622 - AgenticMedicalRAG - INFO - 🔄 Processing new data and updating vector store if needed... +2025-09-26 19:46:49,709 - AgenticMedicalRAG - INFO - 📦 Loading chunks cache for BM25 retriever... +2025-09-26 19:46:49,734 - AgenticMedicalRAG - INFO - 🔍 Creating vector retriever... +2025-09-26 19:46:49,735 - AgenticMedicalRAG - INFO - 📝 Creating BM25 retriever... +2025-09-26 19:46:50,398 - AgenticMedicalRAG - INFO - 🔄 Creating hybrid retriever... +2025-09-26 19:46:50,399 - AgenticMedicalRAG - INFO - ✅ Retrievers created and hybrid retriever is ready. +2025-09-26 19:46:50,432 - AgenticMedicalRAG - INFO - Agentic Medical Guidelines Assistant starting... +2025-09-26 19:46:50,433 - AgenticMedicalRAG - INFO - Starting Gradio interface... +2025-09-26 19:47:19,702 - AgenticMedicalRAG - WARNING - Input too long: 1266 characters +2025-09-26 19:47:31,877 - AgenticMedicalRAG - WARNING - Input too long: 1243 characters +2025-09-26 20:08:25,379 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-09-26 20:08:26,332 - AgenticMedicalRAG - INFO - 🔄 Processing new data and updating vector store if needed... +2025-09-26 20:08:26,681 - AgenticMedicalRAG - INFO - 📦 Loading chunks cache for BM25 retriever... +2025-09-26 20:08:26,708 - AgenticMedicalRAG - INFO - 🔍 Creating vector retriever... +2025-09-26 20:08:26,708 - AgenticMedicalRAG - INFO - 📝 Creating BM25 retriever... +2025-09-26 20:08:27,591 - AgenticMedicalRAG - INFO - 🔄 Creating hybrid retriever... +2025-09-26 20:08:27,591 - AgenticMedicalRAG - INFO - ✅ Retrievers created and hybrid retriever is ready. +2025-09-26 20:08:27,623 - AgenticMedicalRAG - INFO - Agentic Medical Guidelines Assistant starting... +2025-09-26 20:08:27,623 - AgenticMedicalRAG - INFO - Starting Gradio interface... +2025-09-26 20:08:32,951 - AgenticMedicalRAG - ERROR - Failed to launch Gradio: Cannot find empty port in range: 7860-7860. You can specify a different port by setting the GRADIO_SERVER_PORT environment variable or passing the `server_port` parameter to `launch()`. +2025-09-26 20:09:39,723 - AgenticMedicalRAG - ERROR - Failed to load embedding model: (MaxRetryError('HTTPSConnectionPool(host=\'huggingface.co\', port=443): Max retries exceeded with url: /api/models/abhinand/MedEmbed-base-v0.1/tree/main/additional_chat_templates?recursive=False&expand=False (Caused by NameResolutionError(": Failed to resolve \'huggingface.co\' ([Errno 11004] getaddrinfo failed)"))'), '(Request ID: 9208b60a-cd11-44be-9664-7c39920579a3)') +2025-09-26 20:11:04,608 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-09-26 20:11:05,539 - AgenticMedicalRAG - INFO - 🔄 Processing new data and updating vector store if needed... +2025-09-26 20:11:05,636 - AgenticMedicalRAG - INFO - 📦 Loading chunks cache for BM25 retriever... +2025-09-26 20:11:05,660 - AgenticMedicalRAG - INFO - 🔍 Creating vector retriever... +2025-09-26 20:11:05,661 - AgenticMedicalRAG - INFO - 📝 Creating BM25 retriever... +2025-09-26 20:11:06,558 - AgenticMedicalRAG - INFO - 🔄 Creating hybrid retriever... +2025-09-26 20:11:06,558 - AgenticMedicalRAG - INFO - ✅ Retrievers created and hybrid retriever is ready. +2025-09-26 20:11:06,589 - AgenticMedicalRAG - INFO - Agentic Medical Guidelines Assistant starting... +2025-09-26 20:11:06,590 - AgenticMedicalRAG - INFO - Starting Gradio interface... +2025-09-26 23:45:11,863 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-09-26 23:45:12,691 - AgenticMedicalRAG - INFO - 🔄 Processing new data and updating vector store if needed... +2025-09-26 23:45:12,820 - AgenticMedicalRAG - INFO - 📦 Loading chunks cache for BM25 retriever... +2025-09-26 23:45:12,854 - AgenticMedicalRAG - INFO - 🔍 Creating vector retriever... +2025-09-26 23:45:12,854 - AgenticMedicalRAG - INFO - 📝 Creating BM25 retriever... +2025-09-26 23:45:13,282 - AgenticMedicalRAG - INFO - 🔄 Creating hybrid retriever... +2025-09-26 23:45:13,282 - AgenticMedicalRAG - INFO - ✅ Retrievers created and hybrid retriever is ready. +2025-09-26 23:45:13,301 - AgenticMedicalRAG - INFO - Agentic Medical Guidelines Assistant starting... +2025-09-26 23:45:13,301 - AgenticMedicalRAG - INFO - Starting Gradio interface... +2025-09-26 23:45:45,554 - AgenticMedicalRAG - INFO - Processing user input (attempt 1): answer these questions +1. What is the recommended... +2025-09-26 23:46:00,742 - AgenticMedicalRAG - ERROR - OpenAI API error: Error code: 413 - {'error': {'code': 'tokens_limit_reached', 'message': 'Request body too large for gpt-4o model. Max size: 8000 tokens.', 'details': 'Request body too large for gpt-4o model. Max size: 8000 tokens.'}} +2025-09-26 23:46:02,742 - AgenticMedicalRAG - INFO - Processing user input (attempt 2): answer these questions +1. What is the recommended... +2025-09-26 23:46:12,045 - AgenticMedicalRAG - ERROR - OpenAI API error: Error code: 413 - {'error': {'code': 'tokens_limit_reached', 'message': 'Request body too large for gpt-4o model. Max size: 8000 tokens.', 'details': 'Request body too large for gpt-4o model. Max size: 8000 tokens.'}} +2025-09-26 23:46:14,047 - AgenticMedicalRAG - INFO - Processing user input (attempt 3): answer these questions +1. What is the recommended... +2025-09-26 23:46:21,991 - AgenticMedicalRAG - ERROR - OpenAI API error: Error code: 413 - {'error': {'code': 'tokens_limit_reached', 'message': 'Request body too large for gpt-4o model. Max size: 8000 tokens.', 'details': 'Request body too large for gpt-4o model. Max size: 8000 tokens.'}} +2025-09-26 23:46:23,993 - AgenticMedicalRAG - INFO - Processing user input (attempt 4): answer these questions +1. What is the recommended... +2025-09-26 23:46:30,101 - AgenticMedicalRAG - ERROR - Unexpected error in run_agent_streaming: cannot schedule new futures after interpreter shutdown +2025-09-26 23:46:30,103 - AgenticMedicalRAG - ERROR - Traceback: Traceback (most recent call last): + File "D:\Work\Agentic-Medical-RAG-AI-Advisor\src\agent.py", line 248, in run_agent_streaming + response = await task + ^^^^^^^^^^ + File "C:\Users\moaze\miniconda3\envs\medical-rag-app\Lib\concurrent\futures\thread.py", line 58, in run + result = self.fn(*self.args, **self.kwargs) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "D:\Work\Agentic-Medical-RAG-AI-Advisor\src\agent.py", line 218, in run_sync + return agent_executor.invoke( + ^^^^^^^^^^^^^^^^^^^^^^ + File "C:\Users\moaze\miniconda3\envs\medical-rag-app\Lib\site-packages\langchain\chains\base.py", line 165, in invoke + self._call(inputs, run_manager=run_manager) + File "C:\Users\moaze\miniconda3\envs\medical-rag-app\Lib\site-packages\langchain\agents\agent.py", line 1625, in _call + next_step_output = self._take_next_step( + ^^^^^^^^^^^^^^^^^^^^^ + File "C:\Users\moaze\miniconda3\envs\medical-rag-app\Lib\site-packages\langchain\agents\agent.py", line 1325, in _take_next_step + list( + File "C:\Users\moaze\miniconda3\envs\medical-rag-app\Lib\site-packages\langchain\agents\agent.py", line 1352, in _iter_next_step + output = self._action_agent.plan( + ^^^^^^^^^^^^^^^^^^^^^^^^ + File "C:\Users\moaze\miniconda3\envs\medical-rag-app\Lib\site-packages\langchain\agents\agent.py", line 573, in plan + for chunk in self.runnable.stream(inputs, config={"callbacks": callbacks}): + File "C:\Users\moaze\miniconda3\envs\medical-rag-app\Lib\site-packages\langchain_core\runnables\base.py", line 3437, in stream + yield from self.transform(iter([input]), config, **kwargs) + File "C:\Users\moaze\miniconda3\envs\medical-rag-app\Lib\site-packages\langchain_core\runnables\base.py", line 3423, in transform + yield from self._transform_stream_with_config( + File "C:\Users\moaze\miniconda3\envs\medical-rag-app\Lib\site-packages\langchain_core\runnables\base.py", line 2214, in _transform_stream_with_config + chunk: Output = context.run(next, iterator) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "C:\Users\moaze\miniconda3\envs\medical-rag-app\Lib\site-packages\langchain_core\runnables\base.py", line 3385, in _transform + yield from final_pipeline + File "C:\Users\moaze\miniconda3\envs\medical-rag-app\Lib\site-packages\langchain_core\runnables\base.py", line 1428, in transform + for ichunk in input: + File "C:\Users\moaze\miniconda3\envs\medical-rag-app\Lib\site-packages\langchain_core\runnables\base.py", line 5650, in transform + yield from self.bound.transform( + File "C:\Users\moaze\miniconda3\envs\medical-rag-app\Lib\site-packages\langchain_core\runnables\base.py", line 1428, in transform + for ichunk in input: + File "C:\Users\moaze\miniconda3\envs\medical-rag-app\Lib\site-packages\langchain_core\runnables\base.py", line 1428, in transform + for ichunk in input: + File "C:\Users\moaze\miniconda3\envs\medical-rag-app\Lib\site-packages\langchain_core\runnables\passthrough.py", line 595, in transform + yield from self._transform_stream_with_config( + File "C:\Users\moaze\miniconda3\envs\medical-rag-app\Lib\site-packages\langchain_core\runnables\base.py", line 2214, in _transform_stream_with_config + chunk: Output = context.run(next, iterator) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "C:\Users\moaze\miniconda3\envs\medical-rag-app\Lib\site-packages\langchain_core\runnables\passthrough.py", line 567, in _transform + first_map_chunk_future = executor.submit( + ^^^^^^^^^^^^^^^^ + File "C:\Users\moaze\miniconda3\envs\medical-rag-app\Lib\site-packages\langchain_core\runnables\config.py", line 530, in submit + return super().submit( + ^^^^^^^^^^^^^^^ + File "C:\Users\moaze\miniconda3\envs\medical-rag-app\Lib\concurrent\futures\thread.py", line 169, in submit + raise RuntimeError('cannot schedule new futures after ' +RuntimeError: cannot schedule new futures after interpreter shutdown + +2025-09-26 23:48:08,562 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-09-26 23:48:09,457 - AgenticMedicalRAG - INFO - 🔄 Processing new data and updating vector store if needed... +2025-09-26 23:48:09,539 - AgenticMedicalRAG - INFO - 📦 Loading chunks cache for BM25 retriever... +2025-09-26 23:48:09,565 - AgenticMedicalRAG - INFO - 🔍 Creating vector retriever... +2025-09-26 23:48:09,566 - AgenticMedicalRAG - INFO - 📝 Creating BM25 retriever... +2025-09-26 23:48:10,135 - AgenticMedicalRAG - INFO - 🔄 Creating hybrid retriever... +2025-09-26 23:48:10,135 - AgenticMedicalRAG - INFO - ✅ Retrievers created and hybrid retriever is ready. +2025-09-26 23:48:10,162 - AgenticMedicalRAG - INFO - Agentic Medical Guidelines Assistant starting... +2025-09-26 23:48:10,163 - AgenticMedicalRAG - INFO - Starting Gradio interface... +2025-09-26 23:48:39,130 - AgenticMedicalRAG - INFO - Processing user input (attempt 1): What is the recommended first-line treatment for a... +2025-09-26 23:48:42,516 - AgenticMedicalRAG - ERROR - OpenAI API error: Error code: 413 - {'error': {'code': 'tokens_limit_reached', 'message': 'Request body too large for gpt-4o model. Max size: 8000 tokens.', 'details': 'Request body too large for gpt-4o model. Max size: 8000 tokens.'}} +2025-09-26 23:48:44,516 - AgenticMedicalRAG - INFO - Processing user input (attempt 2): What is the recommended first-line treatment for a... +2025-09-26 23:48:45,810 - AgenticMedicalRAG - ERROR - OpenAI API error: Error code: 413 - {'error': {'code': 'tokens_limit_reached', 'message': 'Request body too large for gpt-4o model. Max size: 8000 tokens.', 'details': 'Request body too large for gpt-4o model. Max size: 8000 tokens.'}} +2025-09-26 23:48:47,812 - AgenticMedicalRAG - INFO - Processing user input (attempt 3): What is the recommended first-line treatment for a... +2025-09-26 23:48:49,816 - AgenticMedicalRAG - ERROR - OpenAI API error: Error code: 413 - {'error': {'code': 'tokens_limit_reached', 'message': 'Request body too large for gpt-4o model. Max size: 8000 tokens.', 'details': 'Request body too large for gpt-4o model. Max size: 8000 tokens.'}} +2025-09-26 23:48:51,818 - AgenticMedicalRAG - INFO - Processing user input (attempt 4): What is the recommended first-line treatment for a... +2025-09-26 23:48:53,109 - AgenticMedicalRAG - ERROR - OpenAI API error: Error code: 413 - {'error': {'code': 'tokens_limit_reached', 'message': 'Request body too large for gpt-4o model. Max size: 8000 tokens.', 'details': 'Request body too large for gpt-4o model. Max size: 8000 tokens.'}} +2025-09-27 00:01:32,753 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-09-27 00:01:33,165 - AgenticMedicalRAG - INFO - 🔄 Processing new data and updating vector store if needed... +2025-09-27 00:01:33,216 - AgenticMedicalRAG - INFO - 📦 Loading chunks cache for BM25 retriever... +2025-09-27 00:01:33,227 - AgenticMedicalRAG - INFO - 🔍 Creating vector retriever... +2025-09-27 00:01:33,227 - AgenticMedicalRAG - INFO - 📝 Creating BM25 retriever... +2025-09-27 00:01:33,595 - AgenticMedicalRAG - INFO - 🔄 Creating hybrid retriever... +2025-09-27 00:01:33,595 - AgenticMedicalRAG - INFO - ✅ Retrievers created and hybrid retriever is ready. +2025-09-27 00:01:33,607 - AgenticMedicalRAG - INFO - Agentic Medical Guidelines Assistant starting... +2025-09-27 00:01:33,607 - AgenticMedicalRAG - INFO - Starting Gradio interface... +2025-09-27 00:01:52,894 - AgenticMedicalRAG - INFO - Processing user input (attempt 1): What is the recommended first-line treatment for a... +2025-09-27 00:01:55,464 - AgenticMedicalRAG - WARNING - Retrieved documents have 13021 tokens, but only 6000 tokens available. Truncating... +2025-09-27 00:01:55,477 - AgenticMedicalRAG - INFO - Documents truncated from 13021 to 6293 tokens +2025-09-27 00:02:04,998 - AgenticMedicalRAG - INFO - Successfully processed user input: What is the recommended first-line treatment for a... +2025-09-27 00:03:49,314 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-09-27 00:03:49,725 - AgenticMedicalRAG - INFO - 🔄 Processing new data and updating vector store if needed... +2025-09-27 00:03:49,776 - AgenticMedicalRAG - INFO - 📦 Loading chunks cache for BM25 retriever... +2025-09-27 00:03:49,787 - AgenticMedicalRAG - INFO - 🔍 Creating vector retriever... +2025-09-27 00:03:49,788 - AgenticMedicalRAG - INFO - 📝 Creating BM25 retriever... +2025-09-27 00:03:50,155 - AgenticMedicalRAG - INFO - 🔄 Creating hybrid retriever... +2025-09-27 00:03:50,155 - AgenticMedicalRAG - INFO - ✅ Retrievers created and hybrid retriever is ready. +2025-09-27 00:03:50,170 - AgenticMedicalRAG - INFO - Agentic Medical Guidelines Assistant starting... +2025-09-27 00:03:50,170 - AgenticMedicalRAG - INFO - Starting Gradio interface... +2025-09-27 00:04:10,850 - AgenticMedicalRAG - INFO - Processing user input (attempt 1): What is the recommended first-line treatment for a... +2025-09-27 00:04:13,041 - AgenticMedicalRAG - WARNING - Retrieved documents have 19470 tokens, but only 6000 tokens available. Truncating... +2025-09-27 00:04:13,056 - AgenticMedicalRAG - INFO - Documents truncated from 19470 to 6293 tokens +2025-09-27 00:04:17,388 - AgenticMedicalRAG - INFO - Successfully processed user input: What is the recommended first-line treatment for a... +2025-09-27 00:07:18,132 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-09-27 00:07:18,894 - AgenticMedicalRAG - INFO - 🔄 Processing new data and updating vector store if needed... +2025-09-27 00:07:18,966 - AgenticMedicalRAG - INFO - 📦 Loading chunks cache for BM25 retriever... +2025-09-27 00:07:18,989 - AgenticMedicalRAG - INFO - 🔍 Creating vector retriever... +2025-09-27 00:07:18,989 - AgenticMedicalRAG - INFO - 📝 Creating BM25 retriever... +2025-09-27 00:07:19,549 - AgenticMedicalRAG - INFO - 🔄 Creating hybrid retriever... +2025-09-27 00:07:19,549 - AgenticMedicalRAG - INFO - ✅ Retrievers created and hybrid retriever is ready. +2025-09-27 00:07:19,574 - AgenticMedicalRAG - INFO - Agentic Medical Guidelines Assistant starting... +2025-09-27 00:07:19,574 - AgenticMedicalRAG - INFO - Starting Gradio interface... +2025-09-27 00:07:53,864 - AgenticMedicalRAG - WARNING - Input extremely long: 86731 characters +2025-09-27 00:09:10,694 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-09-27 00:09:11,089 - AgenticMedicalRAG - INFO - 🔄 Processing new data and updating vector store if needed... +2025-09-27 00:09:11,134 - AgenticMedicalRAG - INFO - 📦 Loading chunks cache for BM25 retriever... +2025-09-27 00:09:11,144 - AgenticMedicalRAG - INFO - 🔍 Creating vector retriever... +2025-09-27 00:09:11,144 - AgenticMedicalRAG - INFO - 📝 Creating BM25 retriever... +2025-09-27 00:09:11,495 - AgenticMedicalRAG - INFO - 🔄 Creating hybrid retriever... +2025-09-27 00:09:11,496 - AgenticMedicalRAG - INFO - ✅ Retrievers created and hybrid retriever is ready. +2025-09-27 00:09:11,507 - AgenticMedicalRAG - INFO - Agentic Medical Guidelines Assistant starting... +2025-09-27 00:09:11,507 - AgenticMedicalRAG - INFO - Starting Gradio interface... +2025-09-27 00:09:41,575 - AgenticMedicalRAG - WARNING - Input text has 13096 tokens, exceeding limit of 12000. Truncating to prevent API errors. +2025-09-27 00:09:41,580 - AgenticMedicalRAG - WARNING - Input text has 13096 tokens, exceeding limit of 12000. Truncating text... +2025-09-27 00:09:41,584 - AgenticMedicalRAG - INFO - Text truncated from 13096 to 12000 tokens +2025-09-27 00:09:41,585 - AgenticMedicalRAG - INFO - Processing user input (attempt 1): What is the recommended first-line treatment for a... +2025-09-27 00:09:43,557 - AgenticMedicalRAG - ERROR - OpenAI API error: Error code: 413 - {'error': {'code': 'tokens_limit_reached', 'message': 'Request body too large for gpt-4o model. Max size: 8000 tokens.', 'details': 'Request body too large for gpt-4o model. Max size: 8000 tokens.'}} +2025-09-27 00:09:45,557 - AgenticMedicalRAG - INFO - Processing user input (attempt 2): What is the recommended first-line treatment for a... +2025-09-27 00:09:46,184 - AgenticMedicalRAG - ERROR - OpenAI API error: Error code: 413 - {'error': {'code': 'tokens_limit_reached', 'message': 'Request body too large for gpt-4o model. Max size: 8000 tokens.', 'details': 'Request body too large for gpt-4o model. Max size: 8000 tokens.'}} +2025-09-27 00:09:48,185 - AgenticMedicalRAG - INFO - Processing user input (attempt 3): What is the recommended first-line treatment for a... +2025-09-27 00:09:48,489 - AgenticMedicalRAG - ERROR - OpenAI API error: Error code: 413 - {'error': {'code': 'tokens_limit_reached', 'message': 'Request body too large for gpt-4o model. Max size: 8000 tokens.', 'details': 'Request body too large for gpt-4o model. Max size: 8000 tokens.'}} +2025-09-27 00:09:50,490 - AgenticMedicalRAG - INFO - Processing user input (attempt 4): What is the recommended first-line treatment for a... +2025-09-27 00:09:50,881 - AgenticMedicalRAG - ERROR - OpenAI API error: Error code: 413 - {'error': {'code': 'tokens_limit_reached', 'message': 'Request body too large for gpt-4o model. Max size: 8000 tokens.', 'details': 'Request body too large for gpt-4o model. Max size: 8000 tokens.'}} +2025-09-27 00:17:44,632 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-09-27 00:17:44,978 - AgenticMedicalRAG - INFO - 🔄 Processing new data and updating vector store if needed... +2025-09-27 00:17:45,020 - AgenticMedicalRAG - INFO - 📦 Loading chunks cache for BM25 retriever... +2025-09-27 00:17:45,030 - AgenticMedicalRAG - INFO - 🔍 Creating vector retriever... +2025-09-27 00:17:45,032 - AgenticMedicalRAG - INFO - 📝 Creating BM25 retriever... +2025-09-27 00:17:45,209 - AgenticMedicalRAG - INFO - 🔄 Creating hybrid retriever... +2025-09-27 00:17:45,209 - AgenticMedicalRAG - INFO - ✅ Retrievers created and hybrid retriever is ready. +2025-09-27 00:18:01,192 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-09-27 00:18:01,645 - AgenticMedicalRAG - INFO - 🔄 Processing new data and updating vector store if needed... +2025-09-27 00:18:01,716 - AgenticMedicalRAG - INFO - 📦 Loading chunks cache for BM25 retriever... +2025-09-27 00:18:01,739 - AgenticMedicalRAG - INFO - 🔍 Creating vector retriever... +2025-09-27 00:18:01,739 - AgenticMedicalRAG - INFO - 📝 Creating BM25 retriever... +2025-09-27 00:18:02,034 - AgenticMedicalRAG - INFO - 🔄 Creating hybrid retriever... +2025-09-27 00:18:02,034 - AgenticMedicalRAG - INFO - ✅ Retrievers created and hybrid retriever is ready. +2025-09-27 00:22:06,925 - AgenticMedicalRAG - INFO - Processing user input (attempt 1): What is the recommended first-line treatment for a... +2025-09-27 00:22:16,366 - AgenticMedicalRAG - INFO - Successfully processed user input: What is the recommended first-line treatment for a... +2025-09-28 10:55:59,427 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-09-28 10:55:59,969 - AgenticMedicalRAG - INFO - 🔄 Processing new data and updating vector store if needed... +2025-09-28 10:56:00,109 - AgenticMedicalRAG - INFO - 📦 Loading chunks cache for BM25 retriever... +2025-09-28 10:56:00,135 - AgenticMedicalRAG - INFO - 🔍 Creating vector retriever... +2025-09-28 10:56:00,137 - AgenticMedicalRAG - INFO - 📝 Creating BM25 retriever... +2025-09-28 10:56:00,366 - AgenticMedicalRAG - INFO - 🔄 Creating hybrid retriever... +2025-09-28 10:56:00,366 - AgenticMedicalRAG - INFO - ✅ Retrievers created and hybrid retriever is ready. +2025-09-28 10:56:14,325 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-09-28 10:56:14,690 - AgenticMedicalRAG - INFO - 🔄 Processing new data and updating vector store if needed... +2025-09-28 10:56:14,752 - AgenticMedicalRAG - INFO - 📦 Loading chunks cache for BM25 retriever... +2025-09-28 10:56:14,769 - AgenticMedicalRAG - INFO - 🔍 Creating vector retriever... +2025-09-28 10:56:14,770 - AgenticMedicalRAG - INFO - 📝 Creating BM25 retriever... +2025-09-28 10:56:15,038 - AgenticMedicalRAG - INFO - 🔄 Creating hybrid retriever... +2025-09-28 10:56:15,039 - AgenticMedicalRAG - INFO - ✅ Retrievers created and hybrid retriever is ready. +2025-09-28 10:56:46,615 - AgenticMedicalRAG - INFO - Processing user input (attempt 1): What is the recommended first-line treatment for a... +2025-09-28 10:56:54,928 - AgenticMedicalRAG - INFO - Successfully processed user input: What is the recommended first-line treatment for a... +2025-09-28 10:57:42,486 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-09-28 10:57:43,088 - AgenticMedicalRAG - INFO - 🔄 Processing new data and updating vector store if needed... +2025-09-28 10:57:43,167 - AgenticMedicalRAG - INFO - 📦 Loading chunks cache for BM25 retriever... +2025-09-28 10:57:43,184 - AgenticMedicalRAG - INFO - 🔍 Creating vector retriever... +2025-09-28 10:57:43,184 - AgenticMedicalRAG - INFO - 📝 Creating BM25 retriever... +2025-09-28 10:57:43,466 - AgenticMedicalRAG - INFO - 🔄 Creating hybrid retriever... +2025-09-28 10:57:43,468 - AgenticMedicalRAG - INFO - ✅ Retrievers created and hybrid retriever is ready. +2025-09-28 10:57:58,824 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-09-28 10:57:59,636 - AgenticMedicalRAG - INFO - 🔄 Processing new data and updating vector store if needed... +2025-09-28 10:57:59,733 - AgenticMedicalRAG - INFO - 📦 Loading chunks cache for BM25 retriever... +2025-09-28 10:57:59,759 - AgenticMedicalRAG - INFO - 🔍 Creating vector retriever... +2025-09-28 10:57:59,761 - AgenticMedicalRAG - INFO - 📝 Creating BM25 retriever... +2025-09-28 10:58:00,196 - AgenticMedicalRAG - INFO - 🔄 Creating hybrid retriever... +2025-09-28 10:58:00,198 - AgenticMedicalRAG - INFO - ✅ Retrievers created and hybrid retriever is ready. +2025-09-28 10:58:07,507 - AgenticMedicalRAG - INFO - Processing user input (attempt 1): What is the role of durvalumab in stage III NSCLC ... +2025-09-28 10:58:14,490 - AgenticMedicalRAG - INFO - Successfully processed user input: What is the role of durvalumab in stage III NSCLC ... +2025-09-28 11:06:51,149 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-09-28 11:06:52,034 - AgenticMedicalRAG - INFO - 🔄 Processing new data and updating vector store if needed... +2025-09-28 11:06:52,098 - AgenticMedicalRAG - INFO - 📦 Loading chunks cache for BM25 retriever... +2025-09-28 11:06:52,115 - AgenticMedicalRAG - INFO - 🔍 Creating vector retriever... +2025-09-28 11:06:52,116 - AgenticMedicalRAG - INFO - 📝 Creating BM25 retriever... +2025-09-28 11:06:52,686 - AgenticMedicalRAG - INFO - 🔄 Creating hybrid retriever... +2025-09-28 11:06:52,688 - AgenticMedicalRAG - INFO - ✅ Retrievers created and hybrid retriever is ready. +2025-09-28 11:06:52,707 - AgenticMedicalRAG - INFO - Agentic Medical Guidelines Assistant starting... +2025-09-28 11:06:52,707 - AgenticMedicalRAG - INFO - Starting Gradio interface... +2025-09-28 11:07:38,791 - AgenticMedicalRAG - WARNING - Input too long: 1267 characters +2025-09-28 11:08:37,379 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-09-28 11:08:37,605 - AgenticMedicalRAG - INFO - 🔄 Processing new data and updating vector store if needed... +2025-09-28 11:08:37,964 - AgenticMedicalRAG - INFO - 📦 Loading chunks cache for BM25 retriever... +2025-09-28 11:08:37,991 - AgenticMedicalRAG - INFO - 🔍 Creating vector retriever... +2025-09-28 11:08:37,992 - AgenticMedicalRAG - INFO - 📝 Creating BM25 retriever... +2025-09-28 11:08:38,319 - AgenticMedicalRAG - INFO - 🔄 Creating hybrid retriever... +2025-09-28 11:08:38,319 - AgenticMedicalRAG - INFO - ✅ Retrievers created and hybrid retriever is ready. +2025-09-28 11:10:48,552 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-09-28 11:10:49,497 - AgenticMedicalRAG - INFO - 🔄 Processing new data and updating vector store if needed... +2025-09-28 11:10:49,572 - AgenticMedicalRAG - INFO - 📦 Loading chunks cache for BM25 retriever... +2025-09-28 11:10:49,593 - AgenticMedicalRAG - INFO - 🔍 Creating vector retriever... +2025-09-28 11:10:49,594 - AgenticMedicalRAG - INFO - 📝 Creating BM25 retriever... +2025-09-28 11:10:50,233 - AgenticMedicalRAG - INFO - 🔄 Creating hybrid retriever... +2025-09-28 11:10:50,233 - AgenticMedicalRAG - INFO - ✅ Retrievers created and hybrid retriever is ready. +2025-09-28 11:10:50,263 - AgenticMedicalRAG - INFO - Agentic Medical Guidelines Assistant starting... +2025-09-28 11:10:50,264 - AgenticMedicalRAG - INFO - Starting Gradio interface... +2025-09-28 11:11:02,173 - AgenticMedicalRAG - INFO - Processing user input (attempt 1): answer these questions +1. What is the recommended ... +2025-09-28 11:11:12,208 - AgenticMedicalRAG - ERROR - OpenAI API error: Error code: 413 - {'error': {'code': 'tokens_limit_reached', 'message': 'Request body too large for gpt-4o model. Max size: 8000 tokens.', 'details': 'Request body too large for gpt-4o model. Max size: 8000 tokens.'}} +2025-09-28 11:11:14,210 - AgenticMedicalRAG - INFO - Processing user input (attempt 2): answer these questions +1. What is the recommended ... +2025-09-28 11:11:23,285 - AgenticMedicalRAG - ERROR - OpenAI API error: Error code: 413 - {'error': {'code': 'tokens_limit_reached', 'message': 'Request body too large for gpt-4o model. Max size: 8000 tokens.', 'details': 'Request body too large for gpt-4o model. Max size: 8000 tokens.'}} +2025-09-28 11:11:25,285 - AgenticMedicalRAG - INFO - Processing user input (attempt 3): answer these questions +1. What is the recommended ... +2025-09-28 11:11:34,516 - AgenticMedicalRAG - ERROR - OpenAI API error: Error code: 413 - {'error': {'code': 'tokens_limit_reached', 'message': 'Request body too large for gpt-4o model. Max size: 8000 tokens.', 'details': 'Request body too large for gpt-4o model. Max size: 8000 tokens.'}} +2025-09-28 11:11:36,518 - AgenticMedicalRAG - INFO - Processing user input (attempt 4): answer these questions +1. What is the recommended ... +2025-09-28 11:11:44,732 - AgenticMedicalRAG - ERROR - OpenAI API error: Error code: 413 - {'error': {'code': 'tokens_limit_reached', 'message': 'Request body too large for gpt-4o model. Max size: 8000 tokens.', 'details': 'Request body too large for gpt-4o model. Max size: 8000 tokens.'}} +2025-09-28 11:21:12,827 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-09-28 11:21:13,831 - AgenticMedicalRAG - INFO - 🔄 Processing new data and updating vector store if needed... +2025-09-28 11:21:13,916 - AgenticMedicalRAG - INFO - 📦 Loading chunks cache for BM25 retriever... +2025-09-28 11:21:13,940 - AgenticMedicalRAG - INFO - 🔍 Creating vector retriever... +2025-09-28 11:21:13,941 - AgenticMedicalRAG - INFO - 📝 Creating BM25 retriever... +2025-09-28 11:21:14,618 - AgenticMedicalRAG - INFO - 🔄 Creating hybrid retriever... +2025-09-28 11:21:14,618 - AgenticMedicalRAG - INFO - ✅ Retrievers created and hybrid retriever is ready. +2025-09-28 11:21:14,651 - AgenticMedicalRAG - INFO - Agentic Medical Guidelines Assistant starting... +2025-09-28 11:21:14,652 - AgenticMedicalRAG - INFO - Starting Gradio interface... +2025-09-28 11:21:39,461 - AgenticMedicalRAG - INFO - Processing user input (attempt 1): answer these questions +1. What is the recommended ... +2025-09-28 11:22:25,243 - AgenticMedicalRAG - INFO - Successfully processed user input: answer these questions +1. What is the recommended ... +2025-09-28 11:29:37,083 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-09-28 11:29:37,879 - AgenticMedicalRAG - INFO - 🔄 Processing new data and updating vector store if needed... +2025-09-28 11:29:37,951 - AgenticMedicalRAG - INFO - 📦 Loading chunks cache for BM25 retriever... +2025-09-28 11:29:37,973 - AgenticMedicalRAG - INFO - 🔍 Creating vector retriever... +2025-09-28 11:29:37,974 - AgenticMedicalRAG - INFO - 📝 Creating BM25 retriever... +2025-09-28 11:29:38,532 - AgenticMedicalRAG - INFO - 🔄 Creating hybrid retriever... +2025-09-28 11:29:38,533 - AgenticMedicalRAG - INFO - ✅ Retrievers created and hybrid retriever is ready. +2025-09-28 11:29:38,559 - AgenticMedicalRAG - INFO - Agentic Medical Guidelines Assistant starting... +2025-09-28 11:29:38,561 - AgenticMedicalRAG - INFO - Starting Gradio interface... +2025-09-28 11:30:11,706 - AgenticMedicalRAG - INFO - Processing user input (attempt 1): What is the recommended first-line treatment for a... +2025-09-28 11:30:25,318 - AgenticMedicalRAG - INFO - Successfully processed user input: What is the recommended first-line treatment for a... +2025-09-28 15:21:23,670 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-09-28 15:21:24,225 - AgenticMedicalRAG - INFO - 🔄 Processing new data and updating vector store if needed... +2025-09-28 15:21:24,272 - AgenticMedicalRAG - INFO - 📦 Loading chunks cache for BM25 retriever... +2025-09-28 15:21:24,286 - AgenticMedicalRAG - INFO - 🔍 Creating vector retriever... +2025-09-28 15:21:24,286 - AgenticMedicalRAG - INFO - 📝 Creating BM25 retriever... +2025-09-28 15:21:24,639 - AgenticMedicalRAG - INFO - 🔄 Creating hybrid retriever... +2025-09-28 15:21:24,640 - AgenticMedicalRAG - INFO - ✅ Retrievers created and hybrid retriever is ready. +2025-09-28 15:21:24,644 - AgenticMedicalRAG - ERROR - Failed to import required modules: cannot import name 'side_effect_recording_tool' from 'tools' (D:\Work\Agentic-Medical-RAG-AI-Advisor-GitHub\src\tools.py) +2025-09-28 17:08:24,750 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-09-28 17:08:25,619 - AgenticMedicalRAG - INFO - 🔄 Processing new data and updating vector store if needed... +2025-09-28 17:08:25,713 - AgenticMedicalRAG - INFO - 📦 Loading chunks cache for BM25 retriever... +2025-09-28 17:08:25,731 - AgenticMedicalRAG - INFO - 🔍 Creating vector retriever... +2025-09-28 17:08:25,732 - AgenticMedicalRAG - INFO - 📝 Creating BM25 retriever... +2025-09-28 17:08:26,522 - AgenticMedicalRAG - INFO - 🔄 Creating hybrid retriever... +2025-09-28 17:08:26,522 - AgenticMedicalRAG - INFO - ✅ Retrievers created and hybrid retriever is ready. +2025-09-28 17:08:26,586 - AgenticMedicalRAG - INFO - Agentic Medical Guidelines Assistant starting... +2025-09-28 17:08:26,586 - AgenticMedicalRAG - INFO - Starting Gradio interface... +2025-09-28 17:10:42,577 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-09-28 17:10:43,221 - AgenticMedicalRAG - INFO - 🔄 Processing new data and updating vector store if needed... +2025-09-28 17:10:43,284 - AgenticMedicalRAG - INFO - 📦 Loading chunks cache for BM25 retriever... +2025-09-28 17:10:43,302 - AgenticMedicalRAG - INFO - 🔍 Creating vector retriever... +2025-09-28 17:10:43,302 - AgenticMedicalRAG - INFO - 📝 Creating BM25 retriever... +2025-09-28 17:10:43,858 - AgenticMedicalRAG - INFO - 🔄 Creating hybrid retriever... +2025-09-28 17:10:43,861 - AgenticMedicalRAG - INFO - ✅ Retrievers created and hybrid retriever is ready. +2025-09-28 17:10:43,884 - AgenticMedicalRAG - INFO - Agentic Medical Guidelines Assistant starting... +2025-09-28 17:10:43,884 - AgenticMedicalRAG - INFO - Starting Gradio interface... +2025-09-28 17:15:47,343 - AgenticMedicalRAG - INFO - Processing user input (attempt 1): i found that afatinib has these side effects Diarr... +2025-09-28 17:15:51,260 - AgenticMedicalRAG - INFO - Successfully processed user input: i found that afatinib has these side effects Diarr... +2025-09-28 17:46:31,824 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-09-28 17:46:32,763 - AgenticMedicalRAG - INFO - 🔄 Processing new data and updating vector store if needed... +2025-09-28 17:46:32,871 - AgenticMedicalRAG - INFO - 📦 Loading chunks cache for BM25 retriever... +2025-09-28 17:46:32,894 - AgenticMedicalRAG - INFO - 🔍 Creating vector retriever... +2025-09-28 17:46:32,895 - AgenticMedicalRAG - INFO - 📝 Creating BM25 retriever... +2025-09-28 17:46:33,667 - AgenticMedicalRAG - INFO - 🔄 Creating hybrid retriever... +2025-09-28 17:46:33,669 - AgenticMedicalRAG - INFO - ✅ Retrievers created and hybrid retriever is ready. +2025-09-28 17:46:33,704 - AgenticMedicalRAG - INFO - Agentic Medical Guidelines Assistant starting... +2025-09-28 17:46:33,704 - AgenticMedicalRAG - INFO - Starting Gradio interface... +2025-09-28 17:47:04,888 - AgenticMedicalRAG - INFO - Processing user input (attempt 1): i found that afatinib has these side effects Diarr... +2025-09-28 17:47:08,216 - AgenticMedicalRAG - INFO - Successfully processed user input: i found that afatinib has these side effects Diarr... +2025-09-28 18:24:13,178 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-09-28 18:24:14,245 - AgenticMedicalRAG - INFO - 🔄 Processing new data and updating vector store if needed... +2025-09-28 18:24:14,321 - AgenticMedicalRAG - INFO - 📦 Loading chunks cache for BM25 retriever... +2025-09-28 18:24:14,341 - AgenticMedicalRAG - INFO - 🔍 Creating vector retriever... +2025-09-28 18:24:14,342 - AgenticMedicalRAG - INFO - 📝 Creating BM25 retriever... +2025-09-28 18:24:14,965 - AgenticMedicalRAG - INFO - 🔄 Creating hybrid retriever... +2025-09-28 18:24:14,966 - AgenticMedicalRAG - INFO - ✅ Retrievers created and hybrid retriever is ready. +2025-09-28 18:24:14,998 - AgenticMedicalRAG - INFO - Agentic Medical Guidelines Assistant starting... +2025-09-28 18:24:14,998 - AgenticMedicalRAG - INFO - Starting Gradio interface... +2025-09-28 18:25:46,504 - AgenticMedicalRAG - INFO - Processing user input (attempt 1): I found that afatinib can cause the following side... +2025-09-28 18:25:50,523 - AgenticMedicalRAG - INFO - Successfully processed user input: I found that afatinib can cause the following side... +2025-09-28 18:26:46,519 - AgenticMedicalRAG - INFO - Processing user input (attempt 1): 55 +male +40ml +3 months... +2025-09-28 18:26:50,308 - AgenticMedicalRAG - INFO - Successfully processed user input: 55 +male +40ml +3 months... +2025-09-28 18:27:15,449 - AgenticMedicalRAG - INFO - Processing user input (attempt 1): moderate +ongoing... +2025-09-28 18:27:18,443 - AgenticMedicalRAG - INFO - Successfully processed user input: moderate +ongoing... +2025-09-28 18:27:50,403 - AgenticMedicalRAG - INFO - Processing user input (attempt 1): save report... +2025-09-28 18:27:53,555 - AgenticMedicalRAG - INFO - Successfully processed user input: save report... +2025-09-28 18:38:17,363 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-09-28 18:38:18,153 - AgenticMedicalRAG - INFO - 🔄 Processing new data and updating vector store if needed... +2025-09-28 18:38:18,234 - AgenticMedicalRAG - INFO - 📦 Loading chunks cache for BM25 retriever... +2025-09-28 18:38:18,252 - AgenticMedicalRAG - INFO - 🔍 Creating vector retriever... +2025-09-28 18:38:18,252 - AgenticMedicalRAG - INFO - 📝 Creating BM25 retriever... +2025-09-28 18:38:18,960 - AgenticMedicalRAG - INFO - 🔄 Creating hybrid retriever... +2025-09-28 18:38:18,961 - AgenticMedicalRAG - INFO - ✅ Retrievers created and hybrid retriever is ready. +2025-09-28 18:38:18,995 - AgenticMedicalRAG - INFO - Agentic Medical Guidelines Assistant starting... +2025-09-28 18:38:18,997 - AgenticMedicalRAG - INFO - Starting Gradio interface... +2025-09-28 18:41:37,804 - AgenticMedicalRAG - INFO - Processing user input (attempt 1): I found that afatinib can cause the following side... +2025-09-28 18:41:41,007 - AgenticMedicalRAG - INFO - Successfully processed user input: I found that afatinib can cause the following side... +2025-09-28 18:45:23,962 - AgenticMedicalRAG - INFO - Processing user input (attempt 1): the patient's age is 55 and he is male and dosage ... +2025-09-28 18:45:27,901 - AgenticMedicalRAG - INFO - Successfully processed user input: the patient's age is 55 and he is male and dosage ... +2025-09-28 19:50:08,925 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-09-28 19:50:10,345 - AgenticMedicalRAG - INFO - 🔄 Processing new data and updating vector store if needed... +2025-09-28 19:50:10,519 - AgenticMedicalRAG - INFO - 📦 Loading chunks cache for BM25 retriever... +2025-09-28 19:50:10,544 - AgenticMedicalRAG - INFO - 🔍 Creating vector retriever... +2025-09-28 19:50:10,545 - AgenticMedicalRAG - INFO - 📝 Creating BM25 retriever... +2025-09-28 19:50:11,461 - AgenticMedicalRAG - INFO - 🔄 Creating hybrid retriever... +2025-09-28 19:50:11,463 - AgenticMedicalRAG - INFO - ✅ Retrievers created and hybrid retriever is ready. +2025-09-28 19:50:11,528 - AgenticMedicalRAG - INFO - Agentic Medical Guidelines Assistant starting... +2025-09-28 19:50:11,529 - AgenticMedicalRAG - INFO - Starting Gradio interface... +2025-09-28 19:50:38,620 - AgenticMedicalRAG - INFO - Processing user input (attempt 1): I found that afatinib can cause the following side... +2025-09-28 19:50:43,725 - AgenticMedicalRAG - INFO - Successfully processed user input: I found that afatinib can cause the following side... +2025-09-28 19:51:30,734 - AgenticMedicalRAG - INFO - Conversation memory cleared successfully +2025-09-28 19:51:30,734 - AgenticMedicalRAG - INFO - Successfully cleared chat memory and history +2025-09-28 19:58:55,102 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-09-28 19:58:55,851 - AgenticMedicalRAG - INFO - 🔄 Processing new data and updating vector store if needed... +2025-09-28 19:58:55,931 - AgenticMedicalRAG - INFO - 📦 Loading chunks cache for BM25 retriever... +2025-09-28 19:58:55,954 - AgenticMedicalRAG - INFO - 🔍 Creating vector retriever... +2025-09-28 19:58:55,955 - AgenticMedicalRAG - INFO - 📝 Creating BM25 retriever... +2025-09-28 19:58:56,513 - AgenticMedicalRAG - INFO - 🔄 Creating hybrid retriever... +2025-09-28 19:58:56,514 - AgenticMedicalRAG - INFO - ✅ Retrievers created and hybrid retriever is ready. +2025-09-28 19:58:56,549 - AgenticMedicalRAG - INFO - Agentic Medical Guidelines Assistant starting... +2025-09-28 19:58:56,549 - AgenticMedicalRAG - INFO - Starting Gradio interface... +2025-09-28 19:59:36,399 - AgenticMedicalRAG - INFO - Processing user input (attempt 1): I found that afatinib can cause the following side... +2025-09-28 19:59:40,693 - AgenticMedicalRAG - INFO - Successfully processed user input: I found that afatinib can cause the following side... +2025-09-30 12:07:29,525 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-09-30 12:07:30,290 - AgenticMedicalRAG - INFO - 🔄 Processing new data and updating vector store if needed... +2025-09-30 12:07:30,451 - AgenticMedicalRAG - INFO - 📦 Loading chunks cache for BM25 retriever... +2025-09-30 12:07:30,470 - AgenticMedicalRAG - INFO - 🔍 Creating vector retriever... +2025-09-30 12:07:30,470 - AgenticMedicalRAG - INFO - 📝 Creating BM25 retriever... +2025-09-30 12:07:30,841 - AgenticMedicalRAG - INFO - 🔄 Creating hybrid retriever... +2025-09-30 12:07:30,842 - AgenticMedicalRAG - INFO - ✅ Retrievers created and hybrid retriever is ready. +2025-09-30 12:07:46,793 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-09-30 12:07:47,340 - AgenticMedicalRAG - INFO - 🔄 Processing new data and updating vector store if needed... +2025-09-30 12:07:47,524 - AgenticMedicalRAG - INFO - 📦 Loading chunks cache for BM25 retriever... +2025-09-30 12:07:47,553 - AgenticMedicalRAG - INFO - 🔍 Creating vector retriever... +2025-09-30 12:07:47,554 - AgenticMedicalRAG - INFO - 📝 Creating BM25 retriever... +2025-09-30 12:07:47,915 - AgenticMedicalRAG - INFO - 🔄 Creating hybrid retriever... +2025-09-30 12:07:47,916 - AgenticMedicalRAG - INFO - ✅ Retrievers created and hybrid retriever is ready. +2025-09-30 12:08:18,007 - AgenticMedicalRAG - INFO - Processing user input (attempt 1): How should stage III NSCLC with EGFR mutations be ... +2025-09-30 12:08:29,664 - AgenticMedicalRAG - INFO - Successfully processed user input: How should stage III NSCLC with EGFR mutations be ... +2025-09-30 12:08:52,204 - AgenticMedicalRAG - INFO - Processing user input (attempt 1): How should stage III NSCLC with EGFR mutations be ... +2025-09-30 12:09:03,518 - AgenticMedicalRAG - INFO - Successfully processed user input: How should stage III NSCLC with EGFR mutations be ... +2025-09-30 14:04:01,384 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-09-30 14:04:01,872 - AgenticMedicalRAG - INFO - 🔄 Processing new data and updating vector store if needed... +2025-09-30 14:04:01,957 - AgenticMedicalRAG - INFO - 📦 Loading chunks cache for BM25 retriever... +2025-09-30 14:04:01,979 - AgenticMedicalRAG - INFO - 🔍 Creating vector retriever... +2025-09-30 14:04:01,980 - AgenticMedicalRAG - INFO - 📝 Creating BM25 retriever... +2025-09-30 14:04:02,363 - AgenticMedicalRAG - INFO - 🔄 Creating hybrid retriever... +2025-09-30 14:04:02,364 - AgenticMedicalRAG - INFO - ✅ Retrievers created and hybrid retriever is ready. +2025-09-30 14:08:15,099 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-09-30 14:08:15,489 - AgenticMedicalRAG - INFO - 🔄 Processing new data and updating vector store if needed... +2025-09-30 14:08:15,552 - AgenticMedicalRAG - INFO - 📦 Loading chunks cache for BM25 retriever... +2025-09-30 14:08:15,567 - AgenticMedicalRAG - INFO - 🔍 Creating vector retriever... +2025-09-30 14:08:15,570 - AgenticMedicalRAG - INFO - 📝 Creating BM25 retriever... +2025-09-30 14:08:15,852 - AgenticMedicalRAG - INFO - 🔄 Creating hybrid retriever... +2025-09-30 14:08:15,854 - AgenticMedicalRAG - INFO - ✅ Retrievers created and hybrid retriever is ready. +2025-09-30 14:10:04,366 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-09-30 14:10:04,917 - AgenticMedicalRAG - INFO - 🔄 Processing new data and updating vector store if needed... +2025-09-30 14:10:05,000 - AgenticMedicalRAG - INFO - 📦 Loading chunks cache for BM25 retriever... +2025-09-30 14:10:05,017 - AgenticMedicalRAG - INFO - 🔍 Creating vector retriever... +2025-09-30 14:10:05,018 - AgenticMedicalRAG - INFO - 📝 Creating BM25 retriever... +2025-09-30 14:10:05,321 - AgenticMedicalRAG - INFO - 🔄 Creating hybrid retriever... +2025-09-30 14:10:05,323 - AgenticMedicalRAG - INFO - ✅ Retrievers created and hybrid retriever is ready. +2025-09-30 14:11:43,739 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-09-30 14:11:44,207 - AgenticMedicalRAG - INFO - 🔄 Processing new data and updating vector store if needed... +2025-09-30 14:11:44,283 - AgenticMedicalRAG - INFO - 📦 Loading chunks cache for BM25 retriever... +2025-09-30 14:11:44,307 - AgenticMedicalRAG - INFO - 🔍 Creating vector retriever... +2025-09-30 14:11:44,307 - AgenticMedicalRAG - INFO - 📝 Creating BM25 retriever... +2025-09-30 14:11:44,668 - AgenticMedicalRAG - INFO - 🔄 Creating hybrid retriever... +2025-09-30 14:11:44,669 - AgenticMedicalRAG - INFO - ✅ Retrievers created and hybrid retriever is ready. +2025-09-30 14:12:02,431 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-09-30 14:12:02,911 - AgenticMedicalRAG - INFO - 🔄 Processing new data and updating vector store if needed... +2025-09-30 14:12:02,989 - AgenticMedicalRAG - INFO - 📦 Loading chunks cache for BM25 retriever... +2025-09-30 14:12:03,008 - AgenticMedicalRAG - INFO - 🔍 Creating vector retriever... +2025-09-30 14:12:03,009 - AgenticMedicalRAG - INFO - 📝 Creating BM25 retriever... +2025-09-30 14:12:03,371 - AgenticMedicalRAG - INFO - 🔄 Creating hybrid retriever... +2025-09-30 14:12:03,371 - AgenticMedicalRAG - INFO - ✅ Retrievers created and hybrid retriever is ready. +2025-09-30 14:22:22,453 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-09-30 14:22:23,029 - AgenticMedicalRAG - INFO - 🔄 Processing new data and updating vector store if needed... +2025-09-30 14:22:23,113 - AgenticMedicalRAG - INFO - 📦 Loading chunks cache for BM25 retriever... +2025-09-30 14:22:23,133 - AgenticMedicalRAG - INFO - 🔍 Creating vector retriever... +2025-09-30 14:22:23,134 - AgenticMedicalRAG - INFO - 📝 Creating BM25 retriever... +2025-09-30 14:22:23,485 - AgenticMedicalRAG - INFO - 🔄 Creating hybrid retriever... +2025-09-30 14:22:23,486 - AgenticMedicalRAG - INFO - ✅ Retrievers created and hybrid retriever is ready. +2025-09-30 14:26:58,213 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-09-30 14:26:58,933 - AgenticMedicalRAG - INFO - 🔄 Processing new data and updating vector store if needed... +2025-09-30 14:26:59,009 - AgenticMedicalRAG - INFO - 📦 Loading chunks cache for BM25 retriever... +2025-09-30 14:26:59,029 - AgenticMedicalRAG - INFO - 🔍 Creating vector retriever... +2025-09-30 14:26:59,030 - AgenticMedicalRAG - INFO - 📝 Creating BM25 retriever... +2025-09-30 14:26:59,367 - AgenticMedicalRAG - INFO - 🔄 Creating hybrid retriever... +2025-09-30 14:26:59,367 - AgenticMedicalRAG - INFO - ✅ Retrievers created and hybrid retriever is ready. +2025-09-30 14:27:12,980 - AgenticMedicalRAG - INFO - Processing user input (attempt 1): How should stage III NSCLC with EGFR mutations be ... +2025-09-30 14:27:56,532 - AgenticMedicalRAG - INFO - Successfully processed user input: How should stage III NSCLC with EGFR mutations be ... +2025-09-30 14:28:16,414 - AgenticMedicalRAG - INFO - Processing user input (attempt 1): How should stage III NSCLC with EGFR mutations be ... +2025-09-30 14:28:25,301 - AgenticMedicalRAG - INFO - Successfully processed user input: How should stage III NSCLC with EGFR mutations be ... +2025-09-30 21:42:36,452 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-09-30 21:42:36,937 - AgenticMedicalRAG - INFO - 🔄 Processing new data and updating vector store if needed... +2025-09-30 21:42:37,037 - AgenticMedicalRAG - INFO - 📦 Loading chunks cache for BM25 retriever... +2025-09-30 21:42:37,047 - AgenticMedicalRAG - INFO - 🔍 Creating vector retriever... +2025-09-30 21:42:37,047 - AgenticMedicalRAG - INFO - 📝 Creating BM25 retriever... +2025-09-30 21:42:37,208 - AgenticMedicalRAG - INFO - 🔄 Creating hybrid retriever... +2025-09-30 21:42:37,208 - AgenticMedicalRAG - INFO - ✅ Retrievers created and hybrid retriever is ready. +2025-09-30 22:04:14,108 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-09-30 22:06:21,470 - AgenticMedicalRAG - INFO - Processing user input (attempt 1): How should stage III NSCLC with EGFR mutations be ... +2025-09-30 22:06:21,470 - AgenticMedicalRAG - INFO - Initializing LLM (first time)... +2025-09-30 22:06:21,981 - AgenticMedicalRAG - INFO - LLM initialized successfully +2025-09-30 22:06:24,914 - AgenticMedicalRAG - INFO - 🔄 Initializing retrievers (first time use)... +2025-09-30 22:06:24,915 - AgenticMedicalRAG - INFO - 🔄 Processing new data and updating vector store if needed... +2025-09-30 22:06:24,917 - AgenticMedicalRAG - INFO - Loading embedding model (first time)... +2025-09-30 22:06:39,317 - AgenticMedicalRAG - INFO - Embedding model loaded successfully +2025-09-30 22:06:39,390 - AgenticMedicalRAG - INFO - 📦 Loading chunks cache for BM25 retriever... +2025-09-30 22:06:39,412 - AgenticMedicalRAG - INFO - 🔍 Creating vector retriever... +2025-09-30 22:06:39,412 - AgenticMedicalRAG - INFO - 📝 Creating BM25 retriever... +2025-09-30 22:06:39,712 - AgenticMedicalRAG - INFO - 🔄 Creating hybrid retriever... +2025-09-30 22:06:39,713 - AgenticMedicalRAG - INFO - ✅ Retrievers initialized successfully. +2025-09-30 22:06:51,982 - AgenticMedicalRAG - INFO - Successfully processed user input: How should stage III NSCLC with EGFR mutations be ... +2025-09-30 22:09:15,536 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-09-30 22:09:59,812 - AgenticMedicalRAG - INFO - Processing user input (attempt 1): I found that afatinib can cause the following side... +2025-09-30 22:09:59,812 - AgenticMedicalRAG - INFO - Initializing LLM (first time)... +2025-09-30 22:10:00,261 - AgenticMedicalRAG - INFO - LLM initialized successfully +2025-09-30 22:10:04,676 - AgenticMedicalRAG - INFO - Successfully processed user input: I found that afatinib can cause the following side... +2025-10-01 11:08:17,517 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-10-01 11:08:58,099 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-10-01 11:09:02,449 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-10-01 11:09:06,497 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-10-01 11:09:11,130 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-10-01 11:09:55,514 - AgenticMedicalRAG - INFO - Processing user input (attempt 1): What is the recommended first-line treatment for a... +2025-10-01 11:09:55,515 - AgenticMedicalRAG - INFO - Initializing LLM (first time)... +2025-10-01 11:09:56,194 - AgenticMedicalRAG - INFO - LLM initialized successfully +2025-10-01 11:09:58,163 - AgenticMedicalRAG - INFO - 🔄 Initializing retrievers (first time use)... +2025-10-01 11:09:58,164 - AgenticMedicalRAG - INFO - 🔄 Processing new data and updating vector store if needed... +2025-10-01 11:09:58,166 - AgenticMedicalRAG - INFO - Loading embedding model (first time)... +2025-10-01 11:10:18,154 - AgenticMedicalRAG - INFO - Embedding model loaded successfully +2025-10-01 11:10:18,353 - AgenticMedicalRAG - INFO - 📦 Loading chunks cache for BM25 retriever... +2025-10-01 11:10:18,397 - AgenticMedicalRAG - INFO - 🔍 Creating vector retriever... +2025-10-01 11:10:18,398 - AgenticMedicalRAG - INFO - 📝 Creating BM25 retriever... +2025-10-01 11:10:18,726 - AgenticMedicalRAG - INFO - 🔄 Creating hybrid retriever... +2025-10-01 11:10:18,727 - AgenticMedicalRAG - INFO - ✅ Retrievers initialized successfully. +2025-10-01 11:10:26,024 - AgenticMedicalRAG - INFO - Successfully processed user input: What is the recommended first-line treatment for a... +2025-10-01 11:13:22,817 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-10-01 11:13:39,242 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-10-01 11:14:03,610 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-10-01 11:27:48,592 - AgenticMedicalRAG - INFO - Processing user input (attempt 1): What is the recommended first-line treatment for a... +2025-10-01 11:27:48,592 - AgenticMedicalRAG - INFO - Initializing LLM (first time)... +2025-10-01 11:27:49,013 - AgenticMedicalRAG - INFO - LLM initialized successfully +2025-10-01 11:27:50,879 - AgenticMedicalRAG - INFO - 🔄 Initializing retrievers (first time use)... +2025-10-01 11:27:50,880 - AgenticMedicalRAG - INFO - 🔄 Processing new data and updating vector store if needed... +2025-10-01 11:27:50,882 - AgenticMedicalRAG - INFO - Loading embedding model (first time)... +2025-10-01 11:28:04,902 - AgenticMedicalRAG - INFO - Embedding model loaded successfully +2025-10-01 11:28:04,971 - AgenticMedicalRAG - INFO - 📦 Loading chunks cache for BM25 retriever... +2025-10-01 11:28:04,990 - AgenticMedicalRAG - INFO - 🔍 Creating vector retriever... +2025-10-01 11:28:04,990 - AgenticMedicalRAG - INFO - 📝 Creating BM25 retriever... +2025-10-01 11:28:05,286 - AgenticMedicalRAG - INFO - 🔄 Creating hybrid retriever... +2025-10-01 11:28:05,287 - AgenticMedicalRAG - INFO - ✅ Retrievers initialized successfully. +2025-10-01 11:28:14,371 - AgenticMedicalRAG - INFO - Successfully processed user input: What is the recommended first-line treatment for a... +2025-10-01 11:30:17,632 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-10-01 11:30:36,899 - AgenticMedicalRAG - INFO - Processing user input (attempt 1): What is the recommended first-line treatment for a... +2025-10-01 11:30:36,900 - AgenticMedicalRAG - INFO - Initializing LLM (first time)... +2025-10-01 11:30:37,354 - AgenticMedicalRAG - INFO - LLM initialized successfully +2025-10-01 11:30:39,328 - AgenticMedicalRAG - INFO - 🔄 Initializing retrievers (first time use)... +2025-10-01 11:30:39,329 - AgenticMedicalRAG - INFO - 🔄 Processing new data and updating vector store if needed... +2025-10-01 11:30:39,330 - AgenticMedicalRAG - INFO - Loading embedding model (first time)... +2025-10-01 11:30:52,017 - AgenticMedicalRAG - INFO - Embedding model loaded successfully +2025-10-01 11:30:52,113 - AgenticMedicalRAG - INFO - 📦 Loading chunks cache for BM25 retriever... +2025-10-01 11:30:52,133 - AgenticMedicalRAG - INFO - 🔍 Creating vector retriever... +2025-10-01 11:30:52,135 - AgenticMedicalRAG - INFO - 📝 Creating BM25 retriever... +2025-10-01 11:30:52,426 - AgenticMedicalRAG - INFO - 🔄 Creating hybrid retriever... +2025-10-01 11:30:52,427 - AgenticMedicalRAG - INFO - ✅ Retrievers initialized successfully. +2025-10-01 11:30:59,770 - AgenticMedicalRAG - INFO - Successfully processed user input: What is the recommended first-line treatment for a... +2025-10-01 11:32:34,382 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-10-01 11:32:41,494 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-10-01 11:32:52,116 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-10-01 11:38:23,378 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-10-01 11:38:44,969 - AgenticMedicalRAG - INFO - Processing user input (attempt 1): What is the recommended first-line treatment for a... +2025-10-01 11:38:44,969 - AgenticMedicalRAG - INFO - Initializing LLM (first time)... +2025-10-01 11:38:45,446 - AgenticMedicalRAG - INFO - LLM initialized successfully +2025-10-01 11:38:47,664 - AgenticMedicalRAG - INFO - 🔄 Initializing retrievers (first time use)... +2025-10-01 11:38:47,664 - AgenticMedicalRAG - INFO - 🔄 Processing new data and updating vector store if needed... +2025-10-01 11:38:47,665 - AgenticMedicalRAG - INFO - Loading embedding model (first time)... +2025-10-01 11:39:00,379 - AgenticMedicalRAG - INFO - Embedding model loaded successfully +2025-10-01 11:39:00,471 - AgenticMedicalRAG - INFO - 📦 Loading chunks cache for BM25 retriever... +2025-10-01 11:39:00,496 - AgenticMedicalRAG - INFO - 🔍 Creating vector retriever... +2025-10-01 11:39:00,498 - AgenticMedicalRAG - INFO - 📝 Creating BM25 retriever... +2025-10-01 11:39:00,795 - AgenticMedicalRAG - INFO - 🔄 Creating hybrid retriever... +2025-10-01 11:39:00,796 - AgenticMedicalRAG - INFO - ✅ Retrievers initialized successfully. +2025-10-01 11:39:08,907 - AgenticMedicalRAG - INFO - Successfully processed user input: What is the recommended first-line treatment for a... +2025-10-01 11:57:41,075 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-10-01 12:01:33,774 - AgenticMedicalRAG - INFO - Processing user input (attempt 1): What is the recommended first-line treatment for a... +2025-10-01 12:01:33,775 - AgenticMedicalRAG - INFO - Initializing LLM (first time)... +2025-10-01 12:01:34,237 - AgenticMedicalRAG - INFO - LLM initialized successfully +2025-10-01 12:01:35,987 - AgenticMedicalRAG - INFO - 🔄 Initializing retrievers (first time use)... +2025-10-01 12:01:35,988 - AgenticMedicalRAG - INFO - 🔄 Processing new data and updating vector store if needed... +2025-10-01 12:01:35,990 - AgenticMedicalRAG - INFO - Loading embedding model (first time)... +2025-10-01 12:01:48,472 - AgenticMedicalRAG - INFO - Embedding model loaded successfully +2025-10-01 12:01:48,563 - AgenticMedicalRAG - INFO - 📦 Loading chunks cache for BM25 retriever... +2025-10-01 12:01:48,585 - AgenticMedicalRAG - INFO - 🔍 Creating vector retriever... +2025-10-01 12:01:48,585 - AgenticMedicalRAG - INFO - 📝 Creating BM25 retriever... +2025-10-01 12:01:48,881 - AgenticMedicalRAG - INFO - 🔄 Creating hybrid retriever... +2025-10-01 12:01:48,882 - AgenticMedicalRAG - INFO - ✅ Retrievers initialized successfully. +2025-10-01 12:01:55,918 - AgenticMedicalRAG - INFO - Successfully processed user input: What is the recommended first-line treatment for a... +2025-10-01 12:03:49,244 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-10-01 12:11:06,958 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-10-01 12:11:34,125 - AgenticMedicalRAG - INFO - Processing user input (attempt 1): What is the recommended first-line treatment for a... +2025-10-01 12:11:34,126 - AgenticMedicalRAG - INFO - Initializing LLM (first time)... +2025-10-01 12:11:34,581 - AgenticMedicalRAG - INFO - LLM initialized successfully +2025-10-01 12:11:36,608 - AgenticMedicalRAG - INFO - 🔄 Initializing retrievers (first time use)... +2025-10-01 12:11:36,608 - AgenticMedicalRAG - INFO - 🔄 Processing new data and updating vector store if needed... +2025-10-01 12:11:36,609 - AgenticMedicalRAG - INFO - Loading embedding model (first time)... +2025-10-01 12:11:50,859 - AgenticMedicalRAG - INFO - Embedding model loaded successfully +2025-10-01 12:11:50,974 - AgenticMedicalRAG - INFO - 📦 Loading chunks cache for BM25 retriever... +2025-10-01 12:11:50,999 - AgenticMedicalRAG - INFO - 🔍 Creating vector retriever... +2025-10-01 12:11:51,000 - AgenticMedicalRAG - INFO - 📝 Creating BM25 retriever... +2025-10-01 12:11:51,305 - AgenticMedicalRAG - INFO - 🔄 Creating hybrid retriever... +2025-10-01 12:11:51,306 - AgenticMedicalRAG - INFO - ✅ Retrievers initialized successfully. +2025-10-01 12:12:03,103 - AgenticMedicalRAG - INFO - Successfully processed user input: What is the recommended first-line treatment for a... +2025-10-01 12:15:04,808 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-10-01 12:15:12,227 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-10-01 12:15:35,881 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-10-01 12:18:09,901 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-10-01 12:18:22,784 - AgenticMedicalRAG - INFO - Processing user input (attempt 1): What is the recommended first-line treatment for a... +2025-10-01 12:18:22,785 - AgenticMedicalRAG - INFO - Initializing LLM (first time)... +2025-10-01 12:18:23,232 - AgenticMedicalRAG - INFO - LLM initialized successfully +2025-10-01 12:18:24,941 - AgenticMedicalRAG - INFO - 🔄 Initializing retrievers (first time use)... +2025-10-01 12:18:24,943 - AgenticMedicalRAG - INFO - 🔄 Processing new data and updating vector store if needed... +2025-10-01 12:18:24,944 - AgenticMedicalRAG - INFO - Loading embedding model (first time)... +2025-10-01 12:18:37,203 - AgenticMedicalRAG - INFO - Embedding model loaded successfully +2025-10-01 12:18:37,294 - AgenticMedicalRAG - INFO - 📦 Loading chunks cache for BM25 retriever... +2025-10-01 12:18:37,318 - AgenticMedicalRAG - INFO - 🔍 Creating vector retriever... +2025-10-01 12:18:37,319 - AgenticMedicalRAG - INFO - 📝 Creating BM25 retriever... +2025-10-01 12:18:37,621 - AgenticMedicalRAG - INFO - 🔄 Creating hybrid retriever... +2025-10-01 12:18:37,623 - AgenticMedicalRAG - INFO - ✅ Retrievers initialized successfully. +2025-10-01 12:18:49,475 - AgenticMedicalRAG - INFO - Successfully processed user input: What is the recommended first-line treatment for a... +2025-10-01 12:21:46,365 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-10-01 12:22:00,952 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-10-01 12:22:06,742 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-10-01 12:22:12,344 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-10-01 12:22:26,597 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-10-01 12:22:33,888 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-10-01 12:22:44,821 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-10-01 12:22:56,268 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-10-01 14:26:12,339 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-10-01 14:26:14,168 - AgenticMedicalRAG - INFO - Agentic Medical Guidelines Assistant starting... +2025-10-01 14:26:14,168 - AgenticMedicalRAG - INFO - Starting Gradio interface... +2025-10-01 14:26:48,420 - AgenticMedicalRAG - INFO - Processing user input (attempt 1): What is the recommended first-line treatment for a... +2025-10-01 14:26:48,421 - AgenticMedicalRAG - INFO - Initializing LLM (first time)... +2025-10-01 14:26:48,927 - AgenticMedicalRAG - INFO - LLM initialized successfully +2025-10-01 14:26:51,049 - AgenticMedicalRAG - INFO - 🔄 Initializing retrievers (first time use)... +2025-10-01 14:26:51,050 - AgenticMedicalRAG - INFO - 🔄 Processing new data and updating vector store if needed... +2025-10-01 14:26:51,051 - AgenticMedicalRAG - INFO - Loading embedding model (first time)... +2025-10-01 14:27:05,144 - AgenticMedicalRAG - INFO - Embedding model loaded successfully +2025-10-01 14:27:05,220 - AgenticMedicalRAG - INFO - 📦 Loading chunks cache for BM25 retriever... +2025-10-01 14:27:05,242 - AgenticMedicalRAG - INFO - 🔍 Creating vector retriever... +2025-10-01 14:27:05,242 - AgenticMedicalRAG - INFO - 📝 Creating BM25 retriever... +2025-10-01 14:27:05,587 - AgenticMedicalRAG - INFO - 🔄 Creating hybrid retriever... +2025-10-01 14:27:05,588 - AgenticMedicalRAG - INFO - ✅ Retrievers initialized successfully. +2025-10-01 14:27:25,795 - AgenticMedicalRAG - INFO - Successfully processed user input: What is the recommended first-line treatment for a... +2025-10-01 14:33:51,285 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-10-01 14:33:52,115 - AgenticMedicalRAG - INFO - Agentic Medical Guidelines Assistant starting... +2025-10-01 14:33:52,116 - AgenticMedicalRAG - INFO - Starting Gradio interface... +2025-10-01 14:34:03,074 - AgenticMedicalRAG - INFO - Processing user input (attempt 1): What is the recommended first-line treatment for a... +2025-10-01 14:34:03,077 - AgenticMedicalRAG - INFO - Initializing LLM (first time)... +2025-10-01 14:34:03,588 - AgenticMedicalRAG - INFO - LLM initialized successfully +2025-10-01 14:34:05,104 - AgenticMedicalRAG - INFO - 🔄 Initializing retrievers (first time use)... +2025-10-01 14:34:05,104 - AgenticMedicalRAG - INFO - 🔄 Processing new data and updating vector store if needed... +2025-10-01 14:34:05,105 - AgenticMedicalRAG - INFO - Loading embedding model (first time)... +2025-10-01 14:34:17,293 - AgenticMedicalRAG - INFO - Embedding model loaded successfully +2025-10-01 14:34:17,346 - AgenticMedicalRAG - INFO - 📦 Loading chunks cache for BM25 retriever... +2025-10-01 14:34:17,358 - AgenticMedicalRAG - INFO - 🔍 Creating vector retriever... +2025-10-01 14:34:17,358 - AgenticMedicalRAG - INFO - 📝 Creating BM25 retriever... +2025-10-01 14:34:17,538 - AgenticMedicalRAG - INFO - 🔄 Creating hybrid retriever... +2025-10-01 14:34:17,539 - AgenticMedicalRAG - INFO - ✅ Retrievers initialized successfully. +2025-10-01 14:34:30,405 - AgenticMedicalRAG - INFO - Successfully processed user input: What is the recommended first-line treatment for a... +2025-10-01 14:39:45,532 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-10-01 14:39:46,392 - AgenticMedicalRAG - INFO - Agentic Medical Guidelines Assistant starting... +2025-10-01 14:39:46,392 - AgenticMedicalRAG - INFO - Starting Gradio interface... +2025-10-01 14:39:58,035 - AgenticMedicalRAG - INFO - Processing user input (attempt 1): What is the recommended first-line treatment for a... +2025-10-01 14:39:58,037 - AgenticMedicalRAG - INFO - Initializing LLM (first time)... +2025-10-01 14:39:58,533 - AgenticMedicalRAG - INFO - LLM initialized successfully +2025-10-01 14:40:00,635 - AgenticMedicalRAG - INFO - 🔄 Initializing retrievers (first time use)... +2025-10-01 14:40:00,635 - AgenticMedicalRAG - INFO - 🔄 Processing new data and updating vector store if needed... +2025-10-01 14:40:00,636 - AgenticMedicalRAG - INFO - Loading embedding model (first time)... +2025-10-01 14:40:11,039 - AgenticMedicalRAG - INFO - Embedding model loaded successfully +2025-10-01 14:40:11,099 - AgenticMedicalRAG - INFO - 📦 Loading chunks cache for BM25 retriever... +2025-10-01 14:40:11,115 - AgenticMedicalRAG - INFO - 🔍 Creating vector retriever... +2025-10-01 14:40:11,116 - AgenticMedicalRAG - INFO - 📝 Creating BM25 retriever... +2025-10-01 14:40:11,290 - AgenticMedicalRAG - INFO - 🔄 Creating hybrid retriever... +2025-10-01 14:40:11,291 - AgenticMedicalRAG - INFO - ✅ Retrievers initialized successfully. +2025-10-01 14:40:24,626 - AgenticMedicalRAG - ERROR - OpenAI API error: Error code: 413 - {'error': {'code': 'tokens_limit_reached', 'message': 'Request body too large for gpt-4o model. Max size: 8000 tokens.', 'details': 'Request body too large for gpt-4o model. Max size: 8000 tokens.'}} +2025-10-01 14:40:26,626 - AgenticMedicalRAG - INFO - Processing user input (attempt 2): What is the recommended first-line treatment for a... +2025-10-01 14:40:35,888 - AgenticMedicalRAG - ERROR - Unexpected error in run_agent_streaming: cannot schedule new futures after interpreter shutdown +2025-10-01 14:40:35,889 - AgenticMedicalRAG - ERROR - Traceback: Traceback (most recent call last): + File "D:\Work\Agentic-Medical-RAG-AI-Advisor-GitHub\src\agent.py", line 265, in run_agent_streaming + response = await task + ^^^^^^^^^^ + File "C:\Users\moaze\miniconda3\envs\medical-rag-app\Lib\concurrent\futures\thread.py", line 58, in run + result = self.fn(*self.args, **self.kwargs) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "D:\Work\Agentic-Medical-RAG-AI-Advisor-GitHub\src\agent.py", line 235, in run_sync + return get_agent_executor().invoke( + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "C:\Users\moaze\miniconda3\envs\medical-rag-app\Lib\site-packages\langchain\chains\base.py", line 165, in invoke + self._call(inputs, run_manager=run_manager) + File "C:\Users\moaze\miniconda3\envs\medical-rag-app\Lib\site-packages\langchain\agents\agent.py", line 1625, in _call + next_step_output = self._take_next_step( + ^^^^^^^^^^^^^^^^^^^^^ + File "C:\Users\moaze\miniconda3\envs\medical-rag-app\Lib\site-packages\langchain\agents\agent.py", line 1325, in _take_next_step + list( + File "C:\Users\moaze\miniconda3\envs\medical-rag-app\Lib\site-packages\langchain\agents\agent.py", line 1352, in _iter_next_step + output = self._action_agent.plan( + ^^^^^^^^^^^^^^^^^^^^^^^^ + File "C:\Users\moaze\miniconda3\envs\medical-rag-app\Lib\site-packages\langchain\agents\agent.py", line 573, in plan + for chunk in self.runnable.stream(inputs, config={"callbacks": callbacks}): + File "C:\Users\moaze\miniconda3\envs\medical-rag-app\Lib\site-packages\langchain_core\runnables\base.py", line 3437, in stream + yield from self.transform(iter([input]), config, **kwargs) + File "C:\Users\moaze\miniconda3\envs\medical-rag-app\Lib\site-packages\langchain_core\runnables\base.py", line 3423, in transform + yield from self._transform_stream_with_config( + File "C:\Users\moaze\miniconda3\envs\medical-rag-app\Lib\site-packages\langchain_core\runnables\base.py", line 2214, in _transform_stream_with_config + chunk: Output = context.run(next, iterator) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "C:\Users\moaze\miniconda3\envs\medical-rag-app\Lib\site-packages\langchain_core\runnables\base.py", line 3385, in _transform + yield from final_pipeline + File "C:\Users\moaze\miniconda3\envs\medical-rag-app\Lib\site-packages\langchain_core\runnables\base.py", line 1428, in transform + for ichunk in input: + File "C:\Users\moaze\miniconda3\envs\medical-rag-app\Lib\site-packages\langchain_core\runnables\base.py", line 5650, in transform + yield from self.bound.transform( + File "C:\Users\moaze\miniconda3\envs\medical-rag-app\Lib\site-packages\langchain_core\runnables\base.py", line 1428, in transform + for ichunk in input: + File "C:\Users\moaze\miniconda3\envs\medical-rag-app\Lib\site-packages\langchain_core\runnables\base.py", line 1428, in transform + for ichunk in input: + File "C:\Users\moaze\miniconda3\envs\medical-rag-app\Lib\site-packages\langchain_core\runnables\passthrough.py", line 595, in transform + yield from self._transform_stream_with_config( + File "C:\Users\moaze\miniconda3\envs\medical-rag-app\Lib\site-packages\langchain_core\runnables\base.py", line 2214, in _transform_stream_with_config + chunk: Output = context.run(next, iterator) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "C:\Users\moaze\miniconda3\envs\medical-rag-app\Lib\site-packages\langchain_core\runnables\passthrough.py", line 567, in _transform + first_map_chunk_future = executor.submit( + ^^^^^^^^^^^^^^^^ + File "C:\Users\moaze\miniconda3\envs\medical-rag-app\Lib\site-packages\langchain_core\runnables\config.py", line 530, in submit + return super().submit( + ^^^^^^^^^^^^^^^ + File "C:\Users\moaze\miniconda3\envs\medical-rag-app\Lib\concurrent\futures\thread.py", line 169, in submit + raise RuntimeError('cannot schedule new futures after ' +RuntimeError: cannot schedule new futures after interpreter shutdown + +2025-10-01 14:43:33,792 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-10-01 14:43:34,650 - AgenticMedicalRAG - INFO - Agentic Medical Guidelines Assistant starting... +2025-10-01 14:43:34,650 - AgenticMedicalRAG - INFO - Starting Gradio interface... +2025-10-01 14:43:46,524 - AgenticMedicalRAG - INFO - Processing user input (attempt 1): What is the recommended first-line treatment for a... +2025-10-01 14:43:46,525 - AgenticMedicalRAG - INFO - Initializing LLM (first time)... +2025-10-01 14:43:47,015 - AgenticMedicalRAG - INFO - LLM initialized successfully +2025-10-01 14:43:48,524 - AgenticMedicalRAG - INFO - 🔄 Initializing retrievers (first time use)... +2025-10-01 14:43:48,525 - AgenticMedicalRAG - INFO - 🔄 Processing new data and updating vector store if needed... +2025-10-01 14:43:48,526 - AgenticMedicalRAG - INFO - Loading embedding model (first time)... +2025-10-01 14:43:58,550 - AgenticMedicalRAG - INFO - Embedding model loaded successfully +2025-10-01 14:43:58,592 - AgenticMedicalRAG - INFO - 📦 Loading chunks cache for BM25 retriever... +2025-10-01 14:43:58,603 - AgenticMedicalRAG - INFO - 🔍 Creating vector retriever... +2025-10-01 14:43:58,603 - AgenticMedicalRAG - INFO - 📝 Creating BM25 retriever... +2025-10-01 14:43:58,758 - AgenticMedicalRAG - INFO - 🔄 Creating hybrid retriever... +2025-10-01 14:43:58,759 - AgenticMedicalRAG - INFO - ✅ Retrievers initialized successfully. +2025-10-01 14:44:14,607 - AgenticMedicalRAG - INFO - Successfully processed user input: What is the recommended first-line treatment for a... +2025-10-01 15:02:27,184 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-10-01 15:02:28,358 - AgenticMedicalRAG - INFO - Agentic Medical Guidelines Assistant starting... +2025-10-01 15:02:28,358 - AgenticMedicalRAG - INFO - Starting Gradio interface... +2025-10-01 15:13:26,105 - AgenticMedicalRAG - INFO - Processing user input (attempt 1): What is the recommended first-line treatment for a... +2025-10-01 15:13:26,106 - AgenticMedicalRAG - INFO - Initializing LLM (first time)... +2025-10-01 15:13:26,805 - AgenticMedicalRAG - INFO - LLM initialized successfully +2025-10-01 15:13:28,991 - AgenticMedicalRAG - INFO - 🔄 Initializing retrievers (first time use)... +2025-10-01 15:13:28,991 - AgenticMedicalRAG - INFO - 🔄 Processing new data and updating vector store if needed... +2025-10-01 15:13:28,992 - AgenticMedicalRAG - INFO - Loading embedding model (first time)... +2025-10-01 15:13:47,296 - AgenticMedicalRAG - INFO - Embedding model loaded successfully +2025-10-01 15:13:47,418 - AgenticMedicalRAG - INFO - 📦 Loading chunks cache for BM25 retriever... +2025-10-01 15:13:47,444 - AgenticMedicalRAG - INFO - 🔍 Creating vector retriever... +2025-10-01 15:13:47,444 - AgenticMedicalRAG - INFO - 📝 Creating BM25 retriever... +2025-10-01 15:13:47,612 - AgenticMedicalRAG - INFO - 🔄 Creating hybrid retriever... +2025-10-01 15:13:47,613 - AgenticMedicalRAG - INFO - ✅ Retrievers initialized successfully. +2025-10-01 15:13:58,481 - AgenticMedicalRAG - ERROR - Unexpected error in run_agent_streaming: 1 validation error for medical_answer_validation_tool +retrieved_chunks + Field required [type=missing, input_value={'question': 'What is the... The choice of regimen'}, input_type=dict] + For further information visit https://errors.pydantic.dev/2.11/v/missing +2025-10-01 15:13:58,482 - AgenticMedicalRAG - ERROR - Traceback: Traceback (most recent call last): + File "D:\Work\Agentic-Medical-RAG-AI-Advisor-GitHub\src\agent.py", line 270, in run_agent_streaming + response = await task + ^^^^^^^^^^ + File "C:\Users\moaze\miniconda3\envs\medical-rag-app\Lib\concurrent\futures\thread.py", line 58, in run + result = self.fn(*self.args, **self.kwargs) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "D:\Work\Agentic-Medical-RAG-AI-Advisor-GitHub\src\agent.py", line 240, in run_sync + return get_agent_executor().invoke( + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "C:\Users\moaze\miniconda3\envs\medical-rag-app\Lib\site-packages\langchain\chains\base.py", line 165, in invoke + self._call(inputs, run_manager=run_manager) + File "C:\Users\moaze\miniconda3\envs\medical-rag-app\Lib\site-packages\langchain\agents\agent.py", line 1625, in _call + next_step_output = self._take_next_step( + ^^^^^^^^^^^^^^^^^^^^^ + File "C:\Users\moaze\miniconda3\envs\medical-rag-app\Lib\site-packages\langchain\agents\agent.py", line 1325, in _take_next_step + list( + File "C:\Users\moaze\miniconda3\envs\medical-rag-app\Lib\site-packages\langchain\agents\agent.py", line 1408, in _iter_next_step + yield self._perform_agent_action( + ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "C:\Users\moaze\miniconda3\envs\medical-rag-app\Lib\site-packages\langchain\agents\agent.py", line 1433, in _perform_agent_action + observation = tool.run( + ^^^^^^^^^ + File "C:\Users\moaze\miniconda3\envs\medical-rag-app\Lib\site-packages\langchain_core\tools\base.py", line 883, in run + raise error_to_raise + File "C:\Users\moaze\miniconda3\envs\medical-rag-app\Lib\site-packages\langchain_core\tools\base.py", line 845, in run + tool_args, tool_kwargs = self._to_args_and_kwargs( + ^^^^^^^^^^^^^^^^^^^^^^^^^ + File "C:\Users\moaze\miniconda3\envs\medical-rag-app\Lib\site-packages\langchain_core\tools\base.py", line 760, in _to_args_and_kwargs + tool_input = self._parse_input(tool_input, tool_call_id) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "C:\Users\moaze\miniconda3\envs\medical-rag-app\Lib\site-packages\langchain_core\tools\base.py", line 667, in _parse_input + result = input_args.model_validate(tool_input) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "C:\Users\moaze\miniconda3\envs\medical-rag-app\Lib\site-packages\pydantic\main.py", line 705, in model_validate + return cls.__pydantic_validator__.validate_python( + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +pydantic_core._pydantic_core.ValidationError: 1 validation error for medical_answer_validation_tool +retrieved_chunks + Field required [type=missing, input_value={'question': 'What is the... The choice of regimen'}, input_type=dict] + For further information visit https://errors.pydantic.dev/2.11/v/missing + +2025-10-01 15:17:18,358 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-10-01 15:17:19,211 - AgenticMedicalRAG - INFO - Agentic Medical Guidelines Assistant starting... +2025-10-01 15:17:19,212 - AgenticMedicalRAG - INFO - Starting Gradio interface... +2025-10-01 15:17:30,254 - AgenticMedicalRAG - INFO - Processing user input (attempt 1): What is the recommended first-line treatment for a... +2025-10-01 15:17:30,255 - AgenticMedicalRAG - INFO - Initializing LLM (first time)... +2025-10-01 15:17:30,836 - AgenticMedicalRAG - INFO - LLM initialized successfully +2025-10-01 15:17:32,781 - AgenticMedicalRAG - INFO - 🔄 Initializing retrievers (first time use)... +2025-10-01 15:17:32,782 - AgenticMedicalRAG - INFO - 🔄 Processing new data and updating vector store if needed... +2025-10-01 15:17:32,782 - AgenticMedicalRAG - INFO - Loading embedding model (first time)... +2025-10-01 15:17:43,455 - AgenticMedicalRAG - INFO - Embedding model loaded successfully +2025-10-01 15:17:43,502 - AgenticMedicalRAG - INFO - 📦 Loading chunks cache for BM25 retriever... +2025-10-01 15:17:43,513 - AgenticMedicalRAG - INFO - 🔍 Creating vector retriever... +2025-10-01 15:17:43,513 - AgenticMedicalRAG - INFO - 📝 Creating BM25 retriever... +2025-10-01 15:17:43,696 - AgenticMedicalRAG - INFO - 🔄 Creating hybrid retriever... +2025-10-01 15:17:43,697 - AgenticMedicalRAG - INFO - ✅ Retrievers initialized successfully. +2025-10-01 15:17:59,773 - AgenticMedicalRAG - INFO - Successfully processed user input: What is the recommended first-line treatment for a... +2025-10-01 15:27:40,132 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-10-01 15:27:41,014 - AgenticMedicalRAG - INFO - Agentic Medical Guidelines Assistant starting... +2025-10-01 15:27:41,014 - AgenticMedicalRAG - INFO - Starting Gradio interface... +2025-10-01 15:27:55,995 - AgenticMedicalRAG - INFO - Processing user input (attempt 1): What is the recommended first-line treatment for a... +2025-10-01 15:27:55,996 - AgenticMedicalRAG - INFO - Initializing LLM (first time)... +2025-10-01 15:27:56,437 - AgenticMedicalRAG - INFO - LLM initialized successfully +2025-10-01 15:27:58,313 - AgenticMedicalRAG - INFO - 🔄 Initializing retrievers (first time use)... +2025-10-01 15:27:58,313 - AgenticMedicalRAG - INFO - 🔄 Processing new data and updating vector store if needed... +2025-10-01 15:27:58,315 - AgenticMedicalRAG - INFO - Loading embedding model (first time)... +2025-10-01 15:28:13,681 - AgenticMedicalRAG - INFO - Embedding model loaded successfully +2025-10-01 15:28:13,734 - AgenticMedicalRAG - INFO - 📦 Loading chunks cache for BM25 retriever... +2025-10-01 15:28:13,749 - AgenticMedicalRAG - INFO - 🔍 Creating vector retriever... +2025-10-01 15:28:13,749 - AgenticMedicalRAG - INFO - 📝 Creating BM25 retriever... +2025-10-01 15:28:13,986 - AgenticMedicalRAG - INFO - 🔄 Creating hybrid retriever... +2025-10-01 15:28:13,987 - AgenticMedicalRAG - INFO - ✅ Retrievers initialized successfully. +2025-10-01 15:28:29,519 - AgenticMedicalRAG - INFO - Successfully processed user input: What is the recommended first-line treatment for a... +2025-10-01 15:47:00,341 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-10-01 15:47:01,626 - AgenticMedicalRAG - INFO - Agentic Medical Guidelines Assistant starting... +2025-10-01 15:47:01,627 - AgenticMedicalRAG - INFO - Starting Gradio interface... +2025-10-01 15:47:12,019 - AgenticMedicalRAG - INFO - Processing user input (attempt 1): What is the recommended first-line treatment for a... +2025-10-01 15:47:12,022 - AgenticMedicalRAG - INFO - Initializing LLM (first time)... +2025-10-01 15:47:12,542 - AgenticMedicalRAG - INFO - LLM initialized successfully +2025-10-01 15:47:14,778 - AgenticMedicalRAG - INFO - 🔄 Initializing retrievers (first time use)... +2025-10-01 15:47:14,778 - AgenticMedicalRAG - INFO - 🔄 Processing new data and updating vector store if needed... +2025-10-01 15:47:14,780 - AgenticMedicalRAG - INFO - Loading embedding model (first time)... +2025-10-01 15:47:30,972 - AgenticMedicalRAG - INFO - Embedding model loaded successfully +2025-10-01 15:47:31,088 - AgenticMedicalRAG - INFO - 📦 Loading chunks cache for BM25 retriever... +2025-10-01 15:47:31,115 - AgenticMedicalRAG - INFO - 🔍 Creating vector retriever... +2025-10-01 15:47:31,116 - AgenticMedicalRAG - INFO - 📝 Creating BM25 retriever... +2025-10-01 15:47:31,492 - AgenticMedicalRAG - INFO - 🔄 Creating hybrid retriever... +2025-10-01 15:47:31,494 - AgenticMedicalRAG - INFO - ✅ Retrievers initialized successfully. +2025-10-01 15:47:43,627 - AgenticMedicalRAG - INFO - Successfully processed user input: What is the recommended first-line treatment for a... +2025-10-01 16:25:30,425 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-10-01 16:25:31,633 - AgenticMedicalRAG - INFO - Agentic Medical Guidelines Assistant starting... +2025-10-01 16:25:31,633 - AgenticMedicalRAG - INFO - Starting Gradio interface... +2025-10-01 16:25:44,961 - AgenticMedicalRAG - INFO - Processing user input (attempt 1): What is the recommended first-line treatment for a... +2025-10-01 16:25:44,965 - AgenticMedicalRAG - INFO - Initializing LLM (first time)... +2025-10-01 16:25:45,524 - AgenticMedicalRAG - INFO - LLM initialized successfully +2025-10-01 16:25:48,592 - AgenticMedicalRAG - INFO - 🔄 Initializing retrievers (first time use)... +2025-10-01 16:25:48,594 - AgenticMedicalRAG - INFO - 🔄 Processing new data and updating vector store if needed... +2025-10-01 16:25:48,594 - AgenticMedicalRAG - INFO - Loading embedding model (first time)... +2025-10-01 16:26:01,777 - AgenticMedicalRAG - INFO - Embedding model loaded successfully +2025-10-01 16:26:01,867 - AgenticMedicalRAG - INFO - 📦 Loading chunks cache for BM25 retriever... +2025-10-01 16:26:01,892 - AgenticMedicalRAG - INFO - 🔍 Creating vector retriever... +2025-10-01 16:26:01,892 - AgenticMedicalRAG - INFO - 📝 Creating BM25 retriever... +2025-10-01 16:26:02,157 - AgenticMedicalRAG - INFO - 🔄 Creating hybrid retriever... +2025-10-01 16:26:02,158 - AgenticMedicalRAG - INFO - ✅ Retrievers initialized successfully. +2025-10-01 16:26:18,371 - AgenticMedicalRAG - INFO - Successfully processed user input: What is the recommended first-line treatment for a... +2025-10-01 16:35:57,877 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-10-01 16:35:59,261 - AgenticMedicalRAG - INFO - Agentic Medical Guidelines Assistant starting... +2025-10-01 16:35:59,263 - AgenticMedicalRAG - INFO - Starting Gradio interface... +2025-10-01 16:36:17,532 - AgenticMedicalRAG - INFO - Processing user input (attempt 1): What is the recommended first-line treatment for a... +2025-10-01 16:36:17,533 - AgenticMedicalRAG - INFO - Initializing LLM (first time)... +2025-10-01 16:36:18,046 - AgenticMedicalRAG - INFO - LLM initialized successfully +2025-10-01 16:36:20,032 - AgenticMedicalRAG - INFO - 🔄 Initializing retrievers (first time use)... +2025-10-01 16:36:20,033 - AgenticMedicalRAG - INFO - 🔄 Processing new data and updating vector store if needed... +2025-10-01 16:36:20,034 - AgenticMedicalRAG - INFO - Loading embedding model (first time)... +2025-10-01 16:36:33,833 - AgenticMedicalRAG - INFO - Embedding model loaded successfully +2025-10-01 16:36:33,915 - AgenticMedicalRAG - INFO - 📦 Loading chunks cache for BM25 retriever... +2025-10-01 16:36:33,936 - AgenticMedicalRAG - INFO - 🔍 Creating vector retriever... +2025-10-01 16:36:33,937 - AgenticMedicalRAG - INFO - 📝 Creating BM25 retriever... +2025-10-01 16:36:34,209 - AgenticMedicalRAG - INFO - 🔄 Creating hybrid retriever... +2025-10-01 16:36:34,212 - AgenticMedicalRAG - INFO - ✅ Retrievers initialized successfully. +2025-10-01 16:36:47,584 - AgenticMedicalRAG - INFO - Successfully processed user input: What is the recommended first-line treatment for a... +2025-10-01 16:51:01,133 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-10-01 16:51:02,390 - AgenticMedicalRAG - INFO - Agentic Medical Guidelines Assistant starting... +2025-10-01 16:51:02,391 - AgenticMedicalRAG - INFO - Starting Gradio interface... +2025-10-01 17:46:46,709 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-10-01 17:46:47,940 - AgenticMedicalRAG - INFO - Agentic Medical Guidelines Assistant starting... +2025-10-01 17:46:47,940 - AgenticMedicalRAG - INFO - Starting Gradio interface... +2025-10-01 17:47:00,748 - AgenticMedicalRAG - INFO - Processing user input (attempt 1): What is the recommended first-line treatment for a... +2025-10-01 17:47:00,750 - AgenticMedicalRAG - INFO - Initializing LLM (first time)... +2025-10-01 17:47:01,354 - AgenticMedicalRAG - INFO - LLM initialized successfully +2025-10-01 17:47:36,244 - AgenticMedicalRAG - ERROR - OpenAI API error: Connection error. +2025-10-01 17:47:38,245 - AgenticMedicalRAG - INFO - Processing user input (attempt 2): What is the recommended first-line treatment for a... +2025-10-01 17:48:12,725 - AgenticMedicalRAG - ERROR - OpenAI API error: Connection error. +2025-10-01 17:48:14,726 - AgenticMedicalRAG - INFO - Processing user input (attempt 3): What is the recommended first-line treatment for a... +2025-10-01 17:48:16,023 - AgenticMedicalRAG - ERROR - OpenAI API error: Connection error. +2025-10-01 17:48:18,024 - AgenticMedicalRAG - INFO - Processing user input (attempt 4): What is the recommended first-line treatment for a... +2025-10-01 17:48:19,401 - AgenticMedicalRAG - ERROR - OpenAI API error: Connection error. +2025-10-01 17:54:29,723 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-10-01 17:54:31,131 - AgenticMedicalRAG - INFO - Agentic Medical Guidelines Assistant starting... +2025-10-01 17:54:31,131 - AgenticMedicalRAG - INFO - Starting Gradio interface... +2025-10-01 17:54:42,261 - AgenticMedicalRAG - INFO - Processing user input (attempt 1): What is the recommended first-line treatment for a... +2025-10-01 17:54:42,262 - AgenticMedicalRAG - INFO - Initializing LLM (first time)... +2025-10-01 17:54:42,705 - AgenticMedicalRAG - INFO - LLM initialized successfully +2025-10-01 17:54:46,601 - AgenticMedicalRAG - INFO - 🔄 Initializing retrievers (first time use)... +2025-10-01 17:54:46,601 - AgenticMedicalRAG - INFO - 🔄 Processing new data and updating vector store if needed... +2025-10-01 17:54:46,602 - AgenticMedicalRAG - INFO - Loading embedding model (first time)... +2025-10-01 17:54:58,728 - AgenticMedicalRAG - INFO - Embedding model loaded successfully +2025-10-01 17:54:58,807 - AgenticMedicalRAG - INFO - 📦 Loading chunks cache for BM25 retriever... +2025-10-01 17:54:58,823 - AgenticMedicalRAG - INFO - 🔍 Creating vector retriever... +2025-10-01 17:54:58,824 - AgenticMedicalRAG - INFO - 📝 Creating BM25 retriever... +2025-10-01 17:54:59,051 - AgenticMedicalRAG - INFO - 🔄 Creating hybrid retriever... +2025-10-01 17:54:59,051 - AgenticMedicalRAG - INFO - ✅ Retrievers initialized successfully. +2025-10-01 17:55:18,179 - AgenticMedicalRAG - INFO - Successfully processed user input: What is the recommended first-line treatment for a... +2025-10-01 18:19:14,553 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-10-01 18:19:15,941 - AgenticMedicalRAG - INFO - Agentic Medical Guidelines Assistant starting... +2025-10-01 18:19:15,941 - AgenticMedicalRAG - INFO - Starting Gradio interface... +2025-10-01 18:20:06,582 - AgenticMedicalRAG - INFO - Processing user input (attempt 1): What is the recommended first-line treatment for a... +2025-10-01 18:20:06,585 - AgenticMedicalRAG - INFO - Initializing LLM (first time)... +2025-10-01 18:20:07,180 - AgenticMedicalRAG - INFO - LLM initialized successfully +2025-10-01 18:20:09,729 - AgenticMedicalRAG - INFO - 🔄 Initializing retrievers (first time use)... +2025-10-01 18:20:09,730 - AgenticMedicalRAG - INFO - 🔄 Processing new data and updating vector store if needed... +2025-10-01 18:20:09,731 - AgenticMedicalRAG - INFO - Loading embedding model (first time)... +2025-10-01 18:20:26,724 - AgenticMedicalRAG - INFO - Embedding model loaded successfully +2025-10-01 18:20:26,795 - AgenticMedicalRAG - INFO - 📦 Loading chunks cache for BM25 retriever... +2025-10-01 18:20:26,811 - AgenticMedicalRAG - INFO - 🔍 Creating vector retriever... +2025-10-01 18:20:26,817 - AgenticMedicalRAG - INFO - 📝 Creating BM25 retriever... +2025-10-01 18:20:27,081 - AgenticMedicalRAG - INFO - 🔄 Creating hybrid retriever... +2025-10-01 18:20:27,082 - AgenticMedicalRAG - INFO - ✅ Retrievers initialized successfully. +2025-10-01 18:20:43,455 - AgenticMedicalRAG - INFO - Successfully processed user input: What is the recommended first-line treatment for a... +2025-10-02 18:36:22,090 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-10-02 18:36:23,133 - AgenticMedicalRAG - ERROR - Failed to import required modules: cannot import name 'medical_guidelines_knowledge_tool' from 'tools' (C:\Users\moaze\AppData\Roaming\Python\Python313\site-packages\tools\__init__.py) +2025-10-02 19:37:51,324 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-10-02 19:37:51,755 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-10-02 19:37:55,058 - AgenticMedicalRAG - INFO - Agentic Medical Guidelines Assistant starting... +2025-10-02 19:37:55,058 - AgenticMedicalRAG - INFO - Starting Gradio interface... +2025-10-02 19:38:36,766 - AgenticMedicalRAG - INFO - Processing user input (attempt 1): What is the recommended treatment for stage IV NSC... +2025-10-02 19:38:36,767 - AgenticMedicalRAG - INFO - Initializing LLM (first time)... +2025-10-02 19:38:38,415 - AgenticMedicalRAG - INFO - LLM initialized successfully +2025-10-02 19:38:40,711 - AgenticMedicalRAG - INFO - 🔄 Initializing retrievers (first time use)... +2025-10-02 19:38:40,711 - AgenticMedicalRAG - INFO - 🔄 Processing new data and updating vector store if needed... +2025-10-02 19:38:40,712 - AgenticMedicalRAG - INFO - Loading embedding model (first time)... +2025-10-02 19:38:57,251 - AgenticMedicalRAG - INFO - Embedding model loaded successfully +2025-10-02 19:38:57,821 - AgenticMedicalRAG - INFO - 📦 Loading chunks cache for BM25 retriever... +2025-10-02 19:38:58,358 - AgenticMedicalRAG - INFO - 🔍 Creating vector retriever... +2025-10-02 19:38:58,358 - AgenticMedicalRAG - INFO - 📝 Creating BM25 retriever... +2025-10-02 19:38:58,695 - AgenticMedicalRAG - INFO - 🔄 Creating hybrid retriever... +2025-10-02 19:38:58,696 - AgenticMedicalRAG - INFO - ✅ Retrievers initialized successfully. +2025-10-02 19:39:22,186 - AgenticMedicalRAG - INFO - Initializing LLM (first time)... +2025-10-02 19:39:22,188 - AgenticMedicalRAG - INFO - LLM initialized successfully +2025-10-02 19:39:38,655 - AgenticMedicalRAG - INFO - Successfully processed user input: What is the recommended treatment for stage IV NSC... +2025-10-02 19:45:16,628 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-10-02 19:45:17,072 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-10-02 19:45:17,858 - AgenticMedicalRAG - INFO - Agentic Medical Guidelines Assistant starting... +2025-10-02 19:45:17,859 - AgenticMedicalRAG - INFO - Starting Gradio interface... +2025-10-02 19:45:43,221 - AgenticMedicalRAG - INFO - Processing user input (attempt 1): What is the recommended treatment for stage IV NSC... +2025-10-02 19:45:43,223 - AgenticMedicalRAG - INFO - Initializing LLM (first time)... +2025-10-02 19:45:44,433 - AgenticMedicalRAG - INFO - LLM initialized successfully +2025-10-02 19:45:46,353 - AgenticMedicalRAG - INFO - 🔄 Initializing retrievers (first time use)... +2025-10-02 19:45:46,354 - AgenticMedicalRAG - INFO - 🔄 Processing new data and updating vector store if needed... +2025-10-02 19:45:46,355 - AgenticMedicalRAG - INFO - Loading embedding model (first time)... +2025-10-02 19:45:53,977 - AgenticMedicalRAG - INFO - Embedding model loaded successfully +2025-10-02 19:45:54,065 - AgenticMedicalRAG - INFO - 📦 Loading chunks cache for BM25 retriever... +2025-10-02 19:45:54,386 - AgenticMedicalRAG - INFO - 🔍 Creating vector retriever... +2025-10-02 19:45:54,387 - AgenticMedicalRAG - INFO - 📝 Creating BM25 retriever... +2025-10-02 19:45:54,621 - AgenticMedicalRAG - INFO - 🔄 Creating hybrid retriever... +2025-10-02 19:45:54,621 - AgenticMedicalRAG - INFO - ✅ Retrievers initialized successfully. +2025-10-02 19:46:07,764 - AgenticMedicalRAG - INFO - Initializing LLM (first time)... +2025-10-02 19:46:07,765 - AgenticMedicalRAG - INFO - LLM initialized successfully +2025-10-02 19:47:05,025 - AgenticMedicalRAG - INFO - Successfully processed user input: What is the recommended treatment for stage IV NSC... +2025-10-02 19:58:36,581 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-10-02 19:58:36,996 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-10-02 19:58:37,843 - AgenticMedicalRAG - INFO - Agentic Medical Guidelines Assistant starting... +2025-10-02 19:58:37,843 - AgenticMedicalRAG - INFO - Starting Gradio interface... +2025-10-02 19:58:50,737 - AgenticMedicalRAG - INFO - Processing user input (attempt 1): What is the recommended treatment for stage IV NSC... +2025-10-02 19:58:50,738 - AgenticMedicalRAG - INFO - Initializing LLM (first time)... +2025-10-02 19:58:52,005 - AgenticMedicalRAG - INFO - LLM initialized successfully +2025-10-02 19:58:53,484 - AgenticMedicalRAG - INFO - 🔄 Initializing retrievers (first time use)... +2025-10-02 19:58:53,484 - AgenticMedicalRAG - INFO - 🔄 Processing new data and updating vector store if needed... +2025-10-02 19:58:53,485 - AgenticMedicalRAG - INFO - Loading embedding model (first time)... +2025-10-02 19:59:00,460 - AgenticMedicalRAG - INFO - Embedding model loaded successfully +2025-10-02 19:59:00,537 - AgenticMedicalRAG - INFO - 📦 Loading chunks cache for BM25 retriever... +2025-10-02 19:59:01,072 - AgenticMedicalRAG - INFO - 🔍 Creating vector retriever... +2025-10-02 19:59:01,073 - AgenticMedicalRAG - INFO - 📝 Creating BM25 retriever... +2025-10-02 19:59:01,318 - AgenticMedicalRAG - INFO - 🔄 Creating hybrid retriever... +2025-10-02 19:59:01,319 - AgenticMedicalRAG - INFO - ✅ Retrievers initialized successfully. +2025-10-02 19:59:07,390 - AgenticMedicalRAG - INFO - Initializing LLM (first time)... +2025-10-02 19:59:07,392 - AgenticMedicalRAG - INFO - LLM initialized successfully +2025-10-02 19:59:49,818 - AgenticMedicalRAG - INFO - Successfully processed user input: What is the recommended treatment for stage IV NSC... +2025-10-04 17:52:21,573 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-10-04 17:52:24,124 - AgenticMedicalRAG - INFO - Agentic Medical Guidelines Assistant starting... +2025-10-04 17:52:24,125 - AgenticMedicalRAG - INFO - Starting Gradio interface... +2025-10-04 17:52:58,282 - AgenticMedicalRAG - INFO - Processing user input (attempt 1): What is the recommended first-line treatment for a... +2025-10-04 17:52:58,285 - AgenticMedicalRAG - INFO - Initializing LLM (first time)... +2025-10-04 17:52:59,182 - AgenticMedicalRAG - INFO - LLM initialized successfully +2025-10-04 17:53:01,439 - AgenticMedicalRAG - INFO - 🔄 Initializing retrievers (first time use)... +2025-10-04 17:53:01,439 - AgenticMedicalRAG - INFO - 🔄 Processing new data and updating vector store if needed... +2025-10-04 17:53:01,442 - AgenticMedicalRAG - INFO - Loading embedding model (first time)... +2025-10-04 17:53:23,385 - AgenticMedicalRAG - INFO - Embedding model loaded successfully +2025-10-04 17:53:23,612 - AgenticMedicalRAG - INFO - 📦 Loading chunks cache for BM25 retriever... +2025-10-04 17:53:23,664 - AgenticMedicalRAG - INFO - 🔍 Creating vector retriever... +2025-10-04 17:53:23,664 - AgenticMedicalRAG - INFO - 📝 Creating BM25 retriever... +2025-10-04 17:53:24,021 - AgenticMedicalRAG - INFO - 🔄 Creating hybrid retriever... +2025-10-04 17:53:24,023 - AgenticMedicalRAG - INFO - ✅ Retrievers initialized successfully. +2025-10-04 17:53:30,195 - AgenticMedicalRAG - INFO - Performing automatic validation for streaming response... +2025-10-04 17:53:35,609 - AgenticMedicalRAG - ERROR - Failed to parse validation JSON: Expecting value: line 1 column 1 (char 0) +2025-10-04 17:53:35,976 - AgenticMedicalRAG - INFO - Evaluation saved with ID: baf04454-fd01-48b3-9375-8a409059d824 +2025-10-04 17:53:36,977 - AgenticMedicalRAG - INFO - Successfully processed user input: What is the recommended first-line treatment for a... +2025-10-04 18:15:53,482 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-10-04 18:15:54,905 - AgenticMedicalRAG - INFO - Agentic Medical Guidelines Assistant starting... +2025-10-04 18:15:54,906 - AgenticMedicalRAG - INFO - Starting Gradio interface... +2025-10-04 18:16:05,158 - AgenticMedicalRAG - INFO - Processing user input (attempt 1): What is the recommended first-line treatment for a... +2025-10-04 18:16:05,161 - AgenticMedicalRAG - INFO - Initializing LLM (first time)... +2025-10-04 18:16:05,981 - AgenticMedicalRAG - INFO - LLM initialized successfully +2025-10-04 18:16:08,123 - AgenticMedicalRAG - INFO - 🔄 Initializing retrievers (first time use)... +2025-10-04 18:16:08,124 - AgenticMedicalRAG - INFO - 🔄 Processing new data and updating vector store if needed... +2025-10-04 18:16:08,125 - AgenticMedicalRAG - INFO - Loading embedding model (first time)... +2025-10-04 18:16:21,368 - AgenticMedicalRAG - INFO - Embedding model loaded successfully +2025-10-04 18:16:21,430 - AgenticMedicalRAG - INFO - 📦 Loading chunks cache for BM25 retriever... +2025-10-04 18:16:21,446 - AgenticMedicalRAG - INFO - 🔍 Creating vector retriever... +2025-10-04 18:16:21,448 - AgenticMedicalRAG - INFO - 📝 Creating BM25 retriever... +2025-10-04 18:16:21,729 - AgenticMedicalRAG - INFO - 🔄 Creating hybrid retriever... +2025-10-04 18:16:21,730 - AgenticMedicalRAG - INFO - ✅ Retrievers initialized successfully. +2025-10-04 18:16:26,987 - AgenticMedicalRAG - INFO - Performing automatic validation for streaming response... +2025-10-04 18:16:33,282 - AgenticMedicalRAG - INFO - Evaluation saved with ID: 84ea1f44-9fed-49d1-a5d8-1656bdb3e704 +2025-10-04 18:16:35,149 - AgenticMedicalRAG - INFO - Successfully processed user input: What is the recommended first-line treatment for a... +2025-10-04 19:30:07,921 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-10-04 19:30:09,618 - AgenticMedicalRAG - INFO - Agentic Medical Guidelines Assistant starting... +2025-10-04 19:30:09,619 - AgenticMedicalRAG - INFO - Starting Gradio interface... +2025-10-04 19:30:34,744 - AgenticMedicalRAG - INFO - Processing user input (attempt 1): What is the recommended first-line treatment for a... +2025-10-04 19:30:34,745 - AgenticMedicalRAG - INFO - Initializing LLM (first time)... +2025-10-04 19:30:35,398 - AgenticMedicalRAG - INFO - LLM initialized successfully +2025-10-04 19:30:37,778 - AgenticMedicalRAG - INFO - 🔄 Initializing retrievers (first time use)... +2025-10-04 19:30:37,779 - AgenticMedicalRAG - INFO - 🔄 Processing new data and updating vector store if needed... +2025-10-04 19:30:37,779 - AgenticMedicalRAG - INFO - Loading embedding model (first time)... +2025-10-04 19:30:57,624 - AgenticMedicalRAG - INFO - Embedding model loaded successfully +2025-10-04 19:30:57,767 - AgenticMedicalRAG - INFO - 📦 Loading chunks cache for BM25 retriever... +2025-10-04 19:30:57,799 - AgenticMedicalRAG - INFO - 🔍 Creating vector retriever... +2025-10-04 19:30:57,801 - AgenticMedicalRAG - INFO - 📝 Creating BM25 retriever... +2025-10-04 19:30:58,199 - AgenticMedicalRAG - INFO - 🔄 Creating hybrid retriever... +2025-10-04 19:30:58,200 - AgenticMedicalRAG - INFO - ✅ Retrievers initialized successfully. +2025-10-04 19:31:03,763 - AgenticMedicalRAG - INFO - Performing automatic validation for streaming response... +2025-10-04 19:31:03,814 - AgenticMedicalRAG - INFO - Medical answer validator initialized successfully +2025-10-04 19:31:03,815 - AgenticMedicalRAG - ERROR - Error getting next interaction ID: Expecting value: line 1 column 1 (char 0) +2025-10-04 19:31:03,815 - AgenticMedicalRAG - INFO - Starting validation for interaction 1 +2025-10-04 19:31:09,350 - AgenticMedicalRAG - INFO - Evaluation saved with ID: 1 +2025-10-04 19:31:16,710 - AgenticMedicalRAG - INFO - Successfully processed user input: What is the recommended first-line treatment for a... +2025-10-04 19:31:51,524 - AgenticMedicalRAG - INFO - Processing user input (attempt 1): What is the recommended first-line treatment for a... +2025-10-04 19:31:56,979 - AgenticMedicalRAG - INFO - Performing automatic validation for streaming response... +2025-10-04 19:31:56,982 - AgenticMedicalRAG - INFO - Starting validation for interaction 2 +2025-10-04 19:32:03,912 - AgenticMedicalRAG - INFO - Evaluation saved with ID: 2 +2025-10-05 09:39:56,512 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-10-05 09:39:58,032 - AgenticMedicalRAG - INFO - Agentic Medical Guidelines Assistant starting... +2025-10-05 09:39:58,033 - AgenticMedicalRAG - INFO - Starting Gradio interface... +2025-10-05 09:40:38,205 - AgenticMedicalRAG - INFO - Processing user input (attempt 1): What is the recommended first-line treatment for a... +2025-10-05 09:40:38,207 - AgenticMedicalRAG - INFO - Initializing LLM (first time)... +2025-10-05 09:40:39,060 - AgenticMedicalRAG - INFO - LLM initialized successfully +2025-10-05 09:40:41,242 - AgenticMedicalRAG - INFO - 🔄 Initializing retrievers (first time use)... +2025-10-05 09:40:41,243 - AgenticMedicalRAG - INFO - 🔄 Processing new data and updating vector store if needed... +2025-10-05 09:40:41,244 - AgenticMedicalRAG - INFO - Loading embedding model (first time)... +2025-10-05 09:41:01,277 - AgenticMedicalRAG - INFO - Embedding model loaded successfully +2025-10-05 09:41:01,467 - AgenticMedicalRAG - INFO - 📦 Loading chunks cache for BM25 retriever... +2025-10-05 09:41:01,489 - AgenticMedicalRAG - INFO - 🔍 Creating vector retriever... +2025-10-05 09:41:01,489 - AgenticMedicalRAG - INFO - 📝 Creating BM25 retriever... +2025-10-05 09:41:01,845 - AgenticMedicalRAG - INFO - 🔄 Creating hybrid retriever... +2025-10-05 09:41:01,846 - AgenticMedicalRAG - INFO - ✅ Retrievers initialized successfully. +2025-10-05 09:41:08,060 - AgenticMedicalRAG - INFO - Performing automatic validation for streaming response... +2025-10-05 09:41:08,094 - AgenticMedicalRAG - INFO - Medical answer validator initialized successfully +2025-10-05 09:41:08,096 - AgenticMedicalRAG - ERROR - Error getting next interaction ID: Expecting value: line 1 column 1 (char 0) +2025-10-05 09:41:08,096 - AgenticMedicalRAG - INFO - Starting validation for interaction 1 +2025-10-05 09:41:13,992 - AgenticMedicalRAG - INFO - Evaluation saved with ID: 1 +2025-10-05 09:41:20,334 - AgenticMedicalRAG - INFO - Successfully processed user input: What is the recommended first-line treatment for a... +2025-10-05 09:54:30,977 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-10-05 09:54:32,796 - AgenticMedicalRAG - INFO - Agentic Medical Guidelines Assistant starting... +2025-10-05 09:54:32,796 - AgenticMedicalRAG - INFO - 🚀 Starting background initialization of components... +2025-10-05 09:54:32,797 - AgenticMedicalRAG - INFO - 🚀 Starting background initialization... +2025-10-05 09:54:32,798 - AgenticMedicalRAG - INFO - 🔄 Background Init: Starting background initialization... (0%) +2025-10-05 09:54:32,799 - AgenticMedicalRAG - INFO - Starting Gradio interface... +2025-10-05 09:54:32,799 - AgenticMedicalRAG - INFO - 🔄 Background Init: Loading embedding model... (10%) +2025-10-05 09:54:32,804 - AgenticMedicalRAG - INFO - Loading embedding model (first time)... +2025-10-05 09:54:32,935 - AgenticMedicalRAG - ERROR - Failed to launch Gradio: EventListener._setup..event_trigger() got an unexpected keyword argument 'every' +2025-10-05 10:10:31,814 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-10-05 10:10:33,865 - AgenticMedicalRAG - INFO - Agentic Medical Guidelines Assistant starting... +2025-10-05 10:10:33,865 - AgenticMedicalRAG - INFO - 🚀 Starting background initialization of components... +2025-10-05 10:10:33,865 - AgenticMedicalRAG - INFO - 🚀 Starting background initialization... +2025-10-05 10:10:33,867 - AgenticMedicalRAG - INFO - 🔄 Background Init: Starting background initialization... (0%) +2025-10-05 10:10:33,867 - AgenticMedicalRAG - INFO - Starting Gradio interface... +2025-10-05 10:10:33,868 - AgenticMedicalRAG - INFO - 🔄 Background Init: Loading embedding model... (10%) +2025-10-05 10:10:33,871 - AgenticMedicalRAG - INFO - Loading embedding model (first time)... +2025-10-05 10:10:56,627 - AgenticMedicalRAG - INFO - Processing user input (attempt 1): What is the recommended first-line treatment for a... +2025-10-05 10:10:56,630 - AgenticMedicalRAG - INFO - Initializing LLM (first time)... +2025-10-05 10:10:56,902 - AgenticMedicalRAG - INFO - Embedding model loaded successfully +2025-10-05 10:10:56,903 - AgenticMedicalRAG - INFO - 🔄 Background Init: Embedding model loaded successfully (40%) +2025-10-05 10:10:56,905 - AgenticMedicalRAG - INFO - 🔄 Background Init: Initializing retrievers and loading chunks... (50%) +2025-10-05 10:10:56,905 - AgenticMedicalRAG - INFO - 🔄 Initializing retrievers (first time use)... +2025-10-05 10:10:56,908 - AgenticMedicalRAG - INFO - 🔄 Processing new data and updating vector store if needed... +2025-10-05 10:10:57,066 - AgenticMedicalRAG - INFO - 📦 Loading chunks cache for BM25 retriever... +2025-10-05 10:10:57,121 - AgenticMedicalRAG - INFO - 🔍 Creating vector retriever... +2025-10-05 10:10:57,123 - AgenticMedicalRAG - INFO - 📝 Creating BM25 retriever... +2025-10-05 10:10:57,678 - AgenticMedicalRAG - INFO - 🔄 Creating hybrid retriever... +2025-10-05 10:10:57,680 - AgenticMedicalRAG - INFO - ✅ Retrievers initialized successfully. +2025-10-05 10:10:57,680 - AgenticMedicalRAG - INFO - 🔄 Background Init: Retrievers initialized successfully (90%) +2025-10-05 10:10:57,681 - AgenticMedicalRAG - INFO - 🔄 Background Init: Warming up LLM... (95%) +2025-10-05 10:10:57,681 - AgenticMedicalRAG - INFO - Initializing LLM (first time)... +2025-10-05 10:10:58,050 - AgenticMedicalRAG - INFO - LLM initialized successfully +2025-10-05 10:10:58,050 - AgenticMedicalRAG - INFO - LLM initialized successfully +2025-10-05 10:10:58,050 - AgenticMedicalRAG - INFO - 🔄 Background Init: All components initialized successfully (100%) +2025-10-05 10:10:58,076 - AgenticMedicalRAG - INFO - ✅ Background initialization completed successfully +2025-10-05 10:11:06,112 - AgenticMedicalRAG - INFO - Performing automatic validation for streaming response... +2025-10-05 10:11:06,149 - AgenticMedicalRAG - INFO - Medical answer validator initialized successfully +2025-10-05 10:11:06,157 - AgenticMedicalRAG - INFO - Starting validation for interaction 2 +2025-10-05 10:11:11,523 - AgenticMedicalRAG - INFO - Evaluation saved with ID: 2 +2025-10-05 10:11:18,164 - AgenticMedicalRAG - INFO - Successfully processed user input: What is the recommended first-line treatment for a... +2025-10-05 10:13:35,677 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-10-05 10:14:15,795 - AgenticMedicalRAG - INFO - Processing user input (attempt 1): What is the recommended first-line treatment for a... +2025-10-05 10:14:15,795 - AgenticMedicalRAG - INFO - Initializing LLM (first time)... +2025-10-05 10:14:16,303 - AgenticMedicalRAG - INFO - LLM initialized successfully +2025-10-05 10:14:18,160 - AgenticMedicalRAG - INFO - 🔄 Initializing retrievers (first time use)... +2025-10-05 10:14:18,161 - AgenticMedicalRAG - INFO - 🔄 Processing new data and updating vector store if needed... +2025-10-05 10:14:18,163 - AgenticMedicalRAG - INFO - Loading embedding model (first time)... +2025-10-05 10:14:34,085 - AgenticMedicalRAG - INFO - Embedding model loaded successfully +2025-10-05 10:14:34,163 - AgenticMedicalRAG - INFO - 📦 Loading chunks cache for BM25 retriever... +2025-10-05 10:14:34,189 - AgenticMedicalRAG - INFO - 🔍 Creating vector retriever... +2025-10-05 10:14:34,189 - AgenticMedicalRAG - INFO - 📝 Creating BM25 retriever... +2025-10-05 10:14:34,478 - AgenticMedicalRAG - INFO - 🔄 Creating hybrid retriever... +2025-10-05 10:14:34,479 - AgenticMedicalRAG - INFO - ✅ Retrievers initialized successfully. +2025-10-05 10:14:40,213 - AgenticMedicalRAG - INFO - Successfully processed user input: What is the recommended first-line treatment for a... +2025-10-05 10:14:40,213 - AgenticMedicalRAG - INFO - Performing automatic validation... +2025-10-05 10:14:40,261 - AgenticMedicalRAG - INFO - Medical answer validator initialized successfully +2025-10-05 10:14:40,262 - AgenticMedicalRAG - ERROR - Error getting next interaction ID: Expecting value: line 1 column 1 (char 0) +2025-10-05 10:14:40,262 - AgenticMedicalRAG - INFO - Starting validation for interaction 1 +2025-10-05 10:14:47,368 - AgenticMedicalRAG - INFO - Evaluation saved with ID: 1 +2025-10-05 10:17:21,663 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-10-05 10:17:22,909 - AgenticMedicalRAG - INFO - 🚀 Starting background initialization... +2025-10-05 10:17:22,911 - AgenticMedicalRAG - INFO - 🔄 Background Init: Starting background initialization... (0%) +2025-10-05 10:17:22,911 - AgenticMedicalRAG - INFO - 🔄 Background Init: Loading embedding model... (10%) +2025-10-05 10:17:22,913 - AgenticMedicalRAG - INFO - Loading embedding model (first time)... +2025-10-05 10:17:39,692 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-10-05 10:17:40,915 - AgenticMedicalRAG - INFO - 🚀 Starting background initialization... +2025-10-05 10:17:40,915 - AgenticMedicalRAG - INFO - 🔄 Background Init: Starting background initialization... (0%) +2025-10-05 10:17:40,916 - AgenticMedicalRAG - INFO - 🔄 Background Init: Loading embedding model... (10%) +2025-10-05 10:17:40,918 - AgenticMedicalRAG - INFO - Loading embedding model (first time)... +2025-10-05 10:17:46,054 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-10-05 10:17:47,256 - AgenticMedicalRAG - INFO - 🚀 Starting background initialization... +2025-10-05 10:17:47,257 - AgenticMedicalRAG - INFO - 🔄 Background Init: Starting background initialization... (0%) +2025-10-05 10:17:47,259 - AgenticMedicalRAG - INFO - 🔄 Background Init: Loading embedding model... (10%) +2025-10-05 10:17:47,259 - AgenticMedicalRAG - INFO - Loading embedding model (first time)... +2025-10-05 10:17:56,489 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-10-05 10:17:57,616 - AgenticMedicalRAG - INFO - 🚀 Starting background initialization... +2025-10-05 10:17:57,618 - AgenticMedicalRAG - INFO - 🔄 Background Init: Starting background initialization... (0%) +2025-10-05 10:17:57,618 - AgenticMedicalRAG - INFO - 🔄 Background Init: Loading embedding model... (10%) +2025-10-05 10:17:57,619 - AgenticMedicalRAG - INFO - Loading embedding model (first time)... +2025-10-05 10:18:06,637 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-10-05 10:18:07,880 - AgenticMedicalRAG - INFO - 🚀 Starting background initialization... +2025-10-05 10:18:07,882 - AgenticMedicalRAG - INFO - 🔄 Background Init: Starting background initialization... (0%) +2025-10-05 10:18:07,883 - AgenticMedicalRAG - INFO - 🔄 Background Init: Loading embedding model... (10%) +2025-10-05 10:18:07,884 - AgenticMedicalRAG - INFO - Loading embedding model (first time)... +2025-10-05 10:18:13,761 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-10-05 10:18:14,869 - AgenticMedicalRAG - INFO - 🚀 Starting background initialization... +2025-10-05 10:18:14,870 - AgenticMedicalRAG - INFO - 🔄 Background Init: Starting background initialization... (0%) +2025-10-05 10:18:14,871 - AgenticMedicalRAG - INFO - 🔄 Background Init: Loading embedding model... (10%) +2025-10-05 10:18:14,872 - AgenticMedicalRAG - INFO - Loading embedding model (first time)... +2025-10-05 10:18:33,045 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-10-05 10:18:34,261 - AgenticMedicalRAG - INFO - 🚀 Starting background initialization... +2025-10-05 10:18:34,262 - AgenticMedicalRAG - INFO - 🔄 Background Init: Starting background initialization... (0%) +2025-10-05 10:18:34,264 - AgenticMedicalRAG - INFO - 🔄 Background Init: Loading embedding model... (10%) +2025-10-05 10:18:34,265 - AgenticMedicalRAG - INFO - Loading embedding model (first time)... +2025-10-05 10:18:50,081 - AgenticMedicalRAG - INFO - Embedding model loaded successfully +2025-10-05 10:18:50,081 - AgenticMedicalRAG - INFO - 🔄 Background Init: Embedding model loaded successfully (40%) +2025-10-05 10:18:50,082 - AgenticMedicalRAG - INFO - 🔄 Background Init: Initializing retrievers and loading chunks... (50%) +2025-10-05 10:18:50,082 - AgenticMedicalRAG - INFO - 🔄 Initializing retrievers (first time use)... +2025-10-05 10:18:50,083 - AgenticMedicalRAG - INFO - 🔄 Processing new data and updating vector store if needed... +2025-10-05 10:18:50,167 - AgenticMedicalRAG - INFO - 📦 Loading chunks cache for BM25 retriever... +2025-10-05 10:18:50,193 - AgenticMedicalRAG - INFO - 🔍 Creating vector retriever... +2025-10-05 10:18:50,194 - AgenticMedicalRAG - INFO - 📝 Creating BM25 retriever... +2025-10-05 10:18:50,495 - AgenticMedicalRAG - INFO - 🔄 Creating hybrid retriever... +2025-10-05 10:18:50,496 - AgenticMedicalRAG - INFO - ✅ Retrievers initialized successfully. +2025-10-05 10:18:50,496 - AgenticMedicalRAG - INFO - 🔄 Background Init: Retrievers initialized successfully (90%) +2025-10-05 10:18:50,497 - AgenticMedicalRAG - INFO - 🔄 Background Init: Warming up LLM... (95%) +2025-10-05 10:18:50,498 - AgenticMedicalRAG - INFO - Initializing LLM (first time)... +2025-10-05 10:18:50,912 - AgenticMedicalRAG - INFO - LLM initialized successfully +2025-10-05 10:18:50,912 - AgenticMedicalRAG - INFO - 🔄 Background Init: All components initialized successfully (100%) +2025-10-05 10:18:50,913 - AgenticMedicalRAG - INFO - ✅ Background initialization completed successfully +2025-10-05 11:25:34,292 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-10-05 11:25:35,291 - AgenticMedicalRAG - INFO - 🚀 Starting background initialization... +2025-10-05 11:25:35,292 - AgenticMedicalRAG - INFO - 🔄 Background Init: Starting background initialization... (0%) +2025-10-05 11:25:35,292 - AgenticMedicalRAG - INFO - 🔄 Background Init: Loading embedding model... (10%) +2025-10-05 11:25:35,293 - AgenticMedicalRAG - INFO - Loading embedding model (first time)... +2025-10-05 11:25:52,708 - AgenticMedicalRAG - INFO - Embedding model loaded successfully +2025-10-05 11:25:52,709 - AgenticMedicalRAG - INFO - 🔄 Background Init: Embedding model loaded successfully (40%) +2025-10-05 11:25:52,710 - AgenticMedicalRAG - INFO - 🔄 Background Init: Initializing retrievers and loading chunks... (50%) +2025-10-05 11:25:52,710 - AgenticMedicalRAG - INFO - 🔄 Initializing retrievers (first time use)... +2025-10-05 11:25:52,710 - AgenticMedicalRAG - INFO - 🔄 Processing new data and updating vector store if needed... +2025-10-05 11:25:52,815 - AgenticMedicalRAG - INFO - 📦 Loading chunks cache for BM25 retriever... +2025-10-05 11:25:52,844 - AgenticMedicalRAG - INFO - 🔍 Creating vector retriever... +2025-10-05 11:25:52,845 - AgenticMedicalRAG - INFO - 📝 Creating BM25 retriever... +2025-10-05 11:25:53,231 - AgenticMedicalRAG - INFO - 🔄 Creating hybrid retriever... +2025-10-05 11:25:53,232 - AgenticMedicalRAG - INFO - ✅ Retrievers initialized successfully. +2025-10-05 11:25:53,232 - AgenticMedicalRAG - INFO - 🔄 Background Init: Retrievers initialized successfully (90%) +2025-10-05 11:25:53,232 - AgenticMedicalRAG - INFO - 🔄 Background Init: Warming up LLM... (95%) +2025-10-05 11:25:53,234 - AgenticMedicalRAG - INFO - Initializing LLM (first time)... +2025-10-05 11:25:53,701 - AgenticMedicalRAG - INFO - LLM initialized successfully +2025-10-05 11:25:53,702 - AgenticMedicalRAG - INFO - 🔄 Background Init: All components initialized successfully (100%) +2025-10-05 11:25:53,702 - AgenticMedicalRAG - INFO - ✅ Background initialization completed successfully +2025-10-05 11:25:55,088 - AgenticMedicalRAG - INFO - Processing user input (attempt 1): What is the recommended first-line treatment for a... +2025-10-05 11:26:02,082 - AgenticMedicalRAG - INFO - Successfully processed user input: What is the recommended first-line treatment for a... +2025-10-05 11:26:02,083 - AgenticMedicalRAG - INFO - Performing automatic validation... +2025-10-05 11:26:02,128 - AgenticMedicalRAG - INFO - Medical answer validator initialized successfully +2025-10-05 11:26:02,129 - AgenticMedicalRAG - INFO - Starting validation for interaction 2 +2025-10-05 11:26:08,987 - AgenticMedicalRAG - INFO - Evaluation saved with ID: 2 +2025-10-05 14:33:57,468 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-10-05 14:33:59,620 - AgenticMedicalRAG - INFO - Agentic Medical Guidelines Assistant starting... +2025-10-05 14:33:59,621 - AgenticMedicalRAG - INFO - 🚀 Starting background initialization of components... +2025-10-05 14:33:59,621 - AgenticMedicalRAG - INFO - 🚀 Starting background initialization... +2025-10-05 14:33:59,622 - AgenticMedicalRAG - INFO - 🔄 Background Init: Starting background initialization... (0%) +2025-10-05 14:33:59,622 - AgenticMedicalRAG - INFO - Starting Gradio interface... +2025-10-05 14:33:59,623 - AgenticMedicalRAG - INFO - 🔄 Background Init: Loading embedding model... (10%) +2025-10-05 14:33:59,626 - AgenticMedicalRAG - INFO - Loading embedding model (first time)... +2025-10-05 14:34:19,485 - AgenticMedicalRAG - INFO - Processing user input (attempt 1): What is the recommended first-line treatment for a... +2025-10-05 14:34:19,489 - AgenticMedicalRAG - INFO - Initializing LLM (first time)... +2025-10-05 14:34:19,650 - AgenticMedicalRAG - INFO - Embedding model loaded successfully +2025-10-05 14:34:19,651 - AgenticMedicalRAG - INFO - 🔄 Background Init: Embedding model loaded successfully (40%) +2025-10-05 14:34:19,652 - AgenticMedicalRAG - INFO - 🔄 Background Init: Initializing retrievers and loading chunks... (50%) +2025-10-05 14:34:19,653 - AgenticMedicalRAG - INFO - 🔄 Initializing retrievers (first time use)... +2025-10-05 14:34:19,653 - AgenticMedicalRAG - INFO - 🔄 Processing new data and updating vector store if needed... +2025-10-05 14:34:19,968 - AgenticMedicalRAG - INFO - 📦 Loading chunks cache for BM25 retriever... +2025-10-05 14:34:20,048 - AgenticMedicalRAG - INFO - 🔍 Creating vector retriever... +2025-10-05 14:34:20,051 - AgenticMedicalRAG - INFO - 📝 Creating BM25 retriever... +2025-10-05 14:34:20,480 - AgenticMedicalRAG - INFO - 🔄 Creating hybrid retriever... +2025-10-05 14:34:20,482 - AgenticMedicalRAG - INFO - ✅ Retrievers initialized successfully. +2025-10-05 14:34:20,482 - AgenticMedicalRAG - INFO - 🔄 Background Init: Retrievers initialized successfully (90%) +2025-10-05 14:34:20,482 - AgenticMedicalRAG - INFO - 🔄 Background Init: Warming up LLM... (95%) +2025-10-05 14:34:20,482 - AgenticMedicalRAG - INFO - Initializing LLM (first time)... +2025-10-05 14:34:20,844 - AgenticMedicalRAG - INFO - LLM initialized successfully +2025-10-05 14:34:20,844 - AgenticMedicalRAG - INFO - 🔄 Background Init: All components initialized successfully (100%) +2025-10-05 14:34:20,845 - AgenticMedicalRAG - INFO - ✅ Background initialization completed successfully +2025-10-05 14:34:20,848 - AgenticMedicalRAG - INFO - LLM initialized successfully +2025-10-05 14:34:27,587 - AgenticMedicalRAG - INFO - Performing automatic validation for streaming response... +2025-10-05 14:34:27,629 - AgenticMedicalRAG - INFO - Medical answer validator initialized successfully +2025-10-05 14:34:27,652 - AgenticMedicalRAG - INFO - Starting validation for interaction 3 +2025-10-05 14:34:34,486 - AgenticMedicalRAG - INFO - Evaluation saved with ID: 3 +2025-10-05 14:34:41,592 - AgenticMedicalRAG - INFO - Successfully processed user input: What is the recommended first-line treatment for a... +2025-10-05 17:59:55,233 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-10-05 17:59:56,921 - AgenticMedicalRAG - INFO - Agentic Medical Guidelines Assistant starting... +2025-10-05 17:59:56,921 - AgenticMedicalRAG - INFO - 🚀 Starting background initialization of components... +2025-10-05 17:59:56,922 - AgenticMedicalRAG - INFO - 🚀 Starting background initialization... +2025-10-05 17:59:56,922 - AgenticMedicalRAG - INFO - 🔄 Background Init: Starting background initialization... (0%) +2025-10-05 17:59:56,923 - AgenticMedicalRAG - INFO - Starting Gradio interface... +2025-10-05 17:59:56,923 - AgenticMedicalRAG - INFO - 🔄 Background Init: Loading embedding model... (10%) +2025-10-05 17:59:56,926 - AgenticMedicalRAG - INFO - Loading embedding model (first time)... +2025-10-05 18:00:15,260 - AgenticMedicalRAG - INFO - Embedding model loaded successfully +2025-10-05 18:00:15,261 - AgenticMedicalRAG - INFO - 🔄 Background Init: Embedding model loaded successfully (40%) +2025-10-05 18:00:15,262 - AgenticMedicalRAG - INFO - 🔄 Background Init: Initializing retrievers and loading chunks... (50%) +2025-10-05 18:00:15,263 - AgenticMedicalRAG - INFO - 🔄 Initializing retrievers (first time use)... +2025-10-05 18:00:15,263 - AgenticMedicalRAG - INFO - 🔄 Processing new data and updating vector store if needed... +2025-10-05 18:00:15,369 - AgenticMedicalRAG - INFO - 📦 Loading chunks cache for BM25 retriever... +2025-10-05 18:00:15,392 - AgenticMedicalRAG - INFO - 🔍 Creating vector retriever... +2025-10-05 18:00:15,393 - AgenticMedicalRAG - INFO - 📝 Creating BM25 retriever... +2025-10-05 18:00:15,773 - AgenticMedicalRAG - INFO - 🔄 Creating hybrid retriever... +2025-10-05 18:00:15,774 - AgenticMedicalRAG - INFO - ✅ Retrievers initialized successfully. +2025-10-05 18:00:15,774 - AgenticMedicalRAG - INFO - 🔄 Background Init: Retrievers initialized successfully (90%) +2025-10-05 18:00:15,774 - AgenticMedicalRAG - INFO - 🔄 Background Init: Warming up LLM... (95%) +2025-10-05 18:00:15,774 - AgenticMedicalRAG - INFO - Initializing LLM (first time)... +2025-10-05 18:00:16,236 - AgenticMedicalRAG - INFO - LLM initialized successfully +2025-10-05 18:00:16,238 - AgenticMedicalRAG - INFO - 🔄 Background Init: All components initialized successfully (100%) +2025-10-05 18:00:16,239 - AgenticMedicalRAG - INFO - ✅ Background initialization completed successfully +2025-10-05 18:00:19,958 - AgenticMedicalRAG - INFO - Processing user input (attempt 1): i found that Afinitor has these side effects feve... +2025-10-05 18:00:25,273 - AgenticMedicalRAG - INFO - Performing automatic validation for streaming response... +2025-10-05 18:00:25,273 - AgenticMedicalRAG - INFO - Skipping validation: insufficient context +2025-10-05 18:00:25,275 - AgenticMedicalRAG - INFO - Successfully processed user input: i found that Afinitor has these side effects feve... +2025-10-05 18:01:23,852 - AgenticMedicalRAG - INFO - Processing user input (attempt 1): Patient's age : 55 +Patient's gender Male +Medicatio... +2025-10-05 18:01:27,947 - AgenticMedicalRAG - INFO - Successfully processed user input: Patient's age : 55 +Patient's gender Male +Medicatio... +2025-10-05 19:43:38,412 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-10-05 19:44:38,933 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-10-05 19:47:09,786 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-10-05 19:51:49,611 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-10-05 19:51:51,290 - AgenticMedicalRAG - INFO - Agentic Medical Guidelines Assistant starting... +2025-10-05 19:51:51,290 - AgenticMedicalRAG - INFO - 🚀 Starting background initialization of components... +2025-10-05 19:51:51,290 - AgenticMedicalRAG - INFO - 🚀 Starting background initialization... +2025-10-05 19:51:51,290 - AgenticMedicalRAG - INFO - 🔄 Background Init: Starting background initialization... (0%) +2025-10-05 19:51:51,290 - AgenticMedicalRAG - INFO - Starting Gradio interface... +2025-10-05 19:51:51,292 - AgenticMedicalRAG - INFO - 🔄 Background Init: Loading embedding model... (10%) +2025-10-05 19:51:51,292 - AgenticMedicalRAG - INFO - Loading embedding model (first time)... +2025-10-05 19:52:04,282 - AgenticMedicalRAG - INFO - Embedding model loaded successfully +2025-10-05 19:52:04,283 - AgenticMedicalRAG - INFO - 🔄 Background Init: Embedding model loaded successfully (40%) +2025-10-05 19:52:04,284 - AgenticMedicalRAG - INFO - 🔄 Background Init: Initializing retrievers and loading chunks... (50%) +2025-10-05 19:52:04,284 - AgenticMedicalRAG - INFO - 🔄 Initializing retrievers (first time use)... +2025-10-05 19:52:04,284 - AgenticMedicalRAG - INFO - 🔄 Processing new data and updating vector store if needed... +2025-10-05 19:52:04,392 - AgenticMedicalRAG - INFO - 📦 Loading chunks cache for BM25 retriever... +2025-10-05 19:52:04,402 - AgenticMedicalRAG - INFO - 🔍 Creating vector retriever... +2025-10-05 19:52:04,403 - AgenticMedicalRAG - INFO - 📝 Creating BM25 retriever... +2025-10-05 19:52:04,586 - AgenticMedicalRAG - INFO - 🔄 Creating hybrid retriever... +2025-10-05 19:52:04,586 - AgenticMedicalRAG - INFO - ✅ Retrievers initialized successfully. +2025-10-05 19:52:04,587 - AgenticMedicalRAG - INFO - 🔄 Background Init: Retrievers initialized successfully (90%) +2025-10-05 19:52:04,587 - AgenticMedicalRAG - INFO - 🔄 Background Init: Warming up LLM... (95%) +2025-10-05 19:52:04,587 - AgenticMedicalRAG - INFO - Initializing LLM (first time)... +2025-10-05 19:52:04,893 - AgenticMedicalRAG - INFO - LLM initialized successfully +2025-10-05 19:52:04,894 - AgenticMedicalRAG - INFO - 🔄 Background Init: All components initialized successfully (100%) +2025-10-05 19:52:04,894 - AgenticMedicalRAG - INFO - ✅ Background initialization completed successfully +2025-10-05 19:52:12,655 - AgenticMedicalRAG - INFO - Processing user input (attempt 1): i found that Afinitor has these side effects fever... +2025-10-05 19:52:16,603 - AgenticMedicalRAG - INFO - Performing automatic validation for streaming response... +2025-10-05 19:52:16,604 - AgenticMedicalRAG - INFO - Skipping validation: insufficient context +2025-10-05 19:52:16,604 - AgenticMedicalRAG - INFO - Successfully processed user input: i found that Afinitor has these side effects fever... +2025-10-05 19:52:30,710 - AgenticMedicalRAG - INFO - Processing user input (attempt 1): Patient's age : 55 +Patient's gender Male +Medicatio... +2025-10-05 19:55:05,153 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-10-05 19:57:10,249 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-10-05 19:57:10,249 - AgenticMedicalRAG - ERROR - Failed to initialize Google Drive storage: Expecting property name enclosed in double quotes: line 9 column 3 (char 413) +2025-10-05 19:57:10,419 - AgenticMedicalRAG - INFO - Side effects report saved locally: side_effects_reports.csv +2025-10-05 19:57:28,160 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-10-05 19:57:29,173 - AgenticMedicalRAG - INFO - Agentic Medical Guidelines Assistant starting... +2025-10-05 19:57:29,173 - AgenticMedicalRAG - INFO - 🚀 Starting background initialization of components... +2025-10-05 19:57:29,173 - AgenticMedicalRAG - INFO - 🚀 Starting background initialization... +2025-10-05 19:57:29,173 - AgenticMedicalRAG - INFO - 🔄 Background Init: Starting background initialization... (0%) +2025-10-05 19:57:29,173 - AgenticMedicalRAG - INFO - Starting Gradio interface... +2025-10-05 19:57:29,173 - AgenticMedicalRAG - INFO - 🔄 Background Init: Loading embedding model... (10%) +2025-10-05 19:57:29,176 - AgenticMedicalRAG - INFO - Loading embedding model (first time)... +2025-10-05 19:57:39,609 - AgenticMedicalRAG - INFO - Embedding model loaded successfully +2025-10-05 19:57:39,610 - AgenticMedicalRAG - INFO - 🔄 Background Init: Embedding model loaded successfully (40%) +2025-10-05 19:57:39,610 - AgenticMedicalRAG - INFO - 🔄 Background Init: Initializing retrievers and loading chunks... (50%) +2025-10-05 19:57:39,611 - AgenticMedicalRAG - INFO - 🔄 Initializing retrievers (first time use)... +2025-10-05 19:57:39,611 - AgenticMedicalRAG - INFO - 🔄 Processing new data and updating vector store if needed... +2025-10-05 19:57:39,651 - AgenticMedicalRAG - INFO - 📦 Loading chunks cache for BM25 retriever... +2025-10-05 19:57:39,661 - AgenticMedicalRAG - INFO - 🔍 Creating vector retriever... +2025-10-05 19:57:39,662 - AgenticMedicalRAG - INFO - 📝 Creating BM25 retriever... +2025-10-05 19:57:39,830 - AgenticMedicalRAG - INFO - 🔄 Creating hybrid retriever... +2025-10-05 19:57:39,830 - AgenticMedicalRAG - INFO - ✅ Retrievers initialized successfully. +2025-10-05 19:57:39,831 - AgenticMedicalRAG - INFO - 🔄 Background Init: Retrievers initialized successfully (90%) +2025-10-05 19:57:39,831 - AgenticMedicalRAG - INFO - 🔄 Background Init: Warming up LLM... (95%) +2025-10-05 19:57:39,831 - AgenticMedicalRAG - INFO - Initializing LLM (first time)... +2025-10-05 19:57:40,048 - AgenticMedicalRAG - INFO - LLM initialized successfully +2025-10-05 19:57:40,048 - AgenticMedicalRAG - INFO - 🔄 Background Init: All components initialized successfully (100%) +2025-10-05 19:57:40,048 - AgenticMedicalRAG - INFO - ✅ Background initialization completed successfully +2025-10-05 19:58:36,255 - AgenticMedicalRAG - INFO - Processing user input (attempt 1): i found that Afinitor has these side effects fever... +2025-10-05 19:58:38,438 - AgenticMedicalRAG - ERROR - Failed to initialize Google Drive storage: Expecting property name enclosed in double quotes: line 9 column 3 (char 413) +2025-10-05 19:58:38,438 - AgenticMedicalRAG - INFO - Side effects report saved locally: side_effects_reports.csv +2025-10-05 19:58:39,867 - AgenticMedicalRAG - INFO - Successfully processed user input: i found that Afinitor has these side effects fever... +2025-10-05 21:27:43,347 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-10-05 21:27:44,612 - AgenticMedicalRAG - INFO - Agentic Medical Guidelines Assistant starting... +2025-10-05 21:27:44,613 - AgenticMedicalRAG - INFO - 🚀 Starting background initialization of components... +2025-10-05 21:27:44,613 - AgenticMedicalRAG - INFO - 🚀 Starting background initialization... +2025-10-05 21:27:44,613 - AgenticMedicalRAG - INFO - 🔄 Background Init: Starting background initialization... (0%) +2025-10-05 21:27:44,613 - AgenticMedicalRAG - INFO - Starting Gradio interface... +2025-10-05 21:27:44,613 - AgenticMedicalRAG - INFO - 🔄 Background Init: Loading embedding model... (10%) +2025-10-05 21:27:44,615 - AgenticMedicalRAG - INFO - Loading embedding model (first time)... +2025-10-05 21:27:59,170 - AgenticMedicalRAG - INFO - Processing user input (attempt 1): i found that Afinitor has these side effects fever... +2025-10-05 21:27:59,171 - AgenticMedicalRAG - INFO - Initializing LLM (first time)... +2025-10-05 21:27:59,304 - AgenticMedicalRAG - INFO - Embedding model loaded successfully +2025-10-05 21:27:59,305 - AgenticMedicalRAG - INFO - 🔄 Background Init: Embedding model loaded successfully (40%) +2025-10-05 21:27:59,306 - AgenticMedicalRAG - INFO - 🔄 Background Init: Initializing retrievers and loading chunks... (50%) +2025-10-05 21:27:59,306 - AgenticMedicalRAG - INFO - 🔄 Initializing retrievers (first time use)... +2025-10-05 21:27:59,307 - AgenticMedicalRAG - INFO - 🔄 Processing new data and updating vector store if needed... +2025-10-05 21:27:59,425 - AgenticMedicalRAG - INFO - 📦 Loading chunks cache for BM25 retriever... +2025-10-05 21:27:59,458 - AgenticMedicalRAG - INFO - 🔍 Creating vector retriever... +2025-10-05 21:27:59,460 - AgenticMedicalRAG - INFO - 📝 Creating BM25 retriever... +2025-10-05 21:27:59,806 - AgenticMedicalRAG - INFO - 🔄 Creating hybrid retriever... +2025-10-05 21:27:59,807 - AgenticMedicalRAG - INFO - ✅ Retrievers initialized successfully. +2025-10-05 21:27:59,810 - AgenticMedicalRAG - INFO - 🔄 Background Init: Retrievers initialized successfully (90%) +2025-10-05 21:27:59,810 - AgenticMedicalRAG - INFO - 🔄 Background Init: Warming up LLM... (95%) +2025-10-05 21:27:59,810 - AgenticMedicalRAG - INFO - Initializing LLM (first time)... +2025-10-05 21:28:00,148 - AgenticMedicalRAG - INFO - LLM initialized successfully +2025-10-05 21:28:00,148 - AgenticMedicalRAG - INFO - LLM initialized successfully +2025-10-05 21:28:00,148 - AgenticMedicalRAG - INFO - 🔄 Background Init: All components initialized successfully (100%) +2025-10-05 21:28:00,171 - AgenticMedicalRAG - INFO - ✅ Background initialization completed successfully +2025-10-05 21:28:05,714 - AgenticMedicalRAG - INFO - Performing automatic validation for streaming response... +2025-10-05 21:28:05,714 - AgenticMedicalRAG - INFO - Skipping validation: insufficient context +2025-10-05 21:28:05,715 - AgenticMedicalRAG - INFO - Successfully processed user input: i found that Afinitor has these side effects fever... +2025-10-05 21:39:44,415 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-10-05 21:39:44,418 - AgenticMedicalRAG - INFO - GitHub storage initialized for MoazEldsouky/cloud-data-store +2025-10-05 21:39:46,161 - AgenticMedicalRAG - INFO - Successfully uploaded medical_data/side_effects_reports.csv to GitHub +2025-10-05 21:39:47,781 - AgenticMedicalRAG - INFO - Successfully uploaded medical_data/evaluation_results.json to GitHub +2025-10-05 21:39:50,681 - AgenticMedicalRAG - INFO - Successfully uploaded medical_data/side_effects_reports.csv to GitHub +2025-10-05 21:39:50,683 - AgenticMedicalRAG - INFO - Successfully saved side effects report to GitHub +2025-10-05 21:40:13,033 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-10-05 21:40:13,889 - AgenticMedicalRAG - INFO - Agentic Medical Guidelines Assistant starting... +2025-10-05 21:40:13,890 - AgenticMedicalRAG - INFO - 🚀 Starting background initialization of components... +2025-10-05 21:40:13,890 - AgenticMedicalRAG - INFO - 🚀 Starting background initialization... +2025-10-05 21:40:13,890 - AgenticMedicalRAG - INFO - 🔄 Background Init: Starting background initialization... (0%) +2025-10-05 21:40:13,890 - AgenticMedicalRAG - INFO - Starting Gradio interface... +2025-10-05 21:40:13,890 - AgenticMedicalRAG - INFO - 🔄 Background Init: Loading embedding model... (10%) +2025-10-05 21:40:13,891 - AgenticMedicalRAG - INFO - Loading embedding model (first time)... +2025-10-05 21:40:23,258 - AgenticMedicalRAG - INFO - Embedding model loaded successfully +2025-10-05 21:40:23,258 - AgenticMedicalRAG - INFO - 🔄 Background Init: Embedding model loaded successfully (40%) +2025-10-05 21:40:23,259 - AgenticMedicalRAG - INFO - 🔄 Background Init: Initializing retrievers and loading chunks... (50%) +2025-10-05 21:40:23,259 - AgenticMedicalRAG - INFO - 🔄 Initializing retrievers (first time use)... +2025-10-05 21:40:23,260 - AgenticMedicalRAG - INFO - 🔄 Processing new data and updating vector store if needed... +2025-10-05 21:40:23,315 - AgenticMedicalRAG - INFO - 📦 Loading chunks cache for BM25 retriever... +2025-10-05 21:40:23,329 - AgenticMedicalRAG - INFO - 🔍 Creating vector retriever... +2025-10-05 21:40:23,330 - AgenticMedicalRAG - INFO - 📝 Creating BM25 retriever... +2025-10-05 21:40:23,528 - AgenticMedicalRAG - INFO - 🔄 Creating hybrid retriever... +2025-10-05 21:40:23,528 - AgenticMedicalRAG - INFO - ✅ Retrievers initialized successfully. +2025-10-05 21:40:23,528 - AgenticMedicalRAG - INFO - 🔄 Background Init: Retrievers initialized successfully (90%) +2025-10-05 21:40:23,529 - AgenticMedicalRAG - INFO - 🔄 Background Init: Warming up LLM... (95%) +2025-10-05 21:40:23,529 - AgenticMedicalRAG - INFO - Initializing LLM (first time)... +2025-10-05 21:40:23,930 - AgenticMedicalRAG - INFO - LLM initialized successfully +2025-10-05 21:40:23,931 - AgenticMedicalRAG - INFO - 🔄 Background Init: All components initialized successfully (100%) +2025-10-05 21:40:23,931 - AgenticMedicalRAG - INFO - ✅ Background initialization completed successfully +2025-10-05 21:40:41,816 - AgenticMedicalRAG - INFO - Processing user input (attempt 1): i found that Afinitor has these side effects fever... +2025-10-05 21:40:44,691 - AgenticMedicalRAG - INFO - Successfully processed user input: i found that Afinitor has these side effects fever... +2025-10-05 21:49:44,148 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-10-05 21:49:45,213 - AgenticMedicalRAG - INFO - Agentic Medical Guidelines Assistant starting... +2025-10-05 21:49:45,214 - AgenticMedicalRAG - INFO - 🚀 Starting background initialization of components... +2025-10-05 21:49:45,214 - AgenticMedicalRAG - INFO - 🚀 Starting background initialization... +2025-10-05 21:49:45,215 - AgenticMedicalRAG - INFO - 🔄 Background Init: Starting background initialization... (0%) +2025-10-05 21:49:45,215 - AgenticMedicalRAG - INFO - Starting Gradio interface... +2025-10-05 21:49:45,215 - AgenticMedicalRAG - INFO - 🔄 Background Init: Loading embedding model... (10%) +2025-10-05 21:49:45,216 - AgenticMedicalRAG - INFO - Loading embedding model (first time)... +2025-10-05 21:49:56,902 - AgenticMedicalRAG - INFO - Embedding model loaded successfully +2025-10-05 21:49:56,902 - AgenticMedicalRAG - INFO - 🔄 Background Init: Embedding model loaded successfully (40%) +2025-10-05 21:49:56,903 - AgenticMedicalRAG - INFO - 🔄 Background Init: Initializing retrievers and loading chunks... (50%) +2025-10-05 21:49:56,903 - AgenticMedicalRAG - INFO - 🔄 Initializing retrievers (first time use)... +2025-10-05 21:49:56,903 - AgenticMedicalRAG - INFO - 🔄 Processing new data and updating vector store if needed... +2025-10-05 21:49:56,973 - AgenticMedicalRAG - INFO - 📦 Loading chunks cache for BM25 retriever... +2025-10-05 21:49:56,994 - AgenticMedicalRAG - INFO - 🔍 Creating vector retriever... +2025-10-05 21:49:56,995 - AgenticMedicalRAG - INFO - 📝 Creating BM25 retriever... +2025-10-05 21:49:57,312 - AgenticMedicalRAG - INFO - 🔄 Creating hybrid retriever... +2025-10-05 21:49:57,313 - AgenticMedicalRAG - INFO - ✅ Retrievers initialized successfully. +2025-10-05 21:49:57,313 - AgenticMedicalRAG - INFO - 🔄 Background Init: Retrievers initialized successfully (90%) +2025-10-05 21:49:57,313 - AgenticMedicalRAG - INFO - 🔄 Background Init: Warming up LLM... (95%) +2025-10-05 21:49:57,314 - AgenticMedicalRAG - INFO - Initializing LLM (first time)... +2025-10-05 21:49:57,715 - AgenticMedicalRAG - INFO - LLM initialized successfully +2025-10-05 21:49:57,716 - AgenticMedicalRAG - INFO - 🔄 Background Init: All components initialized successfully (100%) +2025-10-05 21:49:57,717 - AgenticMedicalRAG - INFO - ✅ Background initialization completed successfully +2025-10-05 21:50:04,692 - AgenticMedicalRAG - INFO - Processing user input (attempt 1): i found that Afinitor has these side effects fever... +2025-10-05 21:50:07,050 - AgenticMedicalRAG - INFO - GitHub storage initialized for MoazEldsouky/cloud-data-store +2025-10-05 21:50:08,456 - AgenticMedicalRAG - INFO - Successfully uploaded medical_data/side_effects_reports.csv to GitHub +2025-10-05 21:50:09,916 - AgenticMedicalRAG - INFO - Performing automatic validation for streaming response... +2025-10-05 21:50:09,916 - AgenticMedicalRAG - INFO - Skipping validation: insufficient context +2025-10-05 21:50:09,916 - AgenticMedicalRAG - INFO - Successfully processed user input: i found that Afinitor has these side effects fever... +2025-10-05 21:51:09,241 - AgenticMedicalRAG - INFO - Processing user input (attempt 1): What is the recommended first-line treatment for a... +2025-10-05 21:51:19,034 - AgenticMedicalRAG - INFO - Performing automatic validation for streaming response... +2025-10-05 21:51:19,071 - AgenticMedicalRAG - INFO - Medical answer validator initialized successfully +2025-10-05 21:51:19,071 - AgenticMedicalRAG - ERROR - Error getting next interaction ID: Expecting value: line 1 column 1 (char 0) +2025-10-05 21:51:19,072 - AgenticMedicalRAG - INFO - Starting validation for interaction 1 +2025-10-05 21:51:32,900 - AgenticMedicalRAG - INFO - Successfully uploaded medical_data/evaluation_results.json to GitHub +2025-10-05 21:51:32,902 - AgenticMedicalRAG - INFO - Evaluation saved to GitHub with ID: 1 +2025-10-05 21:51:42,220 - AgenticMedicalRAG - INFO - Successfully processed user input: What is the recommended first-line treatment for a... +2025-10-06 15:08:37,777 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-10-06 15:08:40,423 - AgenticMedicalRAG - INFO - Agentic Medical Guidelines Assistant starting... +2025-10-06 15:08:40,424 - AgenticMedicalRAG - INFO - 🚀 Starting background initialization of components... +2025-10-06 15:08:40,424 - AgenticMedicalRAG - INFO - 🚀 Starting background initialization... +2025-10-06 15:08:40,425 - AgenticMedicalRAG - INFO - 🔄 Background Init: Starting background initialization... (0%) +2025-10-06 15:08:40,425 - AgenticMedicalRAG - INFO - Starting Gradio interface... +2025-10-06 15:08:40,426 - AgenticMedicalRAG - INFO - 🔄 Background Init: Loading embedding model... (10%) +2025-10-06 15:08:40,430 - AgenticMedicalRAG - INFO - Loading embedding model (first time)... +2025-10-06 15:09:03,246 - AgenticMedicalRAG - INFO - Embedding model loaded successfully +2025-10-06 15:09:03,248 - AgenticMedicalRAG - INFO - 🔄 Background Init: Embedding model loaded successfully (40%) +2025-10-06 15:09:03,248 - AgenticMedicalRAG - INFO - 🔄 Background Init: Initializing retrievers and loading chunks... (50%) +2025-10-06 15:09:03,249 - AgenticMedicalRAG - INFO - 🔄 Initializing retrievers (first time use)... +2025-10-06 15:09:03,250 - AgenticMedicalRAG - INFO - 🔄 Processing new data and updating vector store if needed... +2025-10-06 15:09:03,472 - AgenticMedicalRAG - INFO - 📦 Loading chunks cache for BM25 retriever... +2025-10-06 15:09:03,523 - AgenticMedicalRAG - INFO - 🔍 Creating vector retriever... +2025-10-06 15:09:03,524 - AgenticMedicalRAG - INFO - 📝 Creating BM25 retriever... +2025-10-06 15:09:03,905 - AgenticMedicalRAG - INFO - 🔄 Creating hybrid retriever... +2025-10-06 15:09:03,906 - AgenticMedicalRAG - INFO - ✅ Retrievers initialized successfully. +2025-10-06 15:09:03,906 - AgenticMedicalRAG - INFO - 🔄 Background Init: Retrievers initialized successfully (90%) +2025-10-06 15:09:03,907 - AgenticMedicalRAG - INFO - 🔄 Background Init: Warming up LLM... (95%) +2025-10-06 15:09:03,907 - AgenticMedicalRAG - INFO - Initializing LLM (first time)... +2025-10-06 15:09:04,562 - AgenticMedicalRAG - INFO - LLM initialized successfully +2025-10-06 15:09:04,562 - AgenticMedicalRAG - INFO - 🔄 Background Init: All components initialized successfully (100%) +2025-10-06 15:09:04,564 - AgenticMedicalRAG - INFO - ✅ Background initialization completed successfully +2025-10-06 15:10:12,041 - AgenticMedicalRAG - INFO - Processing user input (attempt 1): What is the role of durvalumab in stage III NSCLC ... +2025-10-06 15:10:22,109 - AgenticMedicalRAG - INFO - Performing automatic validation for streaming response... +2025-10-06 15:10:22,156 - AgenticMedicalRAG - INFO - Medical answer validator initialized successfully +2025-10-06 15:10:22,158 - AgenticMedicalRAG - ERROR - Error getting next interaction ID: Expecting value: line 1 column 1 (char 0) +2025-10-06 15:10:22,158 - AgenticMedicalRAG - INFO - Starting validation for interaction 1 +2025-10-06 15:10:29,836 - AgenticMedicalRAG - INFO - GitHub storage initialized for MoazEldsouky/cloud-data-store +2025-10-06 15:10:31,963 - AgenticMedicalRAG - INFO - Successfully uploaded medical_data/evaluation_results.json to GitHub +2025-10-06 15:10:31,964 - AgenticMedicalRAG - INFO - Evaluation saved to GitHub with ID: 1 +2025-10-06 15:10:38,504 - AgenticMedicalRAG - INFO - Successfully processed user input: What is the role of durvalumab in stage III NSCLC ... +2025-10-06 15:26:02,901 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-10-06 15:26:02,902 - AgenticMedicalRAG - INFO - GitHub storage initialized for MoazEldsouky/cloud-data-store +2025-10-06 15:26:05,527 - AgenticMedicalRAG - INFO - Successfully uploaded medical_data/evaluation_results.json to GitHub +2025-10-06 15:27:34,937 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-10-06 15:27:36,174 - AgenticMedicalRAG - INFO - Agentic Medical Guidelines Assistant starting... +2025-10-06 15:27:36,174 - AgenticMedicalRAG - INFO - 🚀 Starting background initialization of components... +2025-10-06 15:27:36,175 - AgenticMedicalRAG - INFO - 🚀 Starting background initialization... +2025-10-06 15:27:36,176 - AgenticMedicalRAG - INFO - 🔄 Background Init: Starting background initialization... (0%) +2025-10-06 15:27:36,176 - AgenticMedicalRAG - INFO - Starting Gradio interface... +2025-10-06 15:27:36,176 - AgenticMedicalRAG - INFO - 🔄 Background Init: Loading embedding model... (10%) +2025-10-06 15:27:36,178 - AgenticMedicalRAG - INFO - Loading embedding model (first time)... +2025-10-06 15:27:46,958 - AgenticMedicalRAG - INFO - Processing user input (attempt 1): What is the role of durvalumab in stage III NSCLC ... +2025-10-06 15:27:46,960 - AgenticMedicalRAG - INFO - Initializing LLM (first time)... +2025-10-06 15:27:47,811 - AgenticMedicalRAG - INFO - LLM initialized successfully +2025-10-06 15:27:49,812 - AgenticMedicalRAG - INFO - 🔄 Initializing retrievers (first time use)... +2025-10-06 15:27:49,812 - AgenticMedicalRAG - INFO - 🔄 Processing new data and updating vector store if needed... +2025-10-06 15:27:49,814 - AgenticMedicalRAG - INFO - Loading embedding model (first time)... +2025-10-06 15:27:51,238 - AgenticMedicalRAG - INFO - Embedding model loaded successfully +2025-10-06 15:27:51,239 - AgenticMedicalRAG - INFO - 🔄 Background Init: Embedding model loaded successfully (40%) +2025-10-06 15:27:51,240 - AgenticMedicalRAG - INFO - 🔄 Background Init: Initializing retrievers and loading chunks... (50%) +2025-10-06 15:27:51,240 - AgenticMedicalRAG - INFO - 🔄 Initializing retrievers (first time use)... +2025-10-06 15:27:51,240 - AgenticMedicalRAG - INFO - 🔄 Processing new data and updating vector store if needed... +2025-10-06 15:27:51,334 - AgenticMedicalRAG - INFO - 📦 Loading chunks cache for BM25 retriever... +2025-10-06 15:27:51,362 - AgenticMedicalRAG - INFO - 🔍 Creating vector retriever... +2025-10-06 15:27:51,363 - AgenticMedicalRAG - INFO - 📝 Creating BM25 retriever... +2025-10-06 15:27:51,754 - AgenticMedicalRAG - INFO - 🔄 Creating hybrid retriever... +2025-10-06 15:27:51,756 - AgenticMedicalRAG - INFO - ✅ Retrievers initialized successfully. +2025-10-06 15:27:51,756 - AgenticMedicalRAG - INFO - 🔄 Background Init: Retrievers initialized successfully (90%) +2025-10-06 15:27:51,758 - AgenticMedicalRAG - INFO - 🔄 Background Init: Warming up LLM... (95%) +2025-10-06 15:27:51,760 - AgenticMedicalRAG - INFO - 🔄 Background Init: All components initialized successfully (100%) +2025-10-06 15:27:51,760 - AgenticMedicalRAG - INFO - ✅ Background initialization completed successfully +2025-10-06 15:27:53,335 - AgenticMedicalRAG - INFO - Embedding model loaded successfully +2025-10-06 15:27:53,374 - AgenticMedicalRAG - INFO - 📦 Loading chunks cache for BM25 retriever... +2025-10-06 15:27:53,409 - AgenticMedicalRAG - INFO - 🔍 Creating vector retriever... +2025-10-06 15:27:53,410 - AgenticMedicalRAG - INFO - 📝 Creating BM25 retriever... +2025-10-06 15:27:53,774 - AgenticMedicalRAG - INFO - 🔄 Creating hybrid retriever... +2025-10-06 15:27:53,794 - AgenticMedicalRAG - INFO - ✅ Retrievers initialized successfully. +2025-10-06 15:27:58,811 - AgenticMedicalRAG - INFO - Performing automatic validation for streaming response... +2025-10-06 15:27:58,849 - AgenticMedicalRAG - INFO - Medical answer validator initialized successfully +2025-10-06 15:27:58,850 - AgenticMedicalRAG - INFO - GitHub storage initialized for MoazEldsouky/cloud-data-store +2025-10-06 15:27:59,357 - AgenticMedicalRAG - ERROR - Error getting next interaction ID: Expecting value: line 1 column 1 (char 0) +2025-10-06 15:27:59,358 - AgenticMedicalRAG - INFO - Starting validation for interaction 1 +2025-10-06 15:28:09,637 - AgenticMedicalRAG - INFO - Assigned unique interaction ID: 1 +2025-10-06 15:28:11,580 - AgenticMedicalRAG - INFO - Successfully uploaded medical_data/evaluation_results.json to GitHub +2025-10-06 15:28:11,581 - AgenticMedicalRAG - INFO - Evaluation saved to GitHub with ID: 1 +2025-10-06 15:28:18,941 - AgenticMedicalRAG - INFO - Successfully processed user input: What is the role of durvalumab in stage III NSCLC ... +2025-10-06 15:28:38,365 - AgenticMedicalRAG - INFO - Processing user input (attempt 1): How should patients with stage IV NSCLC and EGFR m... +2025-10-06 15:28:50,010 - AgenticMedicalRAG - INFO - Performing automatic validation for streaming response... +2025-10-06 15:28:50,417 - AgenticMedicalRAG - INFO - Starting validation for interaction 2 +2025-10-06 15:30:00,704 - AgenticMedicalRAG - INFO - Assigned unique interaction ID: 2 +2025-10-06 15:30:02,074 - AgenticMedicalRAG - INFO - Successfully uploaded medical_data/evaluation_results.json to GitHub +2025-10-06 15:30:02,077 - AgenticMedicalRAG - INFO - Evaluation saved to GitHub with ID: 2 +2025-10-06 15:30:10,446 - AgenticMedicalRAG - INFO - Successfully processed user input: How should patients with stage IV NSCLC and EGFR m... +2025-10-06 15:30:10,477 - AgenticMedicalRAG - INFO - Processing user input (attempt 1): How should patients with stage IV NSCLC and EGFR m... +2025-10-06 15:30:17,358 - AgenticMedicalRAG - INFO - Performing automatic validation for streaming response... +2025-10-06 15:30:17,923 - AgenticMedicalRAG - INFO - Starting validation for interaction 3 +2025-10-06 15:30:32,287 - AgenticMedicalRAG - INFO - Assigned unique interaction ID: 3 +2025-10-06 15:30:34,351 - AgenticMedicalRAG - INFO - Successfully uploaded medical_data/evaluation_results.json to GitHub +2025-10-06 15:30:34,352 - AgenticMedicalRAG - INFO - Evaluation saved to GitHub with ID: 3 +2025-10-06 15:30:41,391 - AgenticMedicalRAG - INFO - Successfully processed user input: How should patients with stage IV NSCLC and EGFR m... +2025-10-06 15:30:59,714 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-10-06 15:31:00,943 - AgenticMedicalRAG - INFO - Agentic Medical Guidelines Assistant starting... +2025-10-06 15:31:00,943 - AgenticMedicalRAG - INFO - 🚀 Starting background initialization of components... +2025-10-06 15:31:00,943 - AgenticMedicalRAG - INFO - 🚀 Starting background initialization... +2025-10-06 15:31:00,944 - AgenticMedicalRAG - INFO - 🔄 Background Init: Starting background initialization... (0%) +2025-10-06 15:31:00,944 - AgenticMedicalRAG - INFO - Starting Gradio interface... +2025-10-06 15:31:00,944 - AgenticMedicalRAG - INFO - 🔄 Background Init: Loading embedding model... (10%) +2025-10-06 15:31:00,945 - AgenticMedicalRAG - INFO - Loading embedding model (first time)... +2025-10-06 15:31:16,517 - AgenticMedicalRAG - INFO - Embedding model loaded successfully +2025-10-06 15:31:16,518 - AgenticMedicalRAG - INFO - 🔄 Background Init: Embedding model loaded successfully (40%) +2025-10-06 15:31:16,518 - AgenticMedicalRAG - INFO - 🔄 Background Init: Initializing retrievers and loading chunks... (50%) +2025-10-06 15:31:16,520 - AgenticMedicalRAG - INFO - 🔄 Initializing retrievers (first time use)... +2025-10-06 15:31:16,520 - AgenticMedicalRAG - INFO - 🔄 Processing new data and updating vector store if needed... +2025-10-06 15:31:16,604 - AgenticMedicalRAG - INFO - 📦 Loading chunks cache for BM25 retriever... +2025-10-06 15:31:16,623 - AgenticMedicalRAG - INFO - 🔍 Creating vector retriever... +2025-10-06 15:31:16,624 - AgenticMedicalRAG - INFO - 📝 Creating BM25 retriever... +2025-10-06 15:31:16,938 - AgenticMedicalRAG - INFO - 🔄 Creating hybrid retriever... +2025-10-06 15:31:16,939 - AgenticMedicalRAG - INFO - ✅ Retrievers initialized successfully. +2025-10-06 15:31:16,940 - AgenticMedicalRAG - INFO - 🔄 Background Init: Retrievers initialized successfully (90%) +2025-10-06 15:31:16,941 - AgenticMedicalRAG - INFO - 🔄 Background Init: Warming up LLM... (95%) +2025-10-06 15:31:16,942 - AgenticMedicalRAG - INFO - Initializing LLM (first time)... +2025-10-06 15:31:17,344 - AgenticMedicalRAG - INFO - LLM initialized successfully +2025-10-06 15:31:17,344 - AgenticMedicalRAG - INFO - 🔄 Background Init: All components initialized successfully (100%) +2025-10-06 15:31:17,344 - AgenticMedicalRAG - INFO - ✅ Background initialization completed successfully +2025-10-06 15:31:23,084 - AgenticMedicalRAG - INFO - Processing user input (attempt 1): What is the recommended first-line treatment for a... +2025-10-06 15:31:30,277 - AgenticMedicalRAG - INFO - Performing automatic validation for streaming response... +2025-10-06 15:31:30,310 - AgenticMedicalRAG - INFO - Medical answer validator initialized successfully +2025-10-06 15:31:30,310 - AgenticMedicalRAG - INFO - GitHub storage initialized for MoazEldsouky/cloud-data-store +2025-10-06 15:31:31,135 - AgenticMedicalRAG - INFO - Starting validation for interaction 4 +2025-10-06 15:31:38,938 - AgenticMedicalRAG - INFO - Assigned unique interaction ID: 4 +2025-10-06 15:31:40,976 - AgenticMedicalRAG - INFO - Successfully uploaded medical_data/evaluation_results.json to GitHub +2025-10-06 15:31:40,977 - AgenticMedicalRAG - INFO - Evaluation saved to GitHub with ID: 4 +2025-10-06 15:31:45,752 - AgenticMedicalRAG - INFO - Successfully processed user input: What is the recommended first-line treatment for a... +2025-10-06 15:32:37,581 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-10-06 15:32:38,928 - AgenticMedicalRAG - INFO - Agentic Medical Guidelines Assistant starting... +2025-10-06 15:32:38,928 - AgenticMedicalRAG - INFO - 🚀 Starting background initialization of components... +2025-10-06 15:32:38,929 - AgenticMedicalRAG - INFO - 🚀 Starting background initialization... +2025-10-06 15:32:38,930 - AgenticMedicalRAG - INFO - 🔄 Background Init: Starting background initialization... (0%) +2025-10-06 15:32:38,930 - AgenticMedicalRAG - INFO - Starting Gradio interface... +2025-10-06 15:32:38,930 - AgenticMedicalRAG - INFO - 🔄 Background Init: Loading embedding model... (10%) +2025-10-06 15:32:38,931 - AgenticMedicalRAG - INFO - Loading embedding model (first time)... +2025-10-06 15:32:53,387 - AgenticMedicalRAG - INFO - Embedding model loaded successfully +2025-10-06 15:32:53,388 - AgenticMedicalRAG - INFO - 🔄 Background Init: Embedding model loaded successfully (40%) +2025-10-06 15:32:53,389 - AgenticMedicalRAG - INFO - 🔄 Background Init: Initializing retrievers and loading chunks... (50%) +2025-10-06 15:32:53,390 - AgenticMedicalRAG - INFO - 🔄 Initializing retrievers (first time use)... +2025-10-06 15:32:53,390 - AgenticMedicalRAG - INFO - 🔄 Processing new data and updating vector store if needed... +2025-10-06 15:32:53,495 - AgenticMedicalRAG - INFO - 📦 Loading chunks cache for BM25 retriever... +2025-10-06 15:32:53,518 - AgenticMedicalRAG - INFO - 🔍 Creating vector retriever... +2025-10-06 15:32:53,519 - AgenticMedicalRAG - INFO - 📝 Creating BM25 retriever... +2025-10-06 15:32:53,886 - AgenticMedicalRAG - INFO - 🔄 Creating hybrid retriever... +2025-10-06 15:32:53,887 - AgenticMedicalRAG - INFO - ✅ Retrievers initialized successfully. +2025-10-06 15:32:53,887 - AgenticMedicalRAG - INFO - 🔄 Background Init: Retrievers initialized successfully (90%) +2025-10-06 15:32:53,887 - AgenticMedicalRAG - INFO - 🔄 Background Init: Warming up LLM... (95%) +2025-10-06 15:32:53,889 - AgenticMedicalRAG - INFO - Initializing LLM (first time)... +2025-10-06 15:32:54,295 - AgenticMedicalRAG - INFO - LLM initialized successfully +2025-10-06 15:32:54,295 - AgenticMedicalRAG - INFO - 🔄 Background Init: All components initialized successfully (100%) +2025-10-06 15:32:54,295 - AgenticMedicalRAG - INFO - ✅ Background initialization completed successfully +2025-10-06 15:33:36,327 - AgenticMedicalRAG - INFO - Processing user input (attempt 1): i found that Afinitor has these side effects fever... +2025-10-06 15:33:39,100 - AgenticMedicalRAG - INFO - GitHub storage initialized for MoazEldsouky/cloud-data-store +2025-10-06 15:33:41,044 - AgenticMedicalRAG - INFO - Successfully uploaded medical_data/side_effects_reports.csv to GitHub +2025-10-06 15:33:42,041 - AgenticMedicalRAG - INFO - Successfully processed user input: i found that Afinitor has these side effects fever... +2025-10-06 15:35:17,441 - AgenticMedicalRAG - INFO - Conversation memory cleared successfully +2025-10-06 15:35:17,441 - AgenticMedicalRAG - INFO - Successfully cleared chat memory and history +2025-10-06 15:35:19,806 - AgenticMedicalRAG - INFO - Processing user input (attempt 1): i found that Afinitor has these side effects fever... +2025-10-06 15:35:24,045 - AgenticMedicalRAG - INFO - Successfully uploaded medical_data/side_effects_reports.csv to GitHub +2025-10-06 15:35:25,023 - AgenticMedicalRAG - INFO - Performing automatic validation for streaming response... +2025-10-06 15:35:25,023 - AgenticMedicalRAG - INFO - Skipping validation: insufficient context +2025-10-06 15:35:25,024 - AgenticMedicalRAG - INFO - Successfully processed user input: i found that Afinitor has these side effects fever... +2025-10-06 15:36:28,524 - AgenticMedicalRAG - INFO - Processing user input (attempt 1): i found that cisplatin has serious kidney problems... +2025-10-06 15:36:31,841 - AgenticMedicalRAG - INFO - Performing automatic validation for streaming response... +2025-10-06 15:36:31,843 - AgenticMedicalRAG - INFO - Skipping validation: insufficient context +2025-10-06 15:36:31,844 - AgenticMedicalRAG - INFO - Successfully processed user input: i found that cisplatin has serious kidney problems... +2025-10-06 15:37:05,351 - AgenticMedicalRAG - INFO - Processing user input (attempt 1): i can't provide this information ... +2025-10-06 15:37:09,171 - AgenticMedicalRAG - INFO - Performing automatic validation for streaming response... +2025-10-06 15:37:09,172 - AgenticMedicalRAG - INFO - Skipping validation: insufficient context +2025-10-06 15:37:09,173 - AgenticMedicalRAG - INFO - Successfully processed user input: i can't provide this information ... +2025-10-06 17:08:11,705 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-10-06 17:09:27,389 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-10-06 17:09:28,814 - AgenticMedicalRAG - INFO - Agentic Medical Guidelines Assistant starting... +2025-10-06 17:09:28,815 - AgenticMedicalRAG - INFO - 🚀 Starting background initialization of components... +2025-10-06 17:09:28,815 - AgenticMedicalRAG - INFO - 🚀 Starting background initialization... +2025-10-06 17:09:28,816 - AgenticMedicalRAG - INFO - 🔄 Background Init: Starting background initialization... (0%) +2025-10-06 17:09:28,816 - AgenticMedicalRAG - INFO - Starting Gradio interface... +2025-10-06 17:09:28,816 - AgenticMedicalRAG - INFO - 🔄 Background Init: Loading embedding model... (10%) +2025-10-06 17:09:28,819 - AgenticMedicalRAG - INFO - Loading embedding model (first time)... +2025-10-06 17:09:46,393 - AgenticMedicalRAG - INFO - Embedding model loaded successfully +2025-10-06 17:09:46,394 - AgenticMedicalRAG - INFO - 🔄 Background Init: Embedding model loaded successfully (40%) +2025-10-06 17:09:46,395 - AgenticMedicalRAG - INFO - 🔄 Background Init: Initializing retrievers and loading chunks... (50%) +2025-10-06 17:09:46,396 - AgenticMedicalRAG - INFO - 🔄 Initializing retrievers (first time use)... +2025-10-06 17:09:46,396 - AgenticMedicalRAG - INFO - 🔄 Processing new data and updating vector store if needed... +2025-10-06 17:09:46,495 - AgenticMedicalRAG - INFO - 📦 Loading chunks cache for BM25 retriever... +2025-10-06 17:09:46,518 - AgenticMedicalRAG - INFO - 🔍 Creating vector retriever... +2025-10-06 17:09:46,519 - AgenticMedicalRAG - INFO - 📝 Creating BM25 retriever... +2025-10-06 17:09:46,880 - AgenticMedicalRAG - INFO - 🔄 Creating hybrid retriever... +2025-10-06 17:09:46,881 - AgenticMedicalRAG - INFO - ✅ Retrievers initialized successfully. +2025-10-06 17:09:46,881 - AgenticMedicalRAG - INFO - 🔄 Background Init: Retrievers initialized successfully (90%) +2025-10-06 17:09:46,881 - AgenticMedicalRAG - INFO - 🔄 Background Init: Warming up LLM... (95%) +2025-10-06 17:09:46,882 - AgenticMedicalRAG - INFO - Initializing LLM (first time)... +2025-10-06 17:09:47,409 - AgenticMedicalRAG - INFO - LLM initialized successfully +2025-10-06 17:09:47,411 - AgenticMedicalRAG - INFO - 🔄 Background Init: All components initialized successfully (100%) +2025-10-06 17:09:47,412 - AgenticMedicalRAG - INFO - ✅ Background initialization completed successfully +2025-10-06 17:09:58,532 - AgenticMedicalRAG - INFO - Processing user input (attempt 1): i found that Afinitor has these side effects fever... +2025-10-06 17:10:01,103 - AgenticMedicalRAG - INFO - GitHub storage initialized for MoazEldsouky/cloud-data-store +2025-10-06 17:10:02,722 - AgenticMedicalRAG - INFO - Successfully uploaded medical_data/side_effects_reports.csv to GitHub +2025-10-06 17:10:04,330 - AgenticMedicalRAG - INFO - Successfully processed user input: i found that Afinitor has these side effects fever... +2025-10-06 17:10:54,724 - AgenticMedicalRAG - INFO - Processing user input (attempt 1): i found that cisplatin has serious kidney problems... +2025-10-06 17:10:57,617 - AgenticMedicalRAG - INFO - Performing automatic validation for streaming response... +2025-10-06 17:10:57,619 - AgenticMedicalRAG - INFO - Skipping validation: insufficient context +2025-10-06 17:10:57,620 - AgenticMedicalRAG - INFO - Successfully processed user input: i found that cisplatin has serious kidney problems... +2025-10-06 17:11:21,164 - AgenticMedicalRAG - INFO - Processing user input (attempt 1): i can't provide more details... +2025-10-06 17:11:23,481 - AgenticMedicalRAG - INFO - Successfully processed user input: i can't provide more details... +2025-10-06 17:11:38,539 - AgenticMedicalRAG - INFO - Processing user input (attempt 1): just save them... +2025-10-06 17:11:42,544 - AgenticMedicalRAG - INFO - Successfully processed user input: just save them... +2025-10-06 17:42:58,305 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-10-06 17:42:59,370 - AgenticMedicalRAG - INFO - GitHub storage initialized for MoazEldsouky/cloud-data-store +2025-10-06 17:43:02,269 - AgenticMedicalRAG - INFO - Successfully uploaded medical_data/side_effects_reports.csv to GitHub +2025-10-06 17:43:03,808 - AgenticMedicalRAG - INFO - Successfully uploaded medical_data/side_effects_reports.csv to GitHub +2025-10-06 17:43:34,765 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-10-06 17:43:36,084 - AgenticMedicalRAG - INFO - Agentic Medical Guidelines Assistant starting... +2025-10-06 17:43:36,084 - AgenticMedicalRAG - INFO - 🚀 Starting background initialization of components... +2025-10-06 17:43:36,085 - AgenticMedicalRAG - INFO - 🚀 Starting background initialization... +2025-10-06 17:43:36,085 - AgenticMedicalRAG - INFO - 🔄 Background Init: Starting background initialization... (0%) +2025-10-06 17:43:36,085 - AgenticMedicalRAG - INFO - Starting Gradio interface... +2025-10-06 17:43:36,086 - AgenticMedicalRAG - INFO - 🔄 Background Init: Loading embedding model... (10%) +2025-10-06 17:43:36,087 - AgenticMedicalRAG - INFO - Loading embedding model (first time)... +2025-10-06 17:43:49,496 - AgenticMedicalRAG - INFO - Embedding model loaded successfully +2025-10-06 17:43:49,498 - AgenticMedicalRAG - INFO - 🔄 Background Init: Embedding model loaded successfully (40%) +2025-10-06 17:43:49,499 - AgenticMedicalRAG - INFO - 🔄 Background Init: Initializing retrievers and loading chunks... (50%) +2025-10-06 17:43:49,499 - AgenticMedicalRAG - INFO - 🔄 Initializing retrievers (first time use)... +2025-10-06 17:43:49,499 - AgenticMedicalRAG - INFO - 🔄 Processing new data and updating vector store if needed... +2025-10-06 17:43:49,614 - AgenticMedicalRAG - INFO - 📦 Loading chunks cache for BM25 retriever... +2025-10-06 17:43:49,634 - AgenticMedicalRAG - INFO - 🔍 Creating vector retriever... +2025-10-06 17:43:49,635 - AgenticMedicalRAG - INFO - 📝 Creating BM25 retriever... +2025-10-06 17:43:49,974 - AgenticMedicalRAG - INFO - 🔄 Creating hybrid retriever... +2025-10-06 17:43:49,975 - AgenticMedicalRAG - INFO - ✅ Retrievers initialized successfully. +2025-10-06 17:43:49,976 - AgenticMedicalRAG - INFO - 🔄 Background Init: Retrievers initialized successfully (90%) +2025-10-06 17:43:49,977 - AgenticMedicalRAG - INFO - 🔄 Background Init: Warming up LLM... (95%) +2025-10-06 17:43:49,977 - AgenticMedicalRAG - INFO - Initializing LLM (first time)... +2025-10-06 17:43:50,380 - AgenticMedicalRAG - INFO - LLM initialized successfully +2025-10-06 17:43:50,381 - AgenticMedicalRAG - INFO - 🔄 Background Init: All components initialized successfully (100%) +2025-10-06 17:43:50,382 - AgenticMedicalRAG - INFO - ✅ Background initialization completed successfully +2025-10-06 17:43:54,502 - AgenticMedicalRAG - INFO - Processing user input (attempt 1): i found that cisplatin has serious kidney problems... +2025-10-06 17:43:57,368 - AgenticMedicalRAG - INFO - GitHub storage initialized for MoazEldsouky/cloud-data-store +2025-10-06 17:43:59,683 - AgenticMedicalRAG - INFO - Successfully uploaded medical_data/side_effects_reports.csv to GitHub +2025-10-06 17:44:00,822 - AgenticMedicalRAG - INFO - Performing automatic validation for streaming response... +2025-10-06 17:44:00,822 - AgenticMedicalRAG - INFO - Skipping validation: insufficient context +2025-10-06 17:44:00,826 - AgenticMedicalRAG - INFO - Successfully processed user input: i found that cisplatin has serious kidney problems... +2025-10-06 20:21:21,837 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-10-06 20:21:23,693 - AgenticMedicalRAG - INFO - Agentic Medical Guidelines Assistant starting... +2025-10-06 20:21:23,693 - AgenticMedicalRAG - INFO - 🚀 Starting background initialization of components... +2025-10-06 20:21:23,694 - AgenticMedicalRAG - INFO - 🚀 Starting background initialization... +2025-10-06 20:21:23,694 - AgenticMedicalRAG - INFO - 🔄 Background Init: Starting background initialization... (0%) +2025-10-06 20:21:23,694 - AgenticMedicalRAG - INFO - Starting Gradio interface... +2025-10-06 20:21:23,694 - AgenticMedicalRAG - INFO - 🔄 Background Init: Loading embedding model... (10%) +2025-10-06 20:21:23,699 - AgenticMedicalRAG - INFO - Loading embedding model (first time)... +2025-10-06 20:21:42,056 - AgenticMedicalRAG - INFO - Embedding model loaded successfully +2025-10-06 20:21:42,057 - AgenticMedicalRAG - INFO - 🔄 Background Init: Embedding model loaded successfully (40%) +2025-10-06 20:21:42,058 - AgenticMedicalRAG - INFO - 🔄 Background Init: Initializing retrievers and loading chunks... (50%) +2025-10-06 20:21:42,059 - AgenticMedicalRAG - INFO - 🔄 Initializing retrievers (first time use)... +2025-10-06 20:21:42,059 - AgenticMedicalRAG - INFO - 🔄 Processing new data and updating vector store if needed... +2025-10-06 20:21:42,231 - AgenticMedicalRAG - INFO - 📦 Loading chunks cache for BM25 retriever... +2025-10-06 20:21:42,256 - AgenticMedicalRAG - INFO - 🔍 Creating vector retriever... +2025-10-06 20:21:42,257 - AgenticMedicalRAG - INFO - 📝 Creating BM25 retriever... +2025-10-06 20:21:42,622 - AgenticMedicalRAG - INFO - 🔄 Creating hybrid retriever... +2025-10-06 20:21:42,623 - AgenticMedicalRAG - INFO - ✅ Retrievers initialized successfully. +2025-10-06 20:21:42,623 - AgenticMedicalRAG - INFO - 🔄 Background Init: Retrievers initialized successfully (90%) +2025-10-06 20:21:42,624 - AgenticMedicalRAG - INFO - 🔄 Background Init: Warming up LLM... (95%) +2025-10-06 20:21:42,624 - AgenticMedicalRAG - INFO - Initializing LLM (first time)... +2025-10-06 20:21:43,111 - AgenticMedicalRAG - INFO - LLM initialized successfully +2025-10-06 20:21:43,111 - AgenticMedicalRAG - INFO - 🔄 Background Init: All components initialized successfully (100%) +2025-10-06 20:21:43,113 - AgenticMedicalRAG - INFO - ✅ Background initialization completed successfully +2025-10-06 20:22:04,377 - AgenticMedicalRAG - INFO - Processing user input (attempt 1): i found that Afinitor has these side effects fever... +2025-10-06 20:22:09,733 - AgenticMedicalRAG - INFO - Successfully processed user input: i found that Afinitor has these side effects fever... +2025-10-06 20:23:49,445 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-10-06 20:23:50,770 - AgenticMedicalRAG - INFO - Agentic Medical Guidelines Assistant starting... +2025-10-06 20:23:50,770 - AgenticMedicalRAG - INFO - 🚀 Starting background initialization of components... +2025-10-06 20:23:50,771 - AgenticMedicalRAG - INFO - 🚀 Starting background initialization... +2025-10-06 20:23:50,771 - AgenticMedicalRAG - INFO - 🔄 Background Init: Starting background initialization... (0%) +2025-10-06 20:23:50,771 - AgenticMedicalRAG - INFO - Starting Gradio interface... +2025-10-06 20:23:50,772 - AgenticMedicalRAG - INFO - 🔄 Background Init: Loading embedding model... (10%) +2025-10-06 20:23:50,773 - AgenticMedicalRAG - INFO - Loading embedding model (first time)... +2025-10-06 20:24:03,943 - AgenticMedicalRAG - INFO - Embedding model loaded successfully +2025-10-06 20:24:03,944 - AgenticMedicalRAG - INFO - 🔄 Background Init: Embedding model loaded successfully (40%) +2025-10-06 20:24:03,944 - AgenticMedicalRAG - INFO - 🔄 Background Init: Initializing retrievers and loading chunks... (50%) +2025-10-06 20:24:03,944 - AgenticMedicalRAG - INFO - 🔄 Initializing retrievers (first time use)... +2025-10-06 20:24:03,944 - AgenticMedicalRAG - INFO - 🔄 Processing new data and updating vector store if needed... +2025-10-06 20:24:04,036 - AgenticMedicalRAG - INFO - 📦 Loading chunks cache for BM25 retriever... +2025-10-06 20:24:04,053 - AgenticMedicalRAG - INFO - 🔍 Creating vector retriever... +2025-10-06 20:24:04,055 - AgenticMedicalRAG - INFO - 📝 Creating BM25 retriever... +2025-10-06 20:24:04,351 - AgenticMedicalRAG - INFO - 🔄 Creating hybrid retriever... +2025-10-06 20:24:04,351 - AgenticMedicalRAG - INFO - ✅ Retrievers initialized successfully. +2025-10-06 20:24:04,353 - AgenticMedicalRAG - INFO - 🔄 Background Init: Retrievers initialized successfully (90%) +2025-10-06 20:24:04,354 - AgenticMedicalRAG - INFO - 🔄 Background Init: Warming up LLM... (95%) +2025-10-06 20:24:04,354 - AgenticMedicalRAG - INFO - Initializing LLM (first time)... +2025-10-06 20:24:04,706 - AgenticMedicalRAG - INFO - LLM initialized successfully +2025-10-06 20:24:04,707 - AgenticMedicalRAG - INFO - 🔄 Background Init: All components initialized successfully (100%) +2025-10-06 20:24:04,708 - AgenticMedicalRAG - INFO - ✅ Background initialization completed successfully +2025-10-06 20:25:47,904 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-10-06 20:25:49,148 - AgenticMedicalRAG - INFO - Agentic Medical Guidelines Assistant starting... +2025-10-06 20:25:49,148 - AgenticMedicalRAG - INFO - 🚀 Starting background initialization of components... +2025-10-06 20:25:49,148 - AgenticMedicalRAG - INFO - 🚀 Starting background initialization... +2025-10-06 20:25:49,150 - AgenticMedicalRAG - INFO - 🔄 Background Init: Starting background initialization... (0%) +2025-10-06 20:25:49,150 - AgenticMedicalRAG - INFO - Starting Gradio interface... +2025-10-06 20:25:49,150 - AgenticMedicalRAG - INFO - 🔄 Background Init: Loading embedding model... (10%) +2025-10-06 20:25:49,152 - AgenticMedicalRAG - INFO - Loading embedding model (first time)... +2025-10-06 20:26:02,844 - AgenticMedicalRAG - INFO - Embedding model loaded successfully +2025-10-06 20:26:02,845 - AgenticMedicalRAG - INFO - 🔄 Background Init: Embedding model loaded successfully (40%) +2025-10-06 20:26:02,847 - AgenticMedicalRAG - INFO - 🔄 Background Init: Initializing retrievers and loading chunks... (50%) +2025-10-06 20:26:02,847 - AgenticMedicalRAG - INFO - 🔄 Initializing retrievers (first time use)... +2025-10-06 20:26:02,847 - AgenticMedicalRAG - INFO - 🔄 Processing new data and updating vector store if needed... +2025-10-06 20:26:02,934 - AgenticMedicalRAG - INFO - 📦 Loading chunks cache for BM25 retriever... +2025-10-06 20:26:02,958 - AgenticMedicalRAG - INFO - 🔍 Creating vector retriever... +2025-10-06 20:26:02,958 - AgenticMedicalRAG - INFO - 📝 Creating BM25 retriever... +2025-10-06 20:26:03,360 - AgenticMedicalRAG - INFO - 🔄 Creating hybrid retriever... +2025-10-06 20:26:03,361 - AgenticMedicalRAG - INFO - ✅ Retrievers initialized successfully. +2025-10-06 20:26:03,361 - AgenticMedicalRAG - INFO - 🔄 Background Init: Retrievers initialized successfully (90%) +2025-10-06 20:26:03,362 - AgenticMedicalRAG - INFO - 🔄 Background Init: Warming up LLM... (95%) +2025-10-06 20:26:03,362 - AgenticMedicalRAG - INFO - Initializing LLM (first time)... +2025-10-06 20:26:03,798 - AgenticMedicalRAG - INFO - LLM initialized successfully +2025-10-06 20:26:03,799 - AgenticMedicalRAG - INFO - 🔄 Background Init: All components initialized successfully (100%) +2025-10-06 20:26:03,799 - AgenticMedicalRAG - INFO - ✅ Background initialization completed successfully +2025-10-06 20:26:08,758 - AgenticMedicalRAG - INFO - Processing user input (attempt 1): What is the recommended first-line treatment for a... +2025-10-06 20:26:20,881 - AgenticMedicalRAG - INFO - Performing automatic validation for streaming response... +2025-10-06 20:26:20,922 - AgenticMedicalRAG - INFO - Medical answer validator initialized successfully +2025-10-06 20:26:20,923 - AgenticMedicalRAG - INFO - GitHub storage initialized for MoazEldsouky/cloud-data-store +2025-10-06 20:26:21,802 - AgenticMedicalRAG - INFO - Starting validation for interaction 4 +2025-10-06 20:26:28,649 - AgenticMedicalRAG - INFO - Assigned unique interaction ID: 4 +2025-10-06 20:26:30,776 - AgenticMedicalRAG - INFO - Successfully uploaded medical_data/evaluation_results.json to GitHub +2025-10-06 20:26:30,778 - AgenticMedicalRAG - INFO - Evaluation saved to GitHub with ID: 4 +2025-10-06 20:26:36,348 - AgenticMedicalRAG - INFO - Successfully processed user input: What is the recommended first-line treatment for a... +2025-10-09 18:18:12,151 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-10-09 18:18:14,230 - AgenticMedicalRAG - INFO - 🚀 Starting background initialization... +2025-10-09 18:18:14,231 - AgenticMedicalRAG - INFO - 🔄 Background Init: Starting background initialization... (0%) +2025-10-09 18:18:14,232 - AgenticMedicalRAG - INFO - 🔄 Background Init: Loading embedding model... (10%) +2025-10-09 18:18:14,233 - AgenticMedicalRAG - INFO - Loading embedding model (first time)... +2025-10-09 18:18:37,093 - AgenticMedicalRAG - INFO - Embedding model loaded successfully +2025-10-09 18:18:37,094 - AgenticMedicalRAG - INFO - 🔄 Background Init: Embedding model loaded successfully (40%) +2025-10-09 18:18:37,095 - AgenticMedicalRAG - INFO - 🔄 Background Init: Initializing retrievers and loading chunks... (50%) +2025-10-09 18:18:37,096 - AgenticMedicalRAG - INFO - 🔄 Initializing retrievers (first time use)... +2025-10-09 18:18:37,096 - AgenticMedicalRAG - INFO - 🔄 Processing new data and updating vector store if needed... +2025-10-09 18:18:37,318 - AgenticMedicalRAG - INFO - 📦 Loading chunks cache for BM25 retriever... +2025-10-09 18:18:37,369 - AgenticMedicalRAG - INFO - 🔍 Creating vector retriever... +2025-10-09 18:18:37,370 - AgenticMedicalRAG - INFO - 📝 Creating BM25 retriever... +2025-10-09 18:18:37,831 - AgenticMedicalRAG - INFO - 🔄 Creating hybrid retriever... +2025-10-09 18:18:37,832 - AgenticMedicalRAG - INFO - ✅ Retrievers initialized successfully. +2025-10-09 18:18:37,832 - AgenticMedicalRAG - INFO - 🔄 Background Init: Retrievers initialized successfully (90%) +2025-10-09 18:18:37,833 - AgenticMedicalRAG - INFO - 🔄 Background Init: Warming up LLM... (95%) +2025-10-09 18:18:37,834 - AgenticMedicalRAG - INFO - Initializing LLM (first time)... +2025-10-09 18:18:38,491 - AgenticMedicalRAG - INFO - LLM initialized successfully +2025-10-09 18:18:38,492 - AgenticMedicalRAG - INFO - 🔄 Background Init: All components initialized successfully (100%) +2025-10-09 18:18:38,493 - AgenticMedicalRAG - INFO - ✅ Background initialization completed successfully +2025-10-09 18:21:19,426 - AgenticMedicalRAG - INFO - Processing user input (attempt 1): How does consolidation therapy with durvalumab imp... +2025-10-09 18:21:32,307 - AgenticMedicalRAG - INFO - Successfully processed user input: How does consolidation therapy with durvalumab imp... +2025-10-09 18:21:32,308 - AgenticMedicalRAG - INFO - Performing automatic validation... +2025-10-09 18:21:32,355 - AgenticMedicalRAG - INFO - Medical answer validator initialized successfully +2025-10-09 18:21:32,355 - AgenticMedicalRAG - INFO - GitHub storage initialized for MoazEldsouky/cloud-data-store +2025-10-09 18:21:33,079 - AgenticMedicalRAG - INFO - Starting validation for interaction 8 +2025-10-09 18:21:40,998 - AgenticMedicalRAG - INFO - Assigned unique interaction ID: 8 +2025-10-09 18:21:43,940 - AgenticMedicalRAG - INFO - Successfully uploaded medical_data/evaluation_results.json to GitHub +2025-10-09 18:21:43,942 - AgenticMedicalRAG - INFO - Evaluation saved to GitHub with ID: 8 +2025-10-09 18:28:15,416 - AgenticMedicalRAG - INFO - Processing user input (attempt 1): i found that Afinitor has these side effects fever... +2025-10-09 18:28:19,280 - AgenticMedicalRAG - INFO - Successfully uploaded medical_data/side_effects_reports.csv to GitHub +2025-10-09 18:28:20,578 - AgenticMedicalRAG - INFO - Successfully processed user input: i found that Afinitor has these side effects fever... +2025-10-11 02:09:02,056 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-10-11 02:14:41,928 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-10-11 02:28:08,651 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-10-11 02:28:09,720 - AgenticMedicalRAG - INFO - 🚀 Starting background initialization... +2025-10-11 02:28:09,721 - AgenticMedicalRAG - INFO - 🔄 Background Init: Starting background initialization... (0%) +2025-10-11 02:28:09,721 - AgenticMedicalRAG - INFO - 🔄 Background Init: Loading embedding model... (10%) +2025-10-11 02:28:09,722 - AgenticMedicalRAG - INFO - Loading embedding model (first time)... +2025-10-11 02:28:28,023 - AgenticMedicalRAG - INFO - Embedding model loaded successfully +2025-10-11 02:28:28,024 - AgenticMedicalRAG - INFO - 🔄 Background Init: Embedding model loaded successfully (40%) +2025-10-11 02:28:28,025 - AgenticMedicalRAG - INFO - 🔄 Background Init: Initializing retrievers and loading chunks... (50%) +2025-10-11 02:28:28,026 - AgenticMedicalRAG - INFO - 🔄 Initializing retrievers (first time use)... +2025-10-11 02:28:28,026 - AgenticMedicalRAG - INFO - 🔄 Processing new data and updating vector store if needed... +2025-10-11 02:28:28,175 - AgenticMedicalRAG - INFO - 📦 Loading chunks cache for BM25 retriever... +2025-10-11 02:28:28,202 - AgenticMedicalRAG - INFO - 🔍 Creating vector retriever... +2025-10-11 02:28:28,202 - AgenticMedicalRAG - INFO - 📝 Creating BM25 retriever... +2025-10-11 02:28:28,462 - AgenticMedicalRAG - INFO - 🔄 Creating hybrid retriever... +2025-10-11 02:28:28,462 - AgenticMedicalRAG - INFO - ✅ Retrievers initialized successfully. +2025-10-11 02:28:28,463 - AgenticMedicalRAG - INFO - 🔄 Background Init: Retrievers initialized successfully (90%) +2025-10-11 02:28:28,464 - AgenticMedicalRAG - INFO - 🔄 Background Init: Warming up LLM... (95%) +2025-10-11 02:28:28,464 - AgenticMedicalRAG - INFO - Initializing LLM (first time)... +2025-10-11 02:28:29,009 - AgenticMedicalRAG - INFO - LLM initialized successfully +2025-10-11 02:28:29,009 - AgenticMedicalRAG - INFO - 🔄 Background Init: All components initialized successfully (100%) +2025-10-11 02:28:29,010 - AgenticMedicalRAG - INFO - ✅ Background initialization completed successfully +2025-10-11 02:28:44,918 - AgenticMedicalRAG - INFO - Processing user input (attempt 1): What is the role of durvalumab in stage III NSCLC ... +2025-10-11 02:28:53,037 - AgenticMedicalRAG - INFO - Successfully processed user input: What is the role of durvalumab in stage III NSCLC ... +2025-10-11 02:28:53,038 - AgenticMedicalRAG - INFO - Performing automatic validation... +2025-10-11 02:28:53,073 - AgenticMedicalRAG - INFO - Medical answer validator initialized successfully +2025-10-11 02:28:53,074 - AgenticMedicalRAG - INFO - GitHub storage initialized for MoazEldsouky/cloud-data-store +2025-10-11 02:28:53,674 - AgenticMedicalRAG - INFO - Starting validation for interaction 9 +2025-10-11 02:29:01,732 - AgenticMedicalRAG - INFO - Assigned unique interaction ID: 9 +2025-10-11 02:29:04,117 - AgenticMedicalRAG - INFO - Successfully uploaded medical_data/evaluation_results.json to GitHub +2025-10-11 02:29:04,119 - AgenticMedicalRAG - INFO - Evaluation saved to GitHub with ID: 9 +2025-10-11 02:31:36,593 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-10-11 02:31:49,474 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-10-11 02:31:50,210 - AgenticMedicalRAG - INFO - 🚀 Starting background initialization... +2025-10-11 02:31:50,216 - AgenticMedicalRAG - INFO - 🔄 Background Init: Starting background initialization... (0%) +2025-10-11 02:31:50,217 - AgenticMedicalRAG - INFO - 🔄 Background Init: Loading embedding model... (10%) +2025-10-11 02:31:50,218 - AgenticMedicalRAG - INFO - Loading embedding model (first time)... +2025-10-11 02:33:35,327 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-10-11 02:35:01,172 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-10-11 02:35:05,338 - AgenticMedicalRAG - INFO - 🚀 Starting background initialization... +2025-10-11 02:35:05,339 - AgenticMedicalRAG - INFO - 🔄 Background Init: Starting background initialization... (0%) +2025-10-11 02:35:05,340 - AgenticMedicalRAG - INFO - 🔄 Background Init: Loading embedding model... (10%) +2025-10-11 02:35:05,340 - AgenticMedicalRAG - INFO - Loading embedding model (first time)... +2025-10-11 02:35:14,932 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-10-11 02:35:15,896 - AgenticMedicalRAG - INFO - 🚀 Starting background initialization... +2025-10-11 02:35:15,897 - AgenticMedicalRAG - INFO - 🔄 Background Init: Starting background initialization... (0%) +2025-10-11 02:35:15,898 - AgenticMedicalRAG - INFO - 🔄 Background Init: Loading embedding model... (10%) +2025-10-11 02:35:15,899 - AgenticMedicalRAG - INFO - Loading embedding model (first time)... +2025-10-11 02:35:25,027 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-10-11 02:35:25,876 - AgenticMedicalRAG - INFO - 🚀 Starting background initialization... +2025-10-11 02:35:25,878 - AgenticMedicalRAG - INFO - 🔄 Background Init: Starting background initialization... (0%) +2025-10-11 02:35:25,878 - AgenticMedicalRAG - INFO - 🔄 Background Init: Loading embedding model... (10%) +2025-10-11 02:35:25,878 - AgenticMedicalRAG - INFO - Loading embedding model (first time)... +2025-10-11 02:35:35,371 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-10-11 02:35:35,387 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-10-11 02:35:36,157 - AgenticMedicalRAG - INFO - 🚀 Starting background initialization... +2025-10-11 02:35:36,158 - AgenticMedicalRAG - INFO - 🔄 Background Init: Starting background initialization... (0%) +2025-10-11 02:35:36,158 - AgenticMedicalRAG - INFO - 🔄 Background Init: Loading embedding model... (10%) +2025-10-11 02:35:36,158 - AgenticMedicalRAG - INFO - Loading embedding model (first time)... +2025-10-11 02:35:44,205 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-10-11 02:35:44,227 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-10-11 02:35:44,988 - AgenticMedicalRAG - INFO - 🚀 Starting background initialization... +2025-10-11 02:35:44,990 - AgenticMedicalRAG - INFO - 🔄 Background Init: Starting background initialization... (0%) +2025-10-11 02:35:44,990 - AgenticMedicalRAG - INFO - 🔄 Background Init: Loading embedding model... (10%) +2025-10-11 02:35:44,991 - AgenticMedicalRAG - INFO - Loading embedding model (first time)... +2025-10-11 02:35:52,736 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-10-11 02:35:52,751 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-10-11 02:35:53,477 - AgenticMedicalRAG - INFO - 🚀 Starting background initialization... +2025-10-11 02:35:53,479 - AgenticMedicalRAG - INFO - 🔄 Background Init: Starting background initialization... (0%) +2025-10-11 02:35:53,479 - AgenticMedicalRAG - INFO - 🔄 Background Init: Loading embedding model... (10%) +2025-10-11 02:35:53,479 - AgenticMedicalRAG - INFO - Loading embedding model (first time)... +2025-10-11 02:36:07,384 - AgenticMedicalRAG - INFO - Embedding model loaded successfully +2025-10-11 02:36:07,385 - AgenticMedicalRAG - INFO - 🔄 Background Init: Embedding model loaded successfully (40%) +2025-10-11 02:36:07,385 - AgenticMedicalRAG - INFO - 🔄 Background Init: Initializing retrievers and loading chunks... (50%) +2025-10-11 02:36:07,387 - AgenticMedicalRAG - INFO - 🔄 Initializing retrievers (first time use)... +2025-10-11 02:36:07,387 - AgenticMedicalRAG - INFO - 🔄 Processing new data and updating vector store if needed... +2025-10-11 02:36:07,815 - AgenticMedicalRAG - INFO - 📦 Loading chunks cache for BM25 retriever... +2025-10-11 02:36:07,829 - AgenticMedicalRAG - INFO - 🔍 Creating vector retriever... +2025-10-11 02:36:07,829 - AgenticMedicalRAG - INFO - 📝 Creating BM25 retriever... +2025-10-11 02:36:08,082 - AgenticMedicalRAG - INFO - 🔄 Creating hybrid retriever... +2025-10-11 02:36:08,083 - AgenticMedicalRAG - INFO - ✅ Retrievers initialized successfully. +2025-10-11 02:36:08,083 - AgenticMedicalRAG - INFO - 🔄 Background Init: Retrievers initialized successfully (90%) +2025-10-11 02:36:08,083 - AgenticMedicalRAG - INFO - 🔄 Background Init: Warming up LLM... (95%) +2025-10-11 02:36:08,083 - AgenticMedicalRAG - INFO - Initializing LLM (first time)... +2025-10-11 02:36:09,261 - AgenticMedicalRAG - INFO - LLM initialized successfully +2025-10-11 02:36:09,262 - AgenticMedicalRAG - INFO - 🔄 Background Init: All components initialized successfully (100%) +2025-10-11 02:36:09,262 - AgenticMedicalRAG - INFO - ✅ Background initialization completed successfully +2025-10-11 02:38:18,468 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-10-11 02:38:18,488 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-10-11 02:38:19,354 - AgenticMedicalRAG - INFO - 🚀 Starting background initialization... +2025-10-11 02:38:19,355 - AgenticMedicalRAG - INFO - 🔄 Background Init: Starting background initialization... (0%) +2025-10-11 02:38:19,356 - AgenticMedicalRAG - INFO - 🔄 Background Init: Loading embedding model... (10%) +2025-10-11 02:38:19,356 - AgenticMedicalRAG - INFO - Loading embedding model (first time)... +2025-10-11 02:38:25,791 - AgenticMedicalRAG - INFO - Embedding model loaded successfully +2025-10-11 02:38:25,791 - AgenticMedicalRAG - INFO - 🔄 Background Init: Embedding model loaded successfully (40%) +2025-10-11 02:38:25,791 - AgenticMedicalRAG - INFO - 🔄 Background Init: Initializing retrievers and loading chunks... (50%) +2025-10-11 02:38:25,793 - AgenticMedicalRAG - INFO - 🔄 Initializing retrievers (first time use)... +2025-10-11 02:38:25,793 - AgenticMedicalRAG - INFO - 🔄 Processing new data and updating vector store if needed... +2025-10-11 02:38:25,877 - AgenticMedicalRAG - INFO - 📦 Loading chunks cache for BM25 retriever... +2025-10-11 02:38:25,893 - AgenticMedicalRAG - INFO - 🔍 Creating vector retriever... +2025-10-11 02:38:25,893 - AgenticMedicalRAG - INFO - 📝 Creating BM25 retriever... +2025-10-11 02:38:26,272 - AgenticMedicalRAG - INFO - 🔄 Creating hybrid retriever... +2025-10-11 02:38:26,274 - AgenticMedicalRAG - INFO - ✅ Retrievers initialized successfully. +2025-10-11 02:38:26,274 - AgenticMedicalRAG - INFO - 🔄 Background Init: Retrievers initialized successfully (90%) +2025-10-11 02:38:26,274 - AgenticMedicalRAG - INFO - 🔄 Background Init: Warming up LLM... (95%) +2025-10-11 02:38:26,275 - AgenticMedicalRAG - INFO - Initializing LLM (first time)... +2025-10-11 02:38:27,189 - AgenticMedicalRAG - INFO - LLM initialized successfully +2025-10-11 02:38:27,189 - AgenticMedicalRAG - INFO - 🔄 Background Init: All components initialized successfully (100%) +2025-10-11 02:38:27,190 - AgenticMedicalRAG - INFO - ✅ Background initialization completed successfully +2025-10-11 02:44:55,723 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-10-11 02:44:55,745 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-10-11 02:44:58,299 - AgenticMedicalRAG - INFO - 🚀 Starting background initialization... +2025-10-11 02:44:58,299 - AgenticMedicalRAG - INFO - 🔄 Background Init: Starting background initialization... (0%) +2025-10-11 02:44:58,300 - AgenticMedicalRAG - INFO - 🔄 Background Init: Loading embedding model... (10%) +2025-10-11 02:44:58,300 - AgenticMedicalRAG - INFO - Loading embedding model (first time)... +2025-10-11 02:45:12,707 - AgenticMedicalRAG - INFO - Embedding model loaded successfully +2025-10-11 02:45:12,707 - AgenticMedicalRAG - INFO - 🔄 Background Init: Embedding model loaded successfully (40%) +2025-10-11 02:45:12,708 - AgenticMedicalRAG - INFO - 🔄 Background Init: Initializing retrievers and loading chunks... (50%) +2025-10-11 02:45:12,709 - AgenticMedicalRAG - INFO - 🔄 Initializing retrievers (first time use)... +2025-10-11 02:45:12,709 - AgenticMedicalRAG - INFO - 🔄 Processing new data and updating vector store if needed... +2025-10-11 02:45:13,106 - AgenticMedicalRAG - INFO - 📦 Loading chunks cache for BM25 retriever... +2025-10-11 02:45:13,127 - AgenticMedicalRAG - INFO - 🔍 Creating vector retriever... +2025-10-11 02:45:13,128 - AgenticMedicalRAG - INFO - 📝 Creating BM25 retriever... +2025-10-11 02:45:13,364 - AgenticMedicalRAG - INFO - 🔄 Creating hybrid retriever... +2025-10-11 02:45:13,365 - AgenticMedicalRAG - INFO - ✅ Retrievers initialized successfully. +2025-10-11 02:45:13,365 - AgenticMedicalRAG - INFO - 🔄 Background Init: Retrievers initialized successfully (90%) +2025-10-11 02:45:13,365 - AgenticMedicalRAG - INFO - 🔄 Background Init: Warming up LLM... (95%) +2025-10-11 02:45:13,365 - AgenticMedicalRAG - INFO - Initializing LLM (first time)... +2025-10-11 02:45:14,368 - AgenticMedicalRAG - INFO - LLM initialized successfully +2025-10-11 02:45:14,368 - AgenticMedicalRAG - INFO - 🔄 Background Init: All components initialized successfully (100%) +2025-10-11 02:45:14,368 - AgenticMedicalRAG - INFO - ✅ Background initialization completed successfully +2025-10-11 02:46:43,529 - AgenticMedicalRAG - INFO - Processing user input (attempt 1): What is the role of durvalumab in stage III NSCLC ... +2025-10-11 02:46:43,530 - AgenticMedicalRAG - INFO - Initializing LLM (first time)... +2025-10-11 02:46:43,530 - AgenticMedicalRAG - INFO - LLM initialized successfully +2025-10-11 02:46:45,550 - AgenticMedicalRAG - INFO - 🔄 Initializing retrievers (first time use)... +2025-10-11 02:46:45,550 - AgenticMedicalRAG - INFO - 🔄 Processing new data and updating vector store if needed... +2025-10-11 02:46:45,595 - AgenticMedicalRAG - INFO - 📦 Loading chunks cache for BM25 retriever... +2025-10-11 02:46:46,017 - AgenticMedicalRAG - INFO - 🔍 Creating vector retriever... +2025-10-11 02:46:46,017 - AgenticMedicalRAG - INFO - 📝 Creating BM25 retriever... +2025-10-11 02:46:46,427 - AgenticMedicalRAG - INFO - 🔄 Creating hybrid retriever... +2025-10-11 02:46:46,428 - AgenticMedicalRAG - INFO - ✅ Retrievers initialized successfully. +2025-10-11 02:46:52,141 - AgenticMedicalRAG - INFO - Successfully processed user input: What is the role of durvalumab in stage III NSCLC ... +2025-10-11 02:46:52,141 - AgenticMedicalRAG - INFO - Performing automatic validation... +2025-10-11 02:46:53,106 - AgenticMedicalRAG - INFO - Medical answer validator initialized successfully +2025-10-11 02:46:53,106 - AgenticMedicalRAG - INFO - GitHub storage initialized for MoazEldsouky/cloud-data-store +2025-10-11 02:46:54,092 - AgenticMedicalRAG - INFO - Starting validation for interaction 10 +2025-10-11 02:47:04,166 - AgenticMedicalRAG - INFO - Assigned unique interaction ID: 10 +2025-10-11 02:47:06,949 - AgenticMedicalRAG - INFO - Successfully uploaded medical_data/evaluation_results.json to GitHub +2025-10-11 02:47:06,950 - AgenticMedicalRAG - INFO - Evaluation saved to GitHub with ID: 10 +2025-10-11 02:47:14,726 - AgenticMedicalRAG - INFO - Processing user input (attempt 1): i found that Afinitor has these side effects fever... +2025-10-11 02:47:16,145 - AgenticMedicalRAG - INFO - GitHub storage initialized for MoazEldsouky/cloud-data-store +2025-10-11 02:47:18,099 - AgenticMedicalRAG - INFO - Successfully uploaded medical_data/side_effects_reports.csv to GitHub +2025-10-11 02:47:18,944 - AgenticMedicalRAG - INFO - Successfully processed user input: i found that Afinitor has these side effects fever... +2025-10-11 03:08:18,657 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-10-11 03:08:18,686 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-10-11 03:08:19,913 - AgenticMedicalRAG - INFO - 🚀 Starting background initialization... +2025-10-11 03:08:19,914 - AgenticMedicalRAG - INFO - 🔄 Background Init: Starting background initialization... (0%) +2025-10-11 03:08:19,914 - AgenticMedicalRAG - INFO - 🔄 Background Init: Loading embedding model... (10%) +2025-10-11 03:08:19,915 - AgenticMedicalRAG - INFO - Loading embedding model (first time)... +2025-10-11 03:08:28,775 - AgenticMedicalRAG - INFO - Embedding model loaded successfully +2025-10-11 03:08:28,775 - AgenticMedicalRAG - INFO - 🔄 Background Init: Embedding model loaded successfully (40%) +2025-10-11 03:08:28,776 - AgenticMedicalRAG - INFO - 🔄 Background Init: Initializing retrievers and loading chunks... (50%) +2025-10-11 03:08:28,778 - AgenticMedicalRAG - INFO - 🔄 Initializing retrievers (first time use)... +2025-10-11 03:08:28,778 - AgenticMedicalRAG - INFO - 🔄 Processing new data and updating vector store if needed... +2025-10-11 03:08:28,841 - AgenticMedicalRAG - INFO - 📦 Loading chunks cache for BM25 retriever... +2025-10-11 03:08:28,855 - AgenticMedicalRAG - INFO - 🔍 Creating vector retriever... +2025-10-11 03:08:28,856 - AgenticMedicalRAG - INFO - 📝 Creating BM25 retriever... +2025-10-11 03:08:29,173 - AgenticMedicalRAG - INFO - 🔄 Creating hybrid retriever... +2025-10-11 03:08:29,174 - AgenticMedicalRAG - INFO - ✅ Retrievers initialized successfully. +2025-10-11 03:08:29,174 - AgenticMedicalRAG - INFO - 🔄 Background Init: Retrievers initialized successfully (90%) +2025-10-11 03:08:29,174 - AgenticMedicalRAG - INFO - 🔄 Background Init: Warming up LLM... (95%) +2025-10-11 03:08:29,175 - AgenticMedicalRAG - INFO - Initializing LLM (first time)... +2025-10-11 03:08:30,124 - AgenticMedicalRAG - INFO - LLM initialized successfully +2025-10-11 03:08:30,124 - AgenticMedicalRAG - INFO - 🔄 Background Init: All components initialized successfully (100%) +2025-10-11 03:08:30,125 - AgenticMedicalRAG - INFO - ✅ Background initialization completed successfully +2025-10-11 03:08:58,104 - AgenticMedicalRAG - INFO - Processing user input (attempt 1): i found that Afinitor has these side effects fever... +2025-10-11 03:08:58,104 - AgenticMedicalRAG - INFO - Initializing LLM (first time)... +2025-10-11 03:08:58,105 - AgenticMedicalRAG - INFO - LLM initialized successfully +2025-10-11 03:08:59,966 - AgenticMedicalRAG - INFO - GitHub storage initialized for MoazEldsouky/cloud-data-store +2025-10-11 03:09:01,856 - AgenticMedicalRAG - INFO - Successfully uploaded medical_data/side_effects_reports.csv to GitHub +2025-10-11 03:09:03,075 - AgenticMedicalRAG - INFO - Successfully processed user input: i found that Afinitor has these side effects fever... +2025-10-11 03:17:32,067 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-10-11 03:17:32,086 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-10-11 03:17:32,800 - AgenticMedicalRAG - INFO - 🚀 Starting background initialization... +2025-10-11 03:17:32,801 - AgenticMedicalRAG - INFO - 🔄 Background Init: Starting background initialization... (0%) +2025-10-11 03:17:32,802 - AgenticMedicalRAG - INFO - 🔄 Background Init: Loading embedding model... (10%) +2025-10-11 03:17:32,802 - AgenticMedicalRAG - INFO - Loading embedding model (first time)... +2025-10-11 03:17:39,488 - AgenticMedicalRAG - INFO - Embedding model loaded successfully +2025-10-11 03:17:39,488 - AgenticMedicalRAG - INFO - 🔄 Background Init: Embedding model loaded successfully (40%) +2025-10-11 03:17:39,489 - AgenticMedicalRAG - INFO - 🔄 Background Init: Initializing retrievers and loading chunks... (50%) +2025-10-11 03:17:39,490 - AgenticMedicalRAG - INFO - 🔄 Initializing retrievers (first time use)... +2025-10-11 03:17:39,490 - AgenticMedicalRAG - INFO - 🔄 Processing new data and updating vector store if needed... +2025-10-11 03:17:39,591 - AgenticMedicalRAG - INFO - 📦 Loading chunks cache for BM25 retriever... +2025-10-11 03:17:39,618 - AgenticMedicalRAG - INFO - 🔍 Creating vector retriever... +2025-10-11 03:17:39,618 - AgenticMedicalRAG - INFO - 📝 Creating BM25 retriever... +2025-10-11 03:17:40,108 - AgenticMedicalRAG - INFO - 🔄 Creating hybrid retriever... +2025-10-11 03:17:40,108 - AgenticMedicalRAG - INFO - ✅ Retrievers initialized successfully. +2025-10-11 03:17:40,108 - AgenticMedicalRAG - INFO - 🔄 Background Init: Retrievers initialized successfully (90%) +2025-10-11 03:17:40,108 - AgenticMedicalRAG - INFO - 🔄 Background Init: Warming up LLM... (95%) +2025-10-11 03:17:40,109 - AgenticMedicalRAG - INFO - Initializing LLM (first time)... +2025-10-11 03:17:41,494 - AgenticMedicalRAG - INFO - LLM initialized successfully +2025-10-11 03:17:41,494 - AgenticMedicalRAG - INFO - 🔄 Background Init: All components initialized successfully (100%) +2025-10-11 03:17:41,495 - AgenticMedicalRAG - INFO - ✅ Background initialization completed successfully +2025-10-11 00:36:26,189 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-10-11 00:36:26,189 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-10-11 00:36:48,003 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-10-11 00:36:48,003 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-10-11 00:37:16,374 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-10-11 00:37:16,375 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-10-11 00:41:11,107 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-10-11 00:50:24,570 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-10-11 04:26:41,002 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-10-11 09:48:32,554 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-10-11 09:51:20,372 - AgenticMedicalRAG - INFO - Configuration validation completed +2025-10-11 09:56:42,170 - AgenticMedicalRAG - INFO - Processing user input (attempt 1): i found that Afinitor has these side effects fever... +2025-10-11 09:56:42,170 - AgenticMedicalRAG - INFO - Initializing LLM (first time)... +2025-10-11 09:56:43,618 - AgenticMedicalRAG - INFO - LLM initialized successfully +2025-10-11 09:56:49,346 - AgenticMedicalRAG - INFO - GitHub storage initialized for MoazEldsouky/cloud-data-store +2025-10-11 09:56:51,485 - AgenticMedicalRAG - INFO - Successfully uploaded medical_data/side_effects_reports.csv to GitHub +2025-10-11 09:56:53,147 - AgenticMedicalRAG - INFO - Successfully processed user input: i found that Afinitor has these side effects fever... +2025-10-11 10:06:17,157 - AgenticMedicalRAG - INFO - Processing user input (attempt 1): i found that Afinitor has these side effects fever... +2025-10-11 10:06:21,851 - AgenticMedicalRAG - INFO - Successfully uploaded medical_data/side_effects_reports.csv to GitHub +2025-10-11 10:06:23,502 - AgenticMedicalRAG - INFO - Successfully processed user input: i found that Afinitor has these side effects fever... +2025-10-11 10:31:03,423 - AgenticMedicalRAG - INFO - Processing user input (attempt 1): i found that Afinitor has these side effects fever... +2025-10-11 10:31:07,847 - AgenticMedicalRAG - INFO - Successfully uploaded medical_data/side_effects_reports.csv to GitHub +2025-10-11 10:31:09,423 - AgenticMedicalRAG - INFO - Successfully processed user input: i found that Afinitor has these side effects fever... +2025-10-11 10:51:36,134 - AgenticMedicalRAG - INFO - Processing user input (attempt 1): i found that Afinitor has these side effects fever... +2025-10-11 10:52:02,453 - AgenticMedicalRAG - INFO - Successfully uploaded medical_data/side_effects_reports.csv to GitHub +2025-10-11 10:52:04,066 - AgenticMedicalRAG - INFO - Successfully processed user input: i found that Afinitor has these side effects fever... +2025-10-11 10:56:32,523 - AgenticMedicalRAG - INFO - Processing user input (attempt 1): i found that Afinitor has these side effects fever... +2025-10-11 10:56:36,573 - AgenticMedicalRAG - INFO - Successfully uploaded medical_data/side_effects_reports.csv to GitHub +2025-10-11 10:56:37,885 - AgenticMedicalRAG - INFO - Successfully processed user input: i found that Afinitor has these side effects fever... +2025-10-11 11:05:26,633 - AgenticMedicalRAG - INFO - Processing user input (attempt 1): i found that Afinitor has these side effects fever... +2025-10-11 11:05:32,331 - AgenticMedicalRAG - INFO - Successfully uploaded medical_data/side_effects_reports.csv to GitHub +2025-10-11 11:05:33,836 - AgenticMedicalRAG - INFO - Successfully processed user input: i found that Afinitor has these side effects fever... diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000000000000000000000000000000000000..a47ee53058a5bbea5e55083edea3690e71517a29 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,33 @@ + +# API +fastapi==0.116.1 +uvicorn==0.35.0 + +# LangChain ecosystem - only what's needed +langchain==0.3.27 +langchain_community==0.3.27 +langchain_openai==0.3.28 +langchain_huggingface==0.3.1 +langchain-pymupdf4llm==0.4.1 + +# OpenAI +openai==1.99.2 + +# Data processing +pandas==2.3.1 +pydantic==2.11.7 + +# Utilities +python-dotenv==1.1.1 +pytz==2025.2 +requests==2.32.4 + +# Embeddings and search - CPU optimized versions +sentence-transformers==5.0.0 +faiss-cpu==1.11.0.post1 # CPU version is much smaller +rank-bm25==0.2.2 + +# Fix for numpy and torch compatibility +numpy<2 +torch==2.2.2+cpu +--extra-index-url https://download.pytorch.org/whl/cpu diff --git a/start_api.py b/start_api.py new file mode 100644 index 0000000000000000000000000000000000000000..e07e73942c8e9ccbfd8759ef621f41c94fca0f4d --- /dev/null +++ b/start_api.py @@ -0,0 +1,21 @@ +""" +Startup script for Medical RAG AI Advisor API +""" +import sys +import os +import uvicorn + +# Add core to Python path +sys.path.append(os.path.join(os.path.dirname(__file__), 'core')) + +if __name__ == "__main__": + + uvicorn.run( + "api.app:app", + host="127.0.0.1", # Use localhost instead of 0.0.0.0 + port=8000, + reload=True, # Disable reload in production for faster startup + log_level="info", + access_log=True, + workers=1 # Single worker for development + )