This project implements a Retrieval-Augmented Generation (RAG) service using FastAPI and Python. It processes PDF files containing medical codes and names, stores them in a vector database, and provides an API for querying the data.
- Extracts medical codes and names from PDF files in the
docs/directory. - Uses SentenceTransformers for embedding generation.
- Stores embeddings in a FAISS vector database in the
rag/directory. - Provides a FastAPI endpoint for querying the data.
- Includes API key authentication for secure access.
main.py: Entry point for the FastAPI application.routers/: Contains API route definitions.controllers/: Handles business logic for API endpoints.services/: Contains the RAG service implementation.middlewares/: Includes middleware for API key authentication.utils/: Utility functions for initialization and setup.
API_KEY: The API key for authenticating requests. Add this to a.envfile in the root directory.
-
Clone the repository:
git clone <repository-url> cd sample-rag
-
Install dependencies:
pip install -r requirements.txt
-
Create the required directories:
mkdir docs rag
-
Add a
.envfile with the following content:API_KEY=your_api_key_here
-
Add PDF files to the
docs/directory. -
Run the application:
uvicorn main:app --reload
GET /query: Query the RAG service with a question.- Headers:
X-API-Key: <your_api_key> - Query Parameters:
question=<your_question>
- Headers:
- The
rag/directory stores the FAISS index and is ignored by version control. - Ensure the
docs/directory contains valid PDF files for processing.