เฐฎเฑ เฐชเฑเฐฒเฐ เฐฎเฐพ เฐฌเฐพเฐงเฑเฐฏเฐค โ Your Farm. Stays Safe.
FarmAlert is a free, AI-powered agricultural decision-support platform built for smallholder farmers in Telangana, India. It delivers hyper-local climate risk forecasts, satellite-derived crop health analysis, bilingual AI advisories in Telugu and English, and a RAG-powered knowledge base grounded in official government documents โ all in one place.
๐ Live Demo: farmalert.vercel.app
๐ Full Technical Documentation: FarmAlert_Technical_Documentation_v1.pdf
The system has two parallel AI pipelines that both converge at Gemini 2.0 Flash:
- Advisory pipeline โ fetches live satellite + weather data, runs through risk and water engines, generates a bilingual action plan
- RAG knowledge base pipeline โ embeds farmer questions, searches Pinecone vector index, retrieves grounded document chunks, generates verified answers
- 14-day weather forecast via Open-Meteo API (temperature, rainfall, UV, ET0)
- 22-year climate baseline anomaly detection via NASA POWER API
- Real-time satellite indices via NASA MODIS โ NDVI, EVI, LST, LAI (180-day history)
- 6 risk classifications โ Heatwave, Drought, Flooding, Soil Moisture Drop, Wind Damage, Pest Risk
- FAO-56 Penman-Monteith crop water requirements with stage-specific Kc coefficients
- Bilingual daily / weekly / monthly action plans in Telugu + English
- Floating chat widget on every page โ glass pill design mirroring the navbar
- Answers grounded in 4 official government documents (346 vectors, Pinecone)
- Query enrichment with farm context (crop + stage + location) for precision retrieval
- In-memory OrderedDict cache (100 entries, LRU eviction) โ โก instant on repeat questions
- Animated letter-by-letter placeholder text, macOS-style expand animation
- Attach saved farms from My Farms to personalize answers
- Interactive Leaflet map for GPS-based farm location
- Save and manage multiple farms with risk history
- My Farms dashboard with last risk status per farm
| Layer | Technology |
|---|---|
| Frontend | React 18 ยท Vite ยท TailwindCSS ยท Leaflet ยท Framer Motion ยท motion/react |
| Backend | FastAPI ยท Python 3.11 ยท asyncio ยท uvicorn |
| AI โ Advisory | Gemini 2.0 Flash (gemini-2.0-flash) |
| AI โ RAG Generation | Gemini 2.5 Flash (gemini-2.5-flash) |
| Embeddings | gemini-embedding-001 ยท 768 dimensions ยท Matryoshka truncation |
| Vector Database | Pinecone Serverless ยท farmalert-kb ยท cosine similarity ยท AWS us-east-1 |
| Weather API | Open-Meteo (14-day forecast ยท ET0) |
| Climate API | NASA POWER (22-year baseline) |
| Satellite API | NASA MODIS (NDVI ยท EVI ยท LST ยท LAI) |
| Frontend Hosting | Vercel |
| Backend Hosting | Render (free tier ยท 512MB RAM) |
| Document | Source | Pages | Chunks |
|---|---|---|---|
| PM-KISAN Operational Guidelines | pmkisan.gov.in | 12 | 15 |
| Telangana Kharif Agro-Advisory 2025 | icar.org.in | 7 | 12 |
| ICAR Soil & Nutrient Management (NRM-2702) | icar.org.in | 115 | 104 |
| PMFBY Crop Insurance Guidelines | pmfby.gov.in | 144 | 215 |
| Total | 278 | 346 |
| Method | Endpoint | Description |
|---|---|---|
POST |
/api/analyze |
Full farm analysis โ weather + satellite + risk + water + Gemini advisory |
POST |
/api/knowledge-base |
RAG Q&A โ embedding + Pinecone search + grounded Gemini answer |
GET |
/ |
Health check |
{
"lat": 17.9784,
"lng": 79.5941,
"crop_type": "cotton",
"crop_stage": "flowering",
"soil_type": "black",
"location_name": "Warangal, Telangana"
}{
"question": "Am I eligible for PM-KISAN scheme?",
"crop": "cotton",
"stage": "flowering",
"location": "Warangal, Telangana"
}{
"answer": "To be eligible for PM-KISAN...",
"cached": false
}- Python 3.11+
- Node.js 18+
- Pinecone account (free tier)
- Google AI Studio API key(s)
cd backend
python -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
pip install -r requirements.txtCreate backend/.env:
GEMINI_API_KEY=your_gemini_api_key
GEMINI_RAG_API_KEY=your_rag_gemini_api_key
PINECONE_API_KEY=your_pinecone_api_key
PINECONE_HOST=your_pinecone_index_hostpython run.pycd frontend
npm installCreate frontend/.env:
VITE_API_URL=http://localhost:8000npm run devcd backend
# Add PDFs to data/source_docs/
python app/scripts/ingest.py| Decision | Reason |
|---|---|
| No LangChain | RAM constraints on Render free tier (512MB) |
| Raw Pinecone SDK | Lighter footprint, direct control |
| PyMuPDF for PDF extraction | pypdf and pdfplumber had silent text duplication bug on sliced PDFs |
output_dimensionality=768 |
Matryoshka Representation Learning โ officially supported truncation, not lossy |
RETRIEVAL_DOCUMENT vs RETRIEVAL_QUERY |
Different embedding modes for ingestion vs query time โ improves retrieval quality |
| Two separate Gemini API keys | Isolates advisory and RAG quota pools โ prevents one feature from exhausting the other |
| In-memory cache (no Redis) | Zero added dependencies, zero cost, adequate for current scale |
| localStorage for farms | No database yet โ sufficient for MVP, clean migration path to Supabase later |
FARMALERT/
โโโ backend/
โ โโโ app/
โ โ โโโ main.py # FastAPI routes
โ โ โโโ config.py # Settings + env vars
โ โ โโโ models.py # Pydantic models
โ โ โโโ services/
โ โ โ โโโ gemini_service.py # Advisory AI generation
โ โ โ โโโ rag_service.py # RAG pipeline
โ โ โ โโโ risk_engine.py # 6-type risk classification
โ โ โ โโโ water.py # FAO-56 water engine
โ โ โ โโโ weather.py # Open-Meteo integration
โ โ โ โโโ climate.py # NASA POWER integration
โ โ โโโ scripts/
โ โ โโโ ingest.py # RAG document ingestion (local only)
โ โ โโโ verify_pinecone.py # Index verification
โ โโโ data/
โ โ โโโ source_docs/ # PDF knowledge base documents
โ โโโ requirements.txt
โโโ frontend/
โ โโโ src/
โ โโโ pages/
โ โ โโโ AnalysePage.jsx # Main farm analysis
โ โ โโโ MyFarmsPage.jsx # Saved farms
โ โโโ components/
โ โโโ KnowledgeChat.jsx # RAG chat widget
โโโ docs/
โโโ farmalert_complete_system_architecture.png
- Render deployment with all env vars (in progress)
- Frontend RAG chat UI connected to live backend
- Add 10โ15 more knowledge base documents
- Supabase database for cross-device farm sync
- Migrate
gemini_service.pyto newgoogle-genaiSDK - Mobile-responsive UI improvements
- Push notifications for critical risk alerts
- Telugu language input support in RAG chat
Suhas Naragani
- GitHub: @SuhasNaragani
- Project: farmalert.vercel.app
This project is open source and available under the MIT License.
เฐฎเฑ เฐชเฑเฐฒเฐ เฐฎเฐพ เฐฌเฐพเฐงเฑเฐฏเฐค