Skip to content

Latest commit

Β 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Research Helper

A comprehensive research assistance application built with React.js frontend and FastAPI/Django backends, featuring AI-powered academic paper search, document processing, and intelligent Q&A with tool calling capabilities.

✨ Features

Frontend (React.js + Vite + Tailwind CSS)

  • Modern UI/UX: Beautiful, responsive design with dark/light mode support
  • Real-time Chat Interface: Interactive research Q&A with typing indicators and message history
  • Authentication: JWT-based authentication with protected routes
  • Document Upload: Support for research papers (PDF, TXT, MD)
  • Modular Architecture: Clean component structure following DRY and SOLID principles
  • Responsive Design: Works seamlessly on desktop, tablet, and mobile devices

Backend (FastAPI + Django REST Framework)

  • πŸ€– AI Research Assistant: Integration with Google Gemini AI and Qdrant vector database
  • πŸ“š Academic Search: Google Scholar integration for paper discovery
  • πŸ” Web Search: SerpAPI integration for current information
  • πŸ› οΈ Tool Calling: LangChain agent orchestration for multi-tool queries
  • πŸ“„ Document Processing: RAG (Retrieval-Augmented Generation) with vector embeddings
  • πŸ‘€ User Management: JWT authentication with refresh token support
  • πŸ’Ύ Chat History: Persistent storage with source attribution
  • πŸ”„ Dual Backend: Django (legacy) + FastAPI (modern, production-ready)

AI Capabilities

  • Research Q&A: Context-aware answers from academic papers and web sources
  • Smart Tool Selection: Automatic routing to Google Scholar, web search, or local documents
  • Vector Search: Efficient similarity search with Qdrant
  • Source Attribution: Transparent citations for all responses
  • Scalable Architecture: Microservices-ready with Docker Compose

πŸ—οΈ Technology Stack

Frontend

  • React.js: Modern React with hooks and functional components
  • Vite: Fast build tool and development server
  • Tailwind CSS: Utility-first CSS framework
  • React Router: Client-side routing
  • React Hot Toast: User-friendly notifications
  • Axios: HTTP client for API calls
  • JWT Authentication: Secure token-based authentication

Backend

  • FastAPI 0.115.0: High-performance async API framework
  • Django REST Framework: Legacy API (fully functional)
  • PostgreSQL: Primary database with SQLAlchemy 2.0 ORM
  • Qdrant: Vector database for semantic search and RAG
  • LangChain 0.3.26: AI agent framework with tool calling
  • Google Generative AI: Gemini 2.0 Flash Exp model
  • Scholarly 1.7.11: Google Scholar API wrapper
  • SerpAPI: Web search integration

πŸš€ Quick Start

Prerequisites

  • Node.js 16+ and npm
  • Python 3.11+
  • Docker & Docker Compose
  • Google AI API key
  • SerpAPI key (optional, for web search)

🐳 Docker Setup (Recommended)

  1. Clone the repository

    git clone <repository-url>
    cd Medical-Chatbot
  2. Configure environment variables

    # FastAPI Backend
    cd serverfapi
    cp .env.example .env.dev
    # Edit .env.dev with your API credentials
  3. Start all services

    # Development mode
    docker compose -f docker-compose.dev.yml up
    
    # Production mode
    docker compose -f docker-compose.prod.yml up

    Services:

Manual Backend Setup (FastAPI)

  1. Set up Python environment

    cd serverfapi
    python -m venv venv
    source venv/bin/activate  # On Windows: venv\Scripts\activate
    pip install -r requirements.txt
  2. Run Qdrant locally

    docker run -p 6333:6333 -p 6334:6334 qdrant/qdrant:latest
  3. Run database migrations

    # Will be created automatically on first run
    python manage.py createsuperuser
  4. Start the Django server

    python manage.py runserver

Frontend Setup

  1. Install dependencies

    cd client
    npm install
  2. Configure environment variables

    cp .env.local.example .env.local
    # Edit .env.local with your backend URL
  3. Start the development server

    uvicorn app.main:app --reload --host 0.0.0.0 --port 8000

Frontend Setup

  1. Install dependencies

    cd client
    npm install
  2. Configure environment variables

    cp .env.local.example .env.local
    # Edit .env.local with your backend URL
  3. Start the development server

    npm run dev

βš™οΈ Configuration

Environment Variables

FastAPI Backend (.env.dev / .env.prod)

# App
APP_NAME=Research Helper API
DEBUG=True
SECRET_KEY=your-secret-key-change-in-production

# Database
DATABASE_URL=postgresql://postgres:postgres@db:5432/research_helper

# AI & Search
GOOGLE_API_KEY=your-google-gemini-api-key
SERPAPI_API_KEY=your-serpapi-key

# Qdrant Vector Database
QDRANT_HOST=qdrant
QDRANT_PORT=6333
QDRANT_COLLECTION_NAME=research_papers

# JWT
ACCESS_TOKEN_EXPIRE_MINUTES=60
REFRESH_TOKEN_EXPIRE_DAYS=7

Frontend (.env.local)

VITE_BACKEND_BASE_URL=http://localhost:8001
VITE_LOGIN_URL=/api/v1/auth/login
VITE_REFRESH_TOKEN_URL=/api/v1/auth/refresh

πŸ“– Usage

Research Assistant Workflow

  1. Register/Login: Create an account or sign in
  2. Upload Documents (Optional):
    • Navigate to Documents/Knowledge Base
    • Upload research papers (PDF, TXT, MD)
    • Papers are automatically processed and embedded
  3. Ask Questions:
    • Go to Research Assistant chat
    • Type research questions
    • Enable "Use Tools" for internet/academic search
  4. Get AI Responses:
    • Receive context-aware answers
    • View source attributions
    • See which tools were used (Scholar/Web/Database)
  5. Search Papers:
    • Use dedicated search endpoint
    • Find papers on Google Scholar
    • Get structured results with citations

API Endpoints

FastAPI (http://localhost:8001/docs):

  • POST /api/v1/auth/register - User registration
  • POST /api/v1/auth/login - Login
  • POST /api/v1/research/ask - Ask research question
  • POST /api/v1/documents/upload - Upload document
  • GET /api/v1/search/papers - Search academic papers
  • GET /api/v1/search/web - Web search

πŸ€– AI Features

Tool Calling with LangChain Agents

  • Google Scholar Tool: Searches academic papers by query
  • Web Search Tool: Uses SerpAPI for current information
  • Research Database Tool: Queries local Qdrant vector store
  • Automatic Tool Selection: LLM chooses appropriate tools based on query
  • Source Attribution: Tracks which tools provided information

RAG (Retrieval-Augmented Generation)

  • Document Ingestion: Automatic chunking with RecursiveCharacterTextSplitter
  • Embedding Generation: Google Generative AI embeddings
  • Vector Storage: Qdrant for fast similarity search
  • Context Retrieval: Relevant document chunks added to prompts
  • Multi-format Support: PDF, TXT, MD files up to 50MB

Smart Responses

  • Context-Aware: Responses based on uploaded documents and web sources
  • Academic Accuracy: Information from peer-reviewed papers
  • Current Information: Web search for latest developments
  • Citation Tracking: Transparent source attribution
  • Multi-source Synthesis: Combines local docs + Scholar + Web

πŸ”’ Security Features

  • JWT Authentication: Secure token-based authentication with refresh tokens
  • Protected Routes: Authentication required for all research endpoints
  • CORS Configuration: Proper cross-origin resource sharing
  • Input Validation: Pydantic models for request/response validation
  • Password Hashing: bcrypt for secure password storage
  • SQL Injection Prevention: SQLAlchemy ORM
  • File Upload Limits: 50MB max with type validation
  • Error Handling: Comprehensive error handling and user feedback

πŸ§ͺ Testing

Backend Testing (FastAPI)

cd serverfapi
pytest

Frontend Testing

cd client
npm test

πŸ›οΈ Architecture Comparison

Feature Django (Legacy) FastAPI (Modern)
Framework Django REST Framework FastAPI
Performance Synchronous Async/Await
Docs Manual Auto-generated (OpenAPI)
Type Safety Limited Full (Pydantic)
Vector DB Pinecone Qdrant
Tool Calling No Yes (LangChain)
Academic Search No Yes (Scholarly)
Web Search No Yes (SerpAPI)

πŸ“‚ Project Structure

Medical-Chatbot/
β”œβ”€β”€ client/                 # React frontend
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ Components/     # React components
β”‚   β”‚   β”œβ”€β”€ Pages/          # Page components
β”‚   β”‚   β”œβ”€β”€ services/       # API services
β”‚   β”‚   └── utility/        # Utilities
β”‚   └── Dockerfile
β”œβ”€β”€ server/                 # Django backend (legacy)
β”‚   β”œβ”€β”€ auth_app/
β”‚   β”œβ”€β”€ chatbot_app/
β”‚   └── requirements.txt
β”œβ”€β”€ serverfapi/            # FastAPI backend (modern)
β”‚   β”œβ”€β”€ app/
β”‚   β”‚   β”œβ”€β”€ api/v1/        # API endpoints
β”‚   β”‚   β”œβ”€β”€ core/          # Configuration
β”‚   β”‚   β”œβ”€β”€ models/        # Database models
β”‚   β”‚   β”œβ”€β”€ schemas/       # Pydantic schemas
β”‚   β”‚   β”œβ”€β”€ services/      # Business logic
β”‚   β”‚   └── main.py
β”‚   β”œβ”€β”€ requirements.txt
β”‚   β”œβ”€β”€ Dockerfile.dev
β”‚   └── Dockerfile.prod
β”œβ”€β”€ docker-compose.dev.yml
β”œβ”€β”€ docker-compose.prod.yml
└── README.md

πŸš€ Deployment

Docker Production Build

docker compose -f docker-compose.prod.yml up -d --build

Services

  • Client (Nginx): Port 80 (production) / 3001 (dev)
  • FastAPI: Port 8001
  • Django: Port 8000
  • PostgreSQL: Port 5432 (internal)
  • Qdrant: Port 6333 (API), 6334 (gRPC)

πŸ“ License

This project is licensed under the MIT License.

🀝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

πŸ“§ Contact

For questions or support, please open an issue on GitHub.


Note: This Research Helper is for educational and research purposes. For production use, ensure proper API keys, security measures, and compliance with academic search APIs' terms of service.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages