AI-Specific Services
Relevant source files
The following files were used as context for generating this wiki page:
The AI-Specific Services are a suite of features that transform VineSight from a reactive record-keeping tool into a proactive, intelligent digital agronomist. These services are designed to provide personalized, predictive, and data-driven insights to grape farmers, helping them optimize operations, increase profitability, and mitigate risks. The implementation is divided into distinct phases, with Phase 2 features already completed and Phase 3 features currently in development.
The core goal of these services is to reduce farmer decision fatigue by providing actionable recommendations, early warnings, and automated analysis. This is achieved by leveraging data from farm history, weather forecasts, soil conditions, and community-wide patterns. The system is built to learn from farmer decisions and outcomes, continuously improving the quality of its advice.
Sources: context/PRD.md:73-195, context/todos.md:3-5
High-Level Architecture
The AI services are built on a multi-provider architecture, utilizing a combination of client-side and cloud-based models to deliver real-time insights.
- AI Providers: The system integrates with multiple AI providers, including OpenAI, Google AI, and Groq, for conversational AI and other language-based tasks.
- Computer Vision: TensorFlow.js is used for client-side computer vision tasks, such as disease detection from images taken on a mobile device.
- Backend: The backend is powered by Supabase and PostgreSQL, which stores all AI-related data, including profiles, recommendations, and predictions.
Sources: AGENTS.md:15-16, context/PRD.md:210-217
Phase 2: Implemented AI Features
Phase 2 established the foundation of smart farming capabilities in VineSight. These features are complete and integrated into the application.
| Feature | Description | Technology |
|---|---|---|
| AI-Powered Disease Detection | Real-time identification of common grape diseases from plant images using the device camera. | TensorFlow.js, Computer Vision |
| AI Chatbot Assistant | A conversational AI assistant providing instant farming guidance in multiple languages (English, Hindi, Marathi). | OpenAI, Natural Language Processing |
| AI Analytics Dashboard | Provides an overall farm health score, yield predictions, and trend analysis based on historical data. | Predictive Analytics |
| Market Intelligence System | Offers ML-based grape price forecasting and recommendations for optimal selling times. | Time Series Forecasting |
| Voice Interface | Enables hands-free operation through speech-to-text and text-to-speech capabilities. | Web Speech API |
Sources: context/PRD.md:73-128
Phase 3: Advanced AI Intelligence
Phase 3 represents a significant evolution, introducing a proactive and highly personalized layer of intelligence. These features are currently in development and are designed to make the system an adaptive learning partner for the farmer.
Sources: context/PRD.md:131-133, context/todos.md:3-5
Database Architecture
The foundation of Phase 3 is a comprehensive database schema designed to store and manage the data required for advanced AI. The schema includes tables for farmer profiles, task recommendations, pest predictions, profitability analysis, market intelligence, community insights, and conversation context.
The following diagram illustrates the relationships between the core AI tables in the Supabase database.
The key tables are summarized below:
| Table | Purpose |
|---|---|
farmer_ai_profiles | Stores personalized AI profiles for each farmer to enable adaptive recommendations. |
ai_task_recommendations | Contains AI-generated task recommendations with reasoning and feedback tracking. |
pest_disease_predictions | Stores weather-based pest/disease predictions and treatment recommendations. |
profitability_analyses | Holds data for expense analysis and profitability optimization insights. |
market_intelligence | Stores market price predictions, trends, and selling optimization data. |
community_insights | Enables anonymous sharing of successful farming practices and outcomes. |
ai_conversation_context | Provides a long-term memory system for AI conversations with relevance decay. |
Sources: supabase/migrations/20250903_phase3_ai_schema.sql:102-108
Personalized Crop Advisory (AI Agronomist)
This system personalizes all AI-driven advice by creating a unique profile for each farmer. The farmer_ai_profiles table captures a farmer's risk tolerance, decision-making patterns, communication style, and success metrics. This profile allows the AI to adapt its recommendations to match the farmer's individual habits and goals.
Sources: context/PRD.md:134-141, supabase/migrations/20250903_phase3_ai_schema.sql:5-16
The FarmerAIProfile interface defines the structure of this data:
// Enhanced Farmer AI Profile
export interface FarmerAIProfile {
id: string;
userId: string;
farmId: number;
riskTolerance: number; // 0-1 scale
decisionPatterns: {
preferredTiming: string; // early_morning, afternoon, evening
riskAversion: number;
adoptionSpeed: 'conservative' | 'moderate' | 'early_adopter';
communicationStyle: 'direct' | 'detailed' | 'visual';
};
successMetrics: {
averageYield: number;
costEfficiency: number;
profitability: number;
waterUseEfficiency: number;
};
learningPreferences: {
preferredChannels: ('voice' | 'text' | 'visual')[];
bestResponseTimes: string[];
languagePreference: 'en' | 'hi' | 'mr';
};
seasonalPatterns: Record<string, any>; // Month-wise activity patterns
createdAt: Date;
updatedAt: Date;
}
Sources: context/TYPES_AND_INTERFACES.md:106-130
Smart Task Generator
The Smart Task Generator proactively creates and schedules farming tasks. It analyzes multiple data points to determine the optimal timing and priority for activities like irrigation and spraying.
The process flow for generating smart tasks is as follows:
This diagram shows how weather, user profile, and farm data are fed into the AI to produce a prioritized list of recommended tasks.
Sources: CLAUDE.md:310-341, context/PRD.md:142-148
The output is a list of AITaskRecommendation objects, stored in the ai_task_recommendations table.
| Field | Type | Description |
|---|---|---|
task_type | text | The type of task (e.g., 'irrigation', 'spray'). |
recommended_date | date | The optimal date to perform the task. |
priority_score | real | A score from 0 to 1 indicating the task's urgency. |
reasoning | text | An AI-generated explanation for why the task is recommended. |
confidence_score | real | The AI's confidence in the recommendation (0-1). |
status | text | The current status ('pending', 'accepted', 'completed', etc.). |
Sources: supabase/migrations/20250903_phase3_ai_schema.sql:19-35
AI-Powered Pest & Disease Alerts
This service provides early warnings for potential pest and disease outbreaks, typically 24-72 hours in advance. It uses predictive modeling based on weather data, historical patterns, and regional reports.
The risk calculation flow is as follows:
This diagram shows how various data sources are used to calculate a risk score, which triggers an alert if it exceeds a set threshold.
Sources: CLAUDE.md:344-377, context/PRD.md:149-157
Enhanced AI Chat Assistant with Long-Term Memory
The AI Chat Assistant is enhanced with long-term memory, allowing it to recall past conversations, decisions, and farm context. This is achieved using the ai_conversation_context table, which stores contextual snippets from conversations.
The following sequence diagram illustrates how context is retrieved and used to answer a user's query.
This system allows the AI to have more meaningful, evolving conversations instead of treating each query as a new, isolated event. The relevance_score and decay_factor fields ensure that the most important and recent context is prioritized.
Sources: CLAUDE.md:417-446, supabase/migrations/20250903_phase3_ai_schema.sql:90-99, context/PRD.md:166-174
Conclusion
The AI-Specific Services are the cornerstone of VineSight's evolution into a premier smart farming platform. By integrating completed Phase 2 features like image-based disease detection with the in-development Phase 3 advanced intelligence, the application provides a holistic support system for farmers. The architecture is designed to be adaptive, personalized, and proactive, leveraging a robust database schema and multi-provider AI integration to deliver tangible value in the form of optimized resource use, improved yields, and enhanced profitability.
Sources: context/PRD.md, CLAUDE.md