DocSense AI is an advanced agentic system powered by LlamaIndex and Google Gemini (gemini-2.0-flash). It processes, indexes, and queries complex PDF documents using Retrieval-Augmented Generation (RAG) while persisting session records dynamically via local tool integration.
graph TD
User([User CLI]) -->|Queries| Agent[ReAct Agent]
Agent -->|1. Route Request| Router{Tool Router}
Router -->|If PDF Query| RAG[LlamaIndex Query Engine]
Router -->|If Note Saving| Notes[Note Saver Tool]
RAG -->|Retrieve Context| Storage[(Vector Store Index)]
Storage -.->|Token Chunking| PDF[Sri_Lanka.pdf]
RAG -->|Generate Answer| LLM[Google Gemini 2.0]
Notes -->|Write Notes| File[data/notes.txt]
LLM -->|Answer| Agent
Agent -->|Final Output| User
%% Styles with high contrast dark text for dark-mode safety
style User fill:#e1f5fe,stroke:#01579b,stroke-width:2px,color:#0a2540
style Agent fill:#ede7f6,stroke:#4a148c,stroke-width:2px,color:#0a2540
style Router fill:#fff3e0,stroke:#e65100,stroke-width:2px,color:#0a2540
style RAG fill:#e8f5e9,stroke:#1b5e20,stroke-width:2px,color:#0a2540
style Notes fill:#fbe9e7,stroke:#bf360c,stroke-width:2px,color:#0a2540
style Storage fill:#e8eaf6,stroke:#1a237e,stroke-width:2px,color:#0a2540
style PDF fill:#fce4ec,stroke:#880e4f,stroke-width:2px,color:#0a2540
style LLM fill:#e0f2f1,stroke:#004d40,stroke-width:2px,color:#0a2540
style File fill:#efebe9,stroke:#3e2723,stroke-width:2px,color:#0a2540
- Intelligent ReAct Agent: Autonomously determines whether to consult knowledge bases or execute procedural tools (e.g. saving summaries).
- API Rate-Limit Optimizer: Special token-splitting batch loader with custom delay buffers to respect free-tier API quotas (bypasses Gemini 429 Resource Exhausted errors).
- Persistent Vector Indexing: Caches document vectors locally to guarantee instantaneous search on subsequent runs.
- Knowledge Source: The RAG context is populated from a comprehensive PDF handbook containing geographic, cultural, and political profiles of Sri Lanka.
- Local Notes Persistence: Integrates a
note_saverFunctionTool to record session logs directly intodata/notes.txton command. - Adaptive API Throttling: Embeds nodes using the new
gemini-embedding-2model in 5-node batches, with 3-second intervals and an automatic 60-second recovery timeout block. This prevents API lockouts on Google's free tier (15 requests per minute limit). - Model Configurations:
- LLM:
gemini-2.0-flash(viagoogle-genaiunified SDK) - Embeddings:
gemini-embedding-2
- LLM:
Ensure you have Python 3.10+ installed.
-
Clone the repository:
git clone https://github.com/SihanUdayaratna03/DocSense-AI.git cd DocSense-AI -
Install dependencies:
pip install -r requirements.txt
-
Configure Environment: Create a
.envfile in the root folder:GEMINI_API_KEY=your_gemini_api_key_here
-
Launch Agent:
python main.py