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.
- 📄 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
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
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.
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.
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
Clone the repository
git clone https://github.com/yourusername/cafri-rag-assistant.git
cd cafri-rag-assistantCreate a virtual environment
python -m venv .venvActivate it
source .venv/bin/activate.venv\Scripts\activateInstall dependencies
pip install -r requirements.txtCreate a .env file in the project root.
GOOGLE_API_KEY=your_google_gemini_api_keyExample:
GOOGLE_API_KEY=AIzaSy********************The application uses Google Gemini 2.5 Flash for answer generation.
Place CAFRI PDFs inside
data/pdfs/
Examples
- Annual Reports
- Agroforestry Advisories
- Establishment & Management Guidelines
- Package of Practices
Create the vector database
python ingest.pyThis performs
- PDF Loading
- Text Cleaning
- Chunking
- Embedding Generation
- ChromaDB Index Creation
Run the application
streamlit run app.pyAsk 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?
| 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 |
- ✅ PDF ingestion
- ✅ Semantic search
- ✅ Local vector database
- ✅ Grounded responses
- ✅ Google Gemini integration
- ✅ English / Hinglish answers
- ✅ Source citations
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
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
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.