An LLM-Powered Intelligent Query-Retrieval System for processing large documents and making contextual decisions. Built for the Bajaj Finserv national-level hackathon.
- Document Processing: Handles PDF, DOCX, and email documents
- Semantic Search: Uses Pinecone vector database for efficient clause retrieval
- LLM Integration: Powered by Google Gemini for intelligent answer generation
- RESTful API: FastAPI-based with comprehensive documentation
- Authentication: Secure Bearer token authentication
- Explainability: Provides clear decision rationale and clause traceability
The system follows a six-step workflow:
- Input Documents: Receives PDF blob URLs and natural language queries
- Document Processing: Downloads and parses PDF content
- Embedding Search: Chunks documents and generates embeddings
- Clause Matching: Performs semantic search to find relevant clauses
- Logic Evaluation: Uses Gemini LLM to generate contextual answers
- JSON Output: Returns structured responses with answers
- Python 3.8+
- Google Gemini API key
- Pinecone API key
- Internet connection for API calls
-
Clone the repository:
git clone <repository-url> cd PolicyQuery-AI
-
Install dependencies:
pip install -r requirements.txt
-
Set up environment variables:
# Copy the example environment file cp env_example.txt .env # Edit .env with your API keys GEMINI_API_KEY=your_gemini_api_key_here PINECONE_API_KEY=your_pinecone_api_key_here PINECONE_ENVIRONMENT=gcp-starter
python main.pyuvicorn main:app --host 0.0.0.0 --port 8000The application will be available at http://localhost:8000
http://localhost:8000/api/v1
All requests require Bearer token authentication:
Authorization: Bearer 3ac5ba63774c0a827bb0436425359a4bc2519da9f4da61af84b5685a1237d4bc
Process document queries and return answers.
Request Body:
{
"documents": "https://hackrx.blob.core.windows.net/assets/policy.pdf?sv=2023-01-03&st=2025-07-04T09%3A11%3A24Z&se=2027-07-05T09%3A11%3A00Z&sr=b&sp=r&sig=N4a9OU0w0QXO6AOIBiu4bpl7AXvEZogeT%2FjUHN%CE%96%CE%97zQ%3D",
"questions": [
"What is the grace period for premium payment under the National Parivar Mediclaim Plus Policy?",
"Are there any sub-limits on room rent and ICU charges for Plan A?"
]
}Response Body:
{
"answers": [
"A grace period of thirty days is provided for premium payment after the due date to renew or continue the policy without losing continuity benefits.",
"Yes, for Plan A, the daily room rent is capped at 1% of the Sum Insured, and ICU charges are capped at 2% of the Sum Insured. These limits do not apply if the treatment is for a listed procedure in a Preferred Provider Network (PPN)."
]
}Health check endpoint.
Detailed health check endpoint.
| Variable | Description | Default |
|---|---|---|
GEMINI_API_KEY |
Google Gemini API key | Required |
PINECONE_API_KEY |
Pinecone API key | Required |
PINECONE_ENVIRONMENT |
Pinecone environment | gcp-starter |
HOST |
Server host | 0.0.0.0 |
PORT |
Server port | 8000 |
- LLM: Google Gemini Pro
- Embedding Model: all-MiniLM-L6-v2 (384 dimensions)
- Vector Database: Pinecone with cosine similarity
- Chunk Size: 1000 words with 200 word overlap
curl -X POST "http://localhost:8000/api/v1/hackrx/run" \
-H "Authorization: Bearer 3ac5ba63774c0a827bb0436425359a4bc2519da9f4da61af84b5685a1237d4bc" \
-H "Content-Type: application/json" \
-d '{
"documents": "https://hackrx.blob.core.windows.net/assets/policy.pdf?sv=2023-01-03&st=2025-07-04T09%3A11%3A24Z&se=2027-07-05T09%3A11%3A00Z&sr=b&sp=r&sig=N4a9OU0w0QXO6AOIBiu4bpl7AXvEZogeT%2FjUHN%CE%96%CE%97zQ%3D",
"questions": [
"What is the grace period for premium payment under the National Parivar Mediclaim Plus Policy?",
"Are there any sub-limits on room rent and ICU charges for Plan A?"
]
}'import requests
import json
url = "http://localhost:8000/api/v1/hackrx/run"
headers = {
"Authorization": "Bearer 3ac5ba63774c0a827bb0436425359a4bc2519da9f4da61af84b5685a1237d4bc",
"Content-Type": "application/json"
}
data = {
"documents": "https://hackrx.blob.core.windows.net/assets/policy.pdf?sv=2023-01-03&st=2025-07-04T09%3A11%3A24Z&se=2027-07-05T09%3A11%3A00Z&sr=b&sp=r&sig=N4a9OU0w0QXO6AOIBiu4bpl7AXvEZogeT%2FjUHN%CE%96%CE%97zQ%3D",
"questions": [
"What is the grace period for premium payment under the National Parivar Mediclaim Plus Policy?",
"Are there any sub-limits on room rent and ICU charges for Plan A?"
]
}
response = requests.post(url, headers=headers, json=data)
print(json.dumps(response.json(), indent=2))The system is optimized for:
- Token Efficiency: Smart chunking and embedding strategies
- Low Latency: Efficient vector search and caching
- Scalability: Modular architecture for easy scaling
- Explainability: Clear decision rationale and clause traceability
- Bearer token authentication
- Input validation and sanitization
- Error handling without information leakage
- Secure API key management
- API Key Errors: Ensure your Gemini and Pinecone API keys are correctly set in the
.envfile - PDF Processing Errors: Check if the PDF URL is accessible and the file is not corrupted
- Memory Issues: For large documents, consider reducing chunk size
- Network Issues: Ensure stable internet connection for API calls
The application provides detailed logging for debugging:
- PDF processing status
- Embedding generation progress
- Search query results
- LLM response generation
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
This project is developed for the Bajaj Finserv hackathon.
For support and questions:
- Check the API documentation at
http://localhost:8000/docs - Review the troubleshooting section
- Open an issue in the repository
Built with β€οΈ for PolicyQuery AI