File size: 5,589 Bytes
373e584 8ae0191 373e584 8ae0191 373e584 8ae0191 |
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 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
---
title: Intelligent Document QnA API
emoji: π
colorFrom: blue
colorTo: green
sdk: docker
app_port: 7860
---
# Intelligent Document Q&A API
[](#)
[](#)
[](#)
[](#)
[](#)
[](#)
A high-performance API that allows you to find answers within your documents using powerful language models. Ingest PDFs, DOCX files, or emails, and get back precise answers to your questions.
This project is designed to be simple to set up and use, acting as a robust backend for any application that needs document-based question-answering capabilities.
---
### π What Makes This Project Different?
Unlike many existing RAG APIs, this project is:
- **Model-Agnostic and Multi-Provider Friendly**
Supports both **Google Gemini** and **Gemini AI** out of the box β no hard dependency on OpenAI.
- **Cloud-Ready and Free-Tier Optimized**
Specifically engineered to run smoothly on platforms like **Render**, with memory-efficient caching and lazy model loading.
- **Format-Intelligent**
Automatically detects and uses the correct loader for `.pdf`, `.docx`, and `.eml` files β no manual preprocessing required.
- **Minimal Memory Footprint**
Designed for low-resource environments β ideal for free-tier deployments, research prototypes, or student projects.
- **Clean JSON Output**
Filters out verbose LLM reasoning ("Thought: Let's find the answer...") and returns only the clean, relevant answers.
This makes it ideal for developers, students, and startups looking to build document Q&A apps without the complexity or cost of large RAG systems.
---
## β¨ Features
- **Multi-Format Support**
Natively handles `.pdf`, `.docx`, and `.eml` files.
- **Persistent Storage**
Uses **Supabase** with `pgvector` to store document embeddings. Process a document once and query it instantly anytime after.
- **High-Quality Answers**
Leverages state-of-the-art language models from **Gemini AI** and **Google** for accurate embeddings and intelligent Q&A.
- **Asynchronous & Fast**
Built with **FastAPI** for high-performance, non-blocking I/O.
- **Easy to Deploy**
Ready to be containerized with **Docker** or deployed to any modern cloud platform.
---
## π Getting Started
Follow these steps to get the API server running on your local machine.
### β
Prerequisites
- Python 3.8+
- A Supabase account with a project created
- API keys from Google AI Studio and Gemini AI
---
### π 1. Clone the Repository
```bash
git clone https://github.com/hacketthadwin/intelligent-document-qna-api.git
cd intelligent-document-qna-api
```
---
### ποΈ 2. Set Up Your Supabase Database
Enable the `vector` extension in your Supabase project:
1. Go to your Supabase project dashboard
2. Navigate to the **SQL Editor**
3. Run the following SQL command:
```sql
create extension if not exists vector;
```
A `documents` table will be automatically created the first time a document is processed via LangChain.
---
### π 3. Configure Environment Variables
Create a `.env` file in the root of your project directory. Use this template:
```env
# --- Service Keys ---
GOOGLE_API_KEY="your_google_api_key_here"
# --- Supabase Credentials for Vector Store ---
SUPABASE_URL="https://your_supabase_project_id.supabase.co"
SUPABASE_SERVICE_KEY="your_supabase_service_role_key_here"
```
---
### π¦ 4. Install Dependencies
Install required packages using pip:
```bash
pip install -r requirements.txt
```
---
### βΆοΈ 5. Run the API Server
Start the FastAPI server with:
```bash
python -m uvicorn main:app --reload
```
Visit [http://127.0.0.1:8000](http://127.0.0.1:8000) to access the API.
Interactive docs available at [http://127.0.0.1:8000/docs](http://127.0.0.1:8000/docs)
---
## βοΈ API Usage
### `POST /query`
This endpoint ingests a document (if it's new) and answers questions about it.
---
### π€ Request Body
- `document_url` (string, required): Public URL to the document you want to query
- `questions` (array of strings, required): One or more questions to ask
#### β
Example using `curl`
```bash
curl -X POST "http://127.0.0.1:8000/query" \
-H "Content-Type: application/json" \
-d '{
"document_url": "https://arxiv.org/pdf/1706.03762.pdf",
"questions": [
"What is the title of this paper?",
"Summarize the abstract in one sentence."
]
}'
```
---
### π₯ Example Success Response
```json
{
"answers": [
"The title of the paper is 'Attention Is All You Need'.",
"The abstract introduces the Transformer, a new network architecture based solely on attention mechanisms that is more parallelizable and requires significantly less time to train than existing models."
],
"document_url": "https://arxiv.org/pdf/1706.03762.pdf",
"message": "New document processed and vectors stored in database."
}
```
---
## π€ Contributing
Contributions are welcome! If you have ideas for features or improvements:
- Open an issue to discuss
- Fork the repository
- Create a new branch
- Make your changes
- Submit a pull request
---
## π License
This project is licensed under the MIT License. See the [LICENSE](./LICENSE) file for more details.
|