Spaces:
Sleeping
Sleeping
File size: 2,282 Bytes
305ef4d | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | Dynamic RAG Engine π
A full-stack, ephemeral Retrieval-Augmented Generation (RAG) API built with FastAPI, LangChain, and Google's Gemini 1.5 Flash.
This application allows users to upload PDF documents dynamically, vectorizes the text in real-time using local Hugging Face embeddings, and serves a chat interface to query the document using an LLM.
ποΈ Architecture
Backend Framework: FastAPI (Asynchronous, High-Performance)
Orchestration: LangChain
Embedding Model: all-MiniLM-L6-v2 (via Hugging Face)
Vector Database: ChromaDB (Ephemeral / In-Memory for session security)
LLM: Google Gemini 1.5 Flash
Frontend: Vanilla HTML/JS with Tailwind CSS (Served via FastAPI)
β¨ Features
Zero-Footprint DB: Uses an in-memory ChromaDB instance that wipes clean after the session, ensuring data privacy and saving server storage.
Modular Pipeline: Document loading, text splitting, embedding, and chain building are separated into clean, maintainable micro-modules (src/).
Custom Logging: Built-in rotating file loggers and middleware for precise API request tracing.
Integrated UI: A modern, single-page application built directly into the root API endpoint.
π Quick Start (Local Deployment)
1. Clone the repository
git clone [https://github.com/yourusername/dynamic-rag-fastapi.git](https://github.com/yourusername/dynamic-rag-fastapi.git)
cd dynamic-rag-fastapi
2. Install dependencies
It is recommended to use a virtual environment.
pip install -r requirements.txt
3. Set your Environment Variables
Create a .env file in the root directory or export the variable in your terminal:
export GOOGLE_API_KEY="your_gemini_api_key_here"
4. Run the Server
Note for Windows users: Avoid using --reload to prevent Uvicorn threading clashes with local PyTorch installations.
uvicorn app:app
5. Access the App
Web UI: http://127.0.0.1:8000/
Interactive API Docs (Swagger): http://127.0.0.1:8000/docs
π‘ API Endpoints
GET /: Serves the frontend web interface.
POST /upload: Accepts a multipart/form-data PDF, chunks the text, creates embeddings, and initializes the RAG chain.
POST /chat: Accepts a JSON payload {"message": "string"} and returns the LLM's context-aware response. |