Inspiration

In agriculture, timing is everything. A farmer identifying a potential disease or pest in their field needs accurate information immediately, not hours later after searching through dense university extension guides or waiting for a call back from an expert. Our inspiration came directly from this high-stakes environment. We imagined a tool that could bridge the gap between vast repositories of expert knowledge—often locked away in cumbersome PDFs—and the person in the field needing an instant, trustworthy answer. We wanted to build an "expert in your pocket" that understands the language of agriculture and delivers practical advice when it matters most.

What it does

  1. Ask a Question: A user asks a natural language question in the chat interface, such as "What are the symptoms of soybean rust?" or "My wheat kernels look scabby and pink, what could be the cause and how do I manage it?"

  2. Intelligent Search: The application uses Elasticsearch's powerful hybrid search to query a specialized knowledge base of agricultural research papers and guides. It combines keyword search (to find specific terms like a product name) and semantic vector search (to understand the user's intent).

  3. Al Synthesis: The most relevant information retrieved by Elastic is passed as context to Google's Gemini Pro model via Vertex Al.

  4. Get an Answer: Gemini synthesizes the technical information into a clear, concise, and actionable answer, which is then displayed to the user in the chat. Essentially, Agri-Advisor Al reads hundreds of pages of technical documents in seconds and provides a simple summary to solve a user's problem.

    How we built it

    We built Agri-Advisor Al on a modern, cloud-native stack, fully integrating the required partner technologies.

o Core Logic: We used LangChain as the orchestration framework to structure our Retrieval- Augmented Generation (RAG) pipeline.

o Data Ingestion & Search (Elastic):

  1. We loaded agricultural PDF guides using PyPDFLoader.

  2. The documents were split into manageable chunks.

  3. Using Google's textembedding-gecko model, we created vector embeddings for each chunk.

  4. These chunks and their corresponding vectors were indexed into Elasticsearch on Elastic Cloud.

  5. For retrieval, we configured the ElasticsearchStore retriever to use hybrid search, giving us the combined power of BM25 keyword matching and Approximate Nearest Neighbor (ANN) vector search.

· Generative Al (Google Cloud):

  1. Vertex Al served as our gateway to Google's powerful foundation models.

  2. The Gemini Pro model was used as the "brain" of our application to understand the retrieved context and generate human-like answers.

Application & Deployment:

  1. The frontend was rapidly developed using Streamlit.

  2. We containerized the entire application using Docker.

  3. All secrets and API keys were securely stored using Google Secret Manager.

  4. The application was built via Cloud Build, stored in Artifact Registry, and deployed globally as a serverless web app on Google Cloud Run, which was configured to securely access credentials from Secret Manager at runtime. The entire development, from coding to deployment, was done within the Google Cloud ecosystem using Cloud Shell.

    Challenges we ran into

    Our primary challenge was ensuring the quality and accuracy of the AI's answers. An early prototype using only vector search struggled with very specific agricultural terms (like chemical names or disease codes), sometimes retrieving conceptually similar but factually incorrect information.

We solved this by implementing Elastic's hybrid search. By combining vector search's contextual understanding with keyword search's precision, our retrieval quality improved dramatically. This ensured that when a user mentioned a specific term, the exact document chunk containing that term was prioritized, leading to far more accurate and reliable answers from the Gemini model.

Another challenge was managing credentials securely in a cloud-native way. Instead of relying on local .env files, we adopted Google Cloud's best practices by using Secret Manager and granting the Cloud Run service account IAM permissions to access secrets at runtime. This was a learning curve but resulted in a much more secure and production-ready architecture.

Accomplishments that we're proud of

We are incredibly proud of building a fully-functional, end-to-end RAG application that solves a real-world problem, all within the hackathon's timeframe. Specifically:

o Seamless Partner Integration: We successfully married Elastic's best-in-class search capabilities with Google's state-of-the-art generative Al, demonstrating a "better together" solution.

o Production-Ready Deployment: We didn't just build a local demo. Our application is deployed securely and scalably on Google Cloud Run, using professional-grade practices like containerization and centralized secret management.

o The Power of Hybrid Search: We tangibly proved the value of hybrid search. Seeing the quality of the answers jump after implementing it was a major "aha!" moment and validated our choice of Elastic for this challenge.

What we learned

This project was a deep dive into the practicalities of building modern AI applications. We learned that the power of a large language model like Gemini is magnified exponentially when it's grounded with accurate, domain-specific data. Furthermore, we learned that the quality of that grounding data depends entirely on the sophistication of the retrieval system. Elastic's hybrid search is not just a feature; it's a critical component for building trustworthy and effective RAG systems. On the deployment side, we learned how incredibly fast and powerful Google Cloud's serverless ecosystem is for going from code to a globally available application.

What's next for Agri-Advisor AI

The future for Agri-Advisor Al is incredibly exciting. Our roadmap includes:

o Multi-modal Input: Integrating Gemini Pro Vision to allow users to upload a photo of a plant leaf and ask, "What disease is this and how do I treat it?"

. Expanding the Knowledge Base: Ingesting a wider array of data sources, including real-time weather data, soil reports, and dynamic pricing information for agricultural products.

o Agentic Capabilities: Evolving from a Q&A bot to an Al agent that can recommend a full treatment schedule, check product availability with distributors via an API, and even create a calendar reminder for the farmer to re-scout their field.

o Proactive Alerts: Integrating with weather APIs to proactively warn farmers about upcoming conditions that are favorable for diseases they've previously inquired about, turning the tool from a reactive to a proactive advisor.

Built With

  • elastic
  • elasticsearch
  • gemini-pro
  • google-artifact-registry
  • google-cloud
  • google-cloud-build
  • google-cloud-run
  • google-cloud-shell
  • google-secret-manager
  • google-vertex-ai
  • langchain
  • python
  • streamlit
Share this project:

Updates