Skip to content

gitnoob101/finservAPI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

28 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

FinserveAPI

FinServe API: Intelligent Document Q&A FinServe API is a high-performance, intelligent Question-Answering system designed to understand and respond to complex queries about documents. Built with a sophisticated Retrieval-Augmented Generation (RAG) pipeline, it can process PDFs, DOCX files, and emails, making it a versatile tool for extracting precise information from unstructured data. Conceived and developed by Akash Gupta and Shubham Verma as a collaborative effort for a hackathon, FinServe API embodies innovation, teamwork, and a passion for solving real-world challenges.

This project was developed for a hackathon to showcase an advanced, production-ready RAG architecture deployed on a scalable, serverless platform.

✨ Features This is not a simple RAG pipeline. It incorporates several advanced techniques to ensure high accuracy and performance:

πŸ“„ Multi-Format Document Support: Ingests and processes PDF, DOCX, and EML files, automatically detecting the file type.

πŸ“Š Advanced Text Extraction: Utilizes pdfplumber to accurately extract not just text but also tables from PDFs, converting them to Markdown for the AI to better understand structured data.

🧠 Smart Chunking: Employs nltk for sentence-aware chunking, which preserves the semantic integrity of the text better than simple fixed-size chunks.

πŸš€ Two-Stage Retrieval with Reranking:

Fast Retrieval: A highly efficient FAISS index retrieves an initial set of relevant document chunks.

Precision Reranking: A sophisticated CrossEncoder model then reranks these initial chunks to find the most contextually relevant passages, significantly boosting answer accuracy.

⚑ Caching Mechanism: Features a robust caching system that saves the processed embeddings and indexes of a document. Subsequent requests for the same document are served almost instantly.

βš™οΈ Parallel Processing: Uses a ThreadPoolExecutor to answer multiple questions in a single API call concurrently, dramatically reducing the total response time.

πŸ› οΈ Technology Stack Backend Framework: FastAPI

LLM: OpenAI GPT-4o Mini

Embedding Model: BAAI/bge-small-en-v1.5

Reranker Model: cross-encoder/ms-marco-MiniLM-L-6-v2

Vector Database: FAISS (Facebook AI Similarity Search)

PDF Parsing: pdfplumber

Deployment: Google Cloud Run with GPU support

Containerization: Docker

API Endpoint The API provides a single endpoint for processing documents and answering questions.

URL: [Your-Deployed-URL]/api/v1/hackrx/run

Method: POST

Authentication: Authorization: Bearer [Your-Security-Token]

Sample Request Body { "documents": "https://hackrx.blob.core.windows.net/assets/policy.pdf", "questions": [ "What is the maximum limit for Domiciliary Hospitalisation under Plan A?", "For Plan B, what is the daily Hospital Cash allowance and for how many days is it provided?" ] }

Sample Response Body { "answers": [ "The limit for Domiciliary Hospitalisation under Plan A is up to INR 1,00,000.", "Under Plan B, the daily Hospital Cash allowance is INR 1,000, for a maximum of 5 days." ] }

πŸš€ Setup and Usage Local Development Prerequisites:

Python 3.9+

Git

Clone the Repository:

git clone https://github.com/YourUsername/FinserveAPI.git cd FinserveAPI

Create a Virtual Environment:

python -m venv .venv source .venv/bin/activate # On Windows: .venv\Scripts\activate

Install Dependencies:

pip install -r requirements.txt

Set Up Environment Variables: Create a file named .env in the root directory and add your OpenAI API key:

OPENAI_API_KEY="sk-..." SECURITY_TOKEN="your-secret-token"

Run the Server:

uvicorn main:app --reload

The API will be available at http://localhost:8000.

Deployment on Google Cloud Run This application is configured for a GPU-enabled deployment on Google Cloud Run.

Prerequisites:

A Google Cloud account with billing enabled.

The gcloud CLI installed and authenticated (gcloud init).

One-Time Deployment Command: Due to a Beta feature requirement for GPUs, the service must be created once from the command line. Run the following command from your project's root directory:

gcloud run deploy finserveapi
--source .
--region us-central1
--allow-unauthenticated
--set-env-vars="OPENAI_API_KEY=your-key,SECURITY_TOKEN=your-token"
--cpu=4
--memory=4Gi
--gpu=type=l4
--min-instances=1
--max-instances=3
--timeout=3600
--cpu-boost
--launch-stage=BETA

Continuous Deployment (Optional): After the initial deployment, you can go to the Cloud Run service in the Google Cloud Console and click "Set up continuous deployment" to link your GitHub repository for automated deployments on every git push.

πŸ“‚ Project Structure . β”œβ”€β”€ .env # Stores secret keys for local development β”œβ”€β”€ .gitignore # Specifies files for Git to ignore β”œβ”€β”€ Dockerfile # Instructions for building the deployment container β”œβ”€β”€ main.py # FastAPI application, API endpoint logic β”œβ”€β”€ rag_pipeline.py # Core RAG logic, including chunking, embedding, and answering └── requirements.txt # List of Python dependencies

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors