Full-model detection took ~8 seconds per photo — too slow for a camera app.
Users point the camera at a plant and expect an answer right away. The original flow asked a vision model to produce the full plant profile from scratch every time: slow, costly per call, and free to describe plants that are not in our catalog.
Describe, embed, retrieve, verify — then read from our own database.
- Flutter appcompress to 512px
- Gemininame + embedding
- Supabase Postgrespgvector · match_plants
Trade-offs I made on purpose.
Retrieve from our catalog instead of generating answers
Results always come from curated plant records, so the app never shows a species we have no care data for.
Verify against 5 candidates, not 1
The nearest vector is not always right. A short second Gemini call picks from the top 5 by number, which is cheap and fixes most near-misses.
Strict timeouts and a fallback path
Each step has a timeout. If the RAG path fails or the catalog is not embedded yet, the app falls back to full model detection instead of showing an error.
Strict JSON for diagnosis
Health status, disease name and confidence level come back as structured JSON, so the Flutter UI renders them without parsing free text.
// match_plants.sql
CREATE OR REPLACE FUNCTION public.match_plants(
query_embedding vector(768),
match_count integer DEFAULT 5
) RETURNS TABLE (id uuid, common_name text, similarity double precision)
LANGUAGE sql STABLE AS $$
SELECT id, common_name,
1 - (embedding <=> query_embedding) AS similarity
FROM public.plants
WHERE embedding IS NOT NULL
ORDER BY embedding <=> query_embedding
LIMIT match_count;
$$;