Skip to content

yaswanth009/fast-api-rag

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

5 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ€– AI Document Assistant

A powerful, modern AI-powered document analysis and chat application built with FastAPI, featuring Retrieval-Augmented Generation (RAG), web search capabilities, and a beautiful responsive UI.

FastAPI Python OpenAI Milvus

✨ Features

🧠 AI-Powered Document Analysis

  • RAG (Retrieval-Augmented Generation): Upload documents and ask questions with AI-generated answers based on your content
  • Multi-format Support: PDF, DOCX, and TXT file processing
  • Smart Chunking: Intelligent document segmentation with overlap for better context
  • Semantic Search: Find relevant information using vector embeddings

🌐 Web Search Integration

  • Person Search: Automatically search the web for information about people
  • Real-time Information: Get current information from multiple web sources
  • Hybrid Responses: Combine document knowledge with web information

🎨 Modern User Interface

  • Responsive Design: Beautiful, modern UI that works on all devices
  • Dark/Light Mode: Toggle between themes with persistent preferences
  • Drag & Drop: Intuitive file upload with visual feedback
  • Real-time Status: Live system status indicators
  • Smooth Animations: Professional animations and transitions

πŸ”§ Advanced Features

  • Vector Database: Milvus Managed (Zilliz Cloud) for scalable vector storage
  • OpenAI Integration: GPT-3.5-Turbo for intelligent responses
  • RESTful API: Clean, well-documented API endpoints
  • Error Handling: Comprehensive error handling and user feedback

πŸš€ Quick Start

Prerequisites

  • Python 3.8 or higher
  • OpenAI API key
  • Milvus Managed (Zilliz Cloud) account

Installation

  1. Clone the repository

    git clone <your-repo-url>
    cd fastapi-vibe-coding
  2. Create and activate virtual environment

    python -m venv myenv
    source myenv/bin/activate  # On Windows: myenv\Scripts\activate
  3. Install dependencies

    pip install -r requirements.txt
  4. Configure environment variables

    export OPENAI_API_KEY="your-openai-api-key-here"
  5. Test OpenAI connection (optional but recommended)

    python test_openai.py
  6. Update Milvus configuration (in main.py)

    MILVUS_URI = "your-milvus-uri"
    MILVUS_TOKEN = "your-milvus-token"
    COLLECTION_NAME = "your-collection-name"
  7. Run the application

    python main.py
  8. Open your browser Navigate to http://localhost:8000 to access the beautiful web interface!

πŸ“š API Documentation

Core Endpoints

πŸ” Ask Questions

POST /ask
Content-Type: application/json

{
  "message": "What is this document about?"
}
  • RAG + Web Search: Combines document context with web information
  • Smart Person Detection: Automatically searches web for person-related queries
  • AI Synthesis: Uses GPT-3.5-Turbo for intelligent responses

πŸ“„ Upload Documents

POST /upload-document
Content-Type: multipart/form-data

file: [PDF/DOCX/TXT file]
  • Multi-format Support: PDF, DOCX, TXT files
  • Automatic Processing: Chunking, embedding, and storage
  • Real-time Feedback: Upload progress and status updates

🌐 Web Search

POST /web-search
Content-Type: application/json

{
  "query": "search term"
}
  • Direct Web Search: Search the web for any topic
  • Content Extraction: Parse and extract relevant information
  • Formatted Results: Clean, structured search results

βž• Add Text Manually

POST /add-document-string
Content-Type: application/json

{
  "text": "Your text content here...",
  "document_name": "Optional Name"
}

πŸ“‹ System Status

GET /api/hello
GET /test-ai
GET /api/status
POST /api/reinitialize-openai
  • Health Checks: API and AI system status
  • Testing: Verify AI functionality
  • Status Monitoring: Comprehensive system status
  • Reinitialization: Reinitialize OpenAI client if needed

πŸ—οΈ Architecture

Frontend

  • Modern UI: Responsive design with CSS Grid and Flexbox
  • JavaScript: Vanilla JS with modern ES6+ features
  • Font Awesome: Professional icons throughout
  • Inter Font: Clean, modern typography

Backend

  • FastAPI: High-performance Python web framework
  • Pydantic: Data validation and serialization
  • Async/Await: Non-blocking I/O operations
  • CORS: Cross-origin resource sharing enabled

AI & Search

  • OpenAI GPT-3.5-Turbo: Natural language processing
  • OpenAI Embeddings: Text vectorization (Ada-002)
  • Milvus Vector DB: Scalable vector storage and search
  • Google Search: Web information retrieval

Data Processing

  • PyPDF2: PDF text extraction
  • python-docx: DOCX file processing
  • BeautifulSoup: Web content parsing
  • Chunking Algorithm: Intelligent text segmentation

🎯 Use Cases

πŸ“Š Document Analysis

  • Research Papers: Extract key insights and answer questions
  • Reports: Analyze business reports and generate summaries
  • Manuals: Get quick answers from technical documentation
  • Books: Interactive reading with AI-powered insights

πŸ‘₯ Person Research

  • Professional Profiles: Get information about people
  • Background Checks: Research individuals and their work
  • Networking: Learn about contacts and connections
  • Biographical Data: Historical and current information

πŸ” Information Discovery

  • Web Search: Find current information on any topic
  • Fact Checking: Verify information from multiple sources
  • Research: Gather information for projects and studies
  • Learning: Interactive learning with AI assistance

πŸ› οΈ Configuration

Environment Variables

OPENAI_API_KEY=sk-your-openai-api-key

Milvus Configuration

MILVUS_URI = "https://your-cluster.zillizcloud.com"
MILVUS_TOKEN = "your-milvus-token"
COLLECTION_NAME = "your-collection-name"
DIMENSION = 3270  # OpenAI Ada embedding dimension

Customization Options

  • Chunk Size: Adjust document chunking parameters
  • Search Results: Configure number of web search results
  • AI Model: Switch between different OpenAI models
  • UI Theme: Customize colors and styling

πŸ“± Screenshots

Main Interface

  • Modern chat interface with document upload
  • Real-time status indicators
  • Dark/light mode toggle
  • Responsive design for all devices

Document Processing

  • Drag & drop file upload
  • Progress indicators
  • Success/error feedback
  • Document information display

AI Chat

  • Message history with timestamps
  • Typing indicators
  • Rich text responses
  • Context-aware answers

πŸ”§ Troubleshooting

OpenAI Connection Issues

  1. Test your API key:

    python test_openai.py
  2. Check environment variable:

    echo $OPENAI_API_KEY
  3. Common issues:

    • Invalid API key: Ensure your key starts with sk- and is correct
    • No credits: Check your OpenAI account billing
    • Rate limits: Wait a moment and try again
    • Network issues: Check your internet connection
  4. Reinitialize OpenAI client:

    curl -X POST http://localhost:8000/api/reinitialize-openai

Milvus Connection Issues

  1. Check configuration in main.py
  2. Verify credentials are correct
  3. Ensure collection exists or can be created
  4. Check network connectivity to Zilliz Cloud

General Issues

  • Port conflicts: Change port in main.py if 8000 is busy
  • Dependencies: Ensure all packages are installed correctly
  • File permissions: Check write permissions for uploads

πŸ”§ Development

fastapi-vibe-coding/
β”œβ”€β”€ main.py              # FastAPI application
β”œβ”€β”€ requirements.txt     # Python dependencies
β”œβ”€β”€ static/
β”‚   └── index.html      # Modern web interface
β”œβ”€β”€ myenv/              # Virtual environment
└── README.md          # This file

Key Dependencies

  • FastAPI: Web framework
  • Uvicorn: ASGI server
  • OpenAI: AI model integration
  • PyMilvus: Vector database client
  • BeautifulSoup: Web scraping
  • Font Awesome: Icons

Running in Development

# Enable auto-reload
uvicorn main:app --reload --host 0.0.0.0 --port 8000

# Or use the built-in runner
python main.py

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/amazing-feature
  3. Commit your changes: git commit -m 'Add amazing feature'
  4. Push to the branch: git push origin feature/amazing-feature
  5. Open a Pull Request

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

  • FastAPI for the excellent web framework
  • OpenAI for powerful AI models
  • Milvus for scalable vector storage
  • Font Awesome for beautiful icons
  • Inter Font for modern typography

πŸ“ž Support


Built with ❀️ using FastAPI, OpenAI, and modern web technologies

Star on GitHub Fork on GitHub

About

Building rag model using fast-API

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published