Skip to content

Rahul9672/AgroRAG

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🌱 CAFRI Agroforestry Knowledge Assistant

An AI-powered Retrieval-Augmented Generation (RAG) system that answers agroforestry-related questions directly from ICAR-CAFRI research documents.

Instead of searching through hundreds of pages of annual reports, advisories, and management guidelines, the assistant retrieves the most relevant information and generates grounded answers with source citations.


🚀 Features

  • 📄 PDF document ingestion
  • 🧹 Automatic text cleaning
  • ✂️ Smart document chunking
  • 🧠 Semantic embeddings using Sentence Transformers
  • 💾 Local vector database with ChromaDB
  • 🔍 Semantic similarity search (Top-K retrieval)
  • 🤖 Answer generation using Google Gemini 2.5 Flash
  • 📚 Source-aware responses
  • 🌐 English / Hinglish support
  • ⚡ Streamlit web interface

🏗️ System Architecture

                    CAFRI Research PDFs
                           │
                           ▼
                     PDF Loader
                           │
                           ▼
                     Text Cleaning
                           │
                           ▼
                    Smart Chunking
                           │
                           ▼
              sentence-transformers
                 (Embedding Model)
                           │
                           ▼
                     ChromaDB
                 (Vector Database)
                           │
                           ▼
              Top-K Similar Chunks
                           │
                           ▼
                 Prompt Engineering
                           │
                           ▼
                Gemini 2.5 Flash API
                           │
                           ▼
          Grounded Answer + Citations

🔄 Complete Workflow

Phase 1 — Document Indexing (One-time)

Research PDFs
      │
      ▼
Load PDFs
      │
      ▼
Extract Text
      │
      ▼
Clean Text
      │
      ▼
Split into Smart Chunks
      │
      ▼
Generate Embeddings
      │
      ▼
Store in ChromaDB

During this phase, all CAFRI research documents are converted into vector embeddings and indexed inside a local ChromaDB database.


Phase 2 — Question Answering

User Question
      │
      ▼
Generate Question Embedding
      │
      ▼
Semantic Similarity Search
      │
      ▼
Retrieve Top-K Relevant Chunks
      │
      ▼
Prompt Construction
      │
      ▼
Gemini 2.5 Flash
      │
      ▼
Answer + Source Citations

Instead of relying on the model's general knowledge, the assistant first retrieves the most relevant document sections and then asks Gemini to answer only using that retrieved context, reducing hallucinations and improving factual accuracy.


📂 Project Structure

cafri-rag-assistant/

│── app.py                  # Streamlit application
│── ingest.py               # Build vector database
│── requirements.txt
│── README.md
│── .env.example

│
├── data/
│     └── pdfs/
│
├── chroma_db/
│
├── ingestion/
│     ├── pdf_loader.py
│     ├── cleaner.py
│     ├── chunker.py
│     └── embedder.py
│
├── rag/
│     ├── retriever.py
│     ├── prompt.py
│     └── generator.py
│
└── utils/
      └── config.py

⚙️ Installation

Clone the repository

git clone https://github.com/yourusername/cafri-rag-assistant.git

cd cafri-rag-assistant

Create a virtual environment

python -m venv .venv

Activate it

macOS / Linux

source .venv/bin/activate

Windows

.venv\Scripts\activate

Install dependencies

pip install -r requirements.txt

🔑 Configure Gemini API

Create a .env file in the project root.

GOOGLE_API_KEY=your_google_gemini_api_key

Example:

GOOGLE_API_KEY=AIzaSy********************

The application uses Google Gemini 2.5 Flash for answer generation.


▶️ Usage

Step 1

Place CAFRI PDFs inside

data/pdfs/

Examples

  • Annual Reports
  • Agroforestry Advisories
  • Establishment & Management Guidelines
  • Package of Practices

Step 2

Create the vector database

python ingest.py

This performs

  • PDF Loading
  • Text Cleaning
  • Chunking
  • Embedding Generation
  • ChromaDB Index Creation

Step 3

Run the application

streamlit run app.py

Step 4

Ask questions such as

What establishment practices are recommended?

What tree spacing is recommended for Poplar?

How should tree basins be managed?

Which agroforestry models are suitable for semi-arid regions?

🛠️ Technology Stack

Component Technology
Programming Language Python
UI Streamlit
PDF Processing pdfplumber / PyPDF
Text Chunking LangChain Text Splitter
Embeddings sentence-transformers (all-MiniLM-L6-v2)
Vector Database ChromaDB
Retrieval Semantic Similarity Search
LLM Google Gemini 2.5 Flash
Environment Variables python-dotenv

📈 Current Capabilities

  • ✅ PDF ingestion
  • ✅ Semantic search
  • ✅ Local vector database
  • ✅ Grounded responses
  • ✅ Google Gemini integration
  • ✅ English / Hinglish answers
  • ✅ Source citations

🚧 Roadmap

The project is actively being enhanced with production-oriented features.

  • 🎨 Beautiful Streamlit UI
  • 💬 Chat History
  • 🧠 Conversation Memory
  • 📚 Source PDF + Page Number
  • 📊 Confidence Score
  • 💡 Suggested Follow-up Questions
  • 🌐 Hindi + English + Hinglish Support
  • 🎤 Voice Input
  • 🗺️ GIS / Map Integration
  • 📄 Export Answers as PDF
  • ⚙️ Better Prompt Engineering
  • 📝 Logging & Monitoring
  • ⚙️ Configuration Management
  • 🐳 Docker Support
  • 📖 Architecture Documentation

🎯 Future Vision

This project aims to evolve into an AI-powered knowledge management platform for agricultural research organizations, enabling researchers, extension workers, and farmers to retrieve trusted information from scientific documents instantly.

Potential future integrations include:

  • GIS-based agroforestry recommendations
  • Satellite imagery support
  • Location-aware advisory system
  • Multi-document reasoning
  • Voice-enabled farmer assistant
  • Mobile application

📜 License

This project is intended for educational and research purposes.

CAFRI research documents remain the property of ICAR-CAFRI. Answers generated by this application are derived from the supplied documents and should always be verified against the original publications before making agricultural decisions.

About

Developed an end-to-end RAG application using Python, ChromaDB, sentence-transformers, Streamlit, and Gemini API to answer queries from agricultural research documents with source-backed responses.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages