Inspiration

Smallholder farmers across Nigeria face critical, time-sensitive threats from crop diseases, soil degradation, and sudden pest infestations. When a crisis strikes in the field, a farmer cannot afford to lose hours scrolling through dense, multi-page agricultural manuals or government PDFs to find a single, actionable remedy. This information bottleneck is heavily worsened by the reality of the ground infrastructure many rural farming communities suffer from completely unstable grid power, zero cellular connectivity, and high mobile data costs.

We were inspired to totally eliminate this documentation lookup delay and bridge the gap. We wanted to turn everyday, offline hardware into an independent, deterministic shield for crop protection. That is why we built YieldGuard a tool designed to turn static farming corpuses into an instant, conversational, fully offline oracle that brings the power of AI directly to the field where it's needed most.

What it does

YieldGuard is a localized, fast Retrieval Augmented Generation (RAG) assistant that reads local agricultural data and generates specific, direct answers to farming queries in real time, completely offline.

To deploy it, an extension officer or cooperative manager simply drops unstructured text guidelines, reference materials, or crop handbooks into a single, structured corpus.json file inside the application's data directory. YieldGuard's local AI subsystem handles data loading, real time semantic retrieval, and contextual parsing entirely on-device. Users can scale and drop as many documents into the JSON source file as they need, giving the local AI a massive, highly specific context pool to safely answer localized queries about crops, livestock, weather, and market logistics without ever touching the public internet or requiring an expensive platform subscription.

How we built it

We engineered YieldGuard from the ground up to work efficiently on a resource constrained hardware profile, benchmarking specifically against a standard Intel Core i5 mobile CPU with 8GB of RAM.

  • Model Exploration & Selection: Because agriculture is highly knowledge retrievable rather than reasoning-heavy, we knew a compact model fortified with a high fidelity local RAG pipeline could systematically beat a massive cloud model. We thoroughly benchmarked multiple parameter sizes and quantization scales. While our 4-bit quantization benchmarks yielded a 48% throughput rating at 77.78% efficiency, moving to Qwen-2.5-1.5B-Instruct using 5-bit precision quantization unlocked our sweet spot, an optimal 54% throughput at 80% efficiency.
  • High-Speed RAG Index: To maximize our efficiency score and protect the 8GB RAM constraints, we bypassed heavy external vector databases entirely. Instead, we engineered a flat vector index using raw NumPy matrix dot products, opening the file in memory-mapped mode. This completely bypassed Python's heap allocation space, locking our steady-state memory footprint at just 1,371 Megabytes.
  • Backend & Inference Gateway: Built using an asynchronous Python FastAPI web framework. The backend offloads the blocking engine inference directly to an optimized asyncio execution pool, running a native async streamer that shunts token chunks straight to the network buffer with zero multi-threading friction. We also eliminated runtime micro-allocations by using clean string slice notations in our context builder loop.
  • Ultra-Lightweight Frontend: We wrapped the core in a clean, minimalist frontend built entirely on HTML, CSS, and JavaScript. By deliberately avoiding bulky modern web frameworks, we preserved critical system memory while keeping the interface as fast as possible. It features a custom character-by-character streaming engine to eliminate DOM-thrashing layout lags.
  • Performance Benchmarks: Our system successfully achieves a sustainable generation throughput of 8.1 tokens per second with a first-token latency of 21.4 seconds running on an unaccelerated mobile CPU.

Challenges we ran into

One of our biggest engineering challenges was system prompt alignment for a lightweight 1.5B model. Small language models operating on resource constrained devices have a much lower cognitive capacity compared to massive cloud endpoints. Initially, our model repeatedly deviated from formatting constraints provided in the system instruction, often skipping layout boundaries or outputting raw text blobs instead of neat, numbered summaries.

We overcame this bottleneck by applying strict prompt-engineering principles and decoupling the structural markdown logic from the AI engine itself. We wrote a smart, highly reactive state-machine parser in our frontend JavaScript code to natively capture plain numbers and reconstruct the UI layout styles dynamically on the fly. This ensures the output always forces a clean, deterministic, few-shot guarded response structure.

Accomplishments that we're proud of

  • Zero-Dependency 7.5GB Optimization: We successfully squeezed a full RAG stack—including vector embeddings, file-mapped matrices, and local LLM execution blocks—to run flawlessly inside a strict hardware sandbox constraint without causing out-of-memory crashes.
  • Bypassing the Heap: Keeping our steady-state memory footprint locked at 1,371 MB on a standard 8GB RAM laptop proves that local AI doesn't require high-end gaming laptops or server grade GPUs to be useful.
  • Instant Token Streaming: We eliminated long line buffering latency. Farmers and extension officers see answers generating word by word instantly on screen, instead of waiting for complete lines or paragraphs to finish processing in the background.
  • Pure Offline Sovereignty: YieldGuard does not rely on open internet, cellular signals, or expensive API keys. It delivers identical, fast response matrix capabilities whether it is booted up in a high tech lab or in a remote, zero-connectivity rural farm field.

What we learned

  • CPU Core Synchronization Strategy: We observed that when running quantized math matrices on constrained laptop CPUs, hyper-threading often inflicts a massive performance penalty due to core switching. Clamping internal processes directly to raw, physical CPU threads yields remarkably stable and predictable throughput.
  • The Power of Vanilla Stack: We learned that modern web frameworks often bloat memory footprints unnecessarily. Dropping back to vanilla HTML, CSS, and JS isn't just retro; it's a vital optimization tool when every megabyte of RAM counts toward local model inference.

What's next for YieldGuard

  • Audio Voice Interfacing: We aim to implement localized text-to-speech and speech-to-text models to allow farmers who cannot read or write to naturally converse with the system using local spoken dialects.
  • Computer Vision Plant Diagnostics: We want to extend the RAG backend system to parse smartphone images of diseased crop leaves, matching visual anomaly patterns against cached offline vector databases for instant diagnosis.

Built With

Share this project:

Updates

Submission history