Project Kisan
AI-Powered Agricultural Assistant
Project Domain
AI Research & NLP
Execution Stage
Open Source · Research Demo
Timeline / Year
2026
Repository & Code
GitHub Repository →Visual Documentation & Artifacts
Click any photo to enlargeEngineering with real-world constraints.
Project Kisan is an open-source intelligent agricultural assistant built around a hybrid inference architecture. In agricultural decision-making, standard language models frequently hallucinate facts, invent pesticide dosages, or state outdated guidance with unjustified confidence. Rather than relying blindly on unconstrained parametric memory, Project Kisan was designed with multi-layered safeguards to minimize hallucination and avoid incorrect information.
The system dynamically decides — via an LLM-based routing agent — whether a query can be answered directly, requires retrieval from a curated internal knowledge base, or demands a live web search to verify time-sensitive or external facts. This ensures the model is grounded in relevant evidence rather than forced to guess.
The inference architecture supports dual foundation models: a fine-tuned Meta Llama 3.2 3B Instruct model for fast, low-latency, and domain-adapted responses, and an optional Meta Llama 3.1 8B Instruct model for situations requiring deeper general reasoning, multi-step explanations, and comprehensive advisory generation.
For domain adaptation, Llama 3.2 3B was fine-tuned with QLoRA (4-bit NF4, LoRA r=16 α=32) on the kisanVaani/agriculture-qa-english-only dataset using SFTTrainer with a 90/10 train/validation split. Fine-tuning ran to checkpoint-3500 with early stopping and was evaluated against domain validation loss.
The retrieval pipeline acts as an active hallucination defense: FAISS vector search retrieves an initial candidate pool of 20 documents using Qwen3-Embedding-0.6B, which a BGE CrossEncoder (BAAI/bge-reranker-v2-m3) reranks down to the top 5 with a strict 0.5 minimum score threshold. Noisy, irrelevant passages that often trigger model hallucination are filtered out before reaching the prompt. For timely queries, DDGS discovers 15 live web results across diverse domains, cleaned via BeautifulSoup, and reranked to top 10 passages with domain diversity caps.
The routing agent outputs a structured JSON tool-call deciding between `direct`, `rag_search`, and `web_search_tool`. When retrieved context is insufficient, the model is instructed to acknowledge uncertainty rather than fabricate unsupported answers. Responses stream token-by-token with transparent source attribution over a FastAPI Server-Sent Events endpoint.
The Danger of Hallucinations and Incorrect Information in Agriculture
In agriculture, incorrect advice carries severe real-world consequences: misdiagnosing a crop pathogen, prescribing incorrect chemical concentrations, or recommending outdated practices can decimate seasonal yields. Unconstrained LLMs frequently hallucinate precise-sounding numbers, dates, and chemicals with false certainty.
Project Kisan was engineered specifically to address this vulnerability. Rather than claiming infallible accuracy, the system incorporates architectural guardrails at every layer: two-stage neural reranking to eliminate misleading context, live web search for verified external facts, strict anti-hallucination prompting that penalizes fabricated dosages, and uncertainty acknowledgment when data is missing.
Component Deep Dives
USER QUERY
│
▼
┌─────────────────────────────┐
│ LLM ROUTER AGENT │
│ (Llama JSON Tool-Call) │
│ direct / rag / web_search │
└──────┬──────────┬───────────┘
│ │ │
direct rag_search web_search_tool
│ │ │
│ ┌─────┴──┐ ┌────┴─────┐
│ │ FAISS │ │ DDGS │
│ │ k=20 │ │ 15 URLs │
│ └────┬────┘ └────┬─────┘
│ │ │
│ BGE CrossEncoder BGE CrossEncoder
│ (top 5 chunks) (top 10 passages)
│ │ │
└────┬────┴──────────────┘
│ CONTEXT BLOCK
▼
┌───────────────────────────────────────┐
│ DUAL MODEL GENERATION │
│ • Fine-tuned Llama 3.2 3B (QLoRA) │
│ [Fast, specialized, checkpoint-3500]│
│ • Meta Llama 3.1 8B Instruct │
│ [Deep multi-step reasoning & depth] │
└───────────────────┬───────────────────┘
│ SSE Token Stream
▼
FastAPI Backend
│
▼
Gradio FrontendDual Foundation Models — Fine-Tuned 3B vs. Configurable 8B
Project Kisan implements a configurable foundation model architecture supporting both Meta Llama 3.2 3B Instruct and Meta Llama 3.1 8B Instruct. This design gives users and deployment environments the flexibility to balance computational efficiency against response depth.
The fine-tuned 3B model (loaded from checkpoint-3500) delivers high-speed, domain-specialized responses with minimal GPU memory footprint, making it ideal for edge deployment, rapid chat turns, and high-throughput advisory environments.
The 8B model (Meta Llama 3.1 8B Instruct) serves as an alternative high-capacity reasoning engine. It provides superior multi-step logical deduction, nuanced agronomic problem solving, and richer contextual synthesis when handling complex multi-factor queries such as disease interaction with climate conditions.
Explore Full Codebase on GitHub
Includes complete source code, installation instructions, launch files, and documentation.
Quantitative Metrics
3B Fine-Tuned + 8B
Foundation Models
Llama 3.2 3B (domain adapted) & Llama 3.1 8B (deep reasoning)
r=16 / α=32
LoRA Config
4-bit NF4 quantisation, double quantisation, BF16 compute
Step 3500
Fine-Tune Checkpoint
90 / 10 split on KisanVaani dataset with early stopping
top k=20
FAISS Recall
Narrowed to top 5 by BGE CrossEncoder reranker (>=0.5 score)
15 results
Web Search
5 diverse sites scraped → BGE reranked → top 10 passages
3 paths
Routing Paths
direct / rag_search / web_search_tool via JSON tool-call
Phased Architecture
Data Preparation
kisanVaani agricultural QA dataset loaded and converted into conversational instruction templates. 90/10 train/validation split applied with fixed seed 42. PDF documents chunked and indexed in FAISS with Qwen3-Embedding-0.6B.
QLoRA Fine-Tuning
Llama 3.2 3B Instruct quantised to 4-bit NF4 with double quantisation and BF16 computation. LoRA adapters (r=16, α=32) trained on attention projections via SFTTrainer with gradient checkpointing, selecting checkpoint-3500 via early stopping.
Dual-Model Inference Setup
Integrated both the fine-tuned Llama 3.2 3B model for fast domain-specific answering and Meta Llama 3.1 8B Instruct for enhanced general reasoning, configurable based on query complexity.
RAG & Web Retrieval Modules
FAISS vector store and BGE CrossEncoder (bge-reranker-v2-m3) assembled for two-stage document retrieval. DDGS web search with BeautifulSoup parsing and domain diversity caps implemented.
Router Agent & Backend
LLM routing agent built to classify queries into direct, rag_search, or web_search_tool via JSON tool-calls. FastAPI SSE streaming backend assembled with asynchronous event queues and source attribution.
Frontend & Deployment
Gradio frontend built for multi-turn conversation, source citation display, and routing-path inspection. Hosted in a GPU environment with ngrok secure tunnels and Kaggle Secrets credential management.
Key Capabilities
Dual-Model Architecture (3B & 8B)
Configurable inference pipeline supporting both a fast, QLoRA-fine-tuned Llama 3.2 3B for specialized responses, and Meta Llama 3.1 8B Instruct for tasks requiring deeper multi-step reasoning and detailed explanations.
LLM Routing Agent
A dedicated LLM call classifies each query and dispatches it — direct answer, RAG retrieval, or live web search — based on structured JSON tool-call output, avoiding brittle keyword heuristics.
QLoRA Domain Fine-Tuning
Llama 3.2 3B Instruct fine-tuned with 4-bit NF4 QLoRA (r=16, α=32) on the KisanVaani agricultural corpus using SFTTrainer, converging at checkpoint-3500 with a 90/10 data split.
Two-Stage RAG Retrieval
FAISS retrieves the top 20 candidate chunks using Qwen3-Embedding-0.6B, which a BGE CrossEncoder reranker then narrows to the top 5 for precision — maximising recall then filtering for relevance.
Live Web Search Integration
DDGS fetches 15 live results; up to 5 pages are scraped and cleaned via BeautifulSoup; BGE reranking selects the top 10 passages with domain diversity caps.
SSE Token Streaming & API
FastAPI streams Llama tokens over Server-Sent Events via TextIteratorStreamer and asyncio.Queue, delivering a responsive chat experience with real-time source attribution.
Hallucination Defense & Guardrails
Rather than assuming generative infallibility, the architecture incorporates multi-layered guardrails: neural CrossEncoder relevance filtering (threshold >= 0.5), uncertainty acknowledgment prompts, domain diversity caps, and explicit constraints against fabricating dosages.
- [01]Llama 3.2 3B Instruct
- [02]Llama 3.1 8B Instruct
- [03]LoRA / PEFT
- [04]QLoRA (4-bit NF4)
- [05]FAISS
- [06]BGE CrossEncoder
- [07]RAG
- [08]FastAPI
- [09]Gradio
- [10]Qwen3-Embedding-0.6B
- [11]DDGS Web Search
Other Selected Works
Autonomous Drone
A ROS2 autonomous-navigation stack for a DJI Tello: monocular ORB-SLAM3 for real-time visual SLAM with a custom depth-estimation and scale-recovery pipeline, plus occupancy mapping and exploration planning layers in active development.
Learn more →Deep Learning & Medical ImagingConditional Multimodal MRI Synthesis & Brain Tumor Segmentation
A two-model system combining a ResNet U-Net for multi-class brain tumor segmentation with a conditional diffusion model that synthesizes 4-modality MRI scans from masks. Led as a two-person project and trained on TPU.
Learn more →Computer Vision & Edge AIGesture-Controlled Drone
A real-time gesture-recognition pipeline controlling a DJI Tello in flight. Built on a self-collected dataset of 5,000+ hand-landmark samples, a feature-engineered classifier, and temporal smoothing for reliable control.
Learn more →