π Overview
As part of the Gen AI Intensive Course by Google & Kaggle, I built a PetCare AI Assistant β a conversational tool that helps pet owners get structured health advice based on their petβs symptoms.
Rather than just prompting an LLM, I implemented a full Retrieval-Augmented Generation (RAG) pipeline using Gemini, vector search, and real veterinary PDFs. The assistant outputs actionable diagnostic advice in structured JSON format, with urgency level and recommended next steps.
π‘ The Problem
Most pet owners rely on scattered or unverified sources when their pet falls ill. The goal was to build an AI assistant that could understand a pet's symptoms and generate grounded, real-time advice β powered by GenAI and veterinary documents.
β GenAI Capabilities Demonstrated
1.Few-shot Prompting
2.Document Understanding (PDFs)
3.Structured JSON Output
4.Retrieval-Augmented Generation (RAG)
5.Evaluation of output vs expert diagnosis
π Dataset & Documents
I used real-world veterinary PDFs including:
- Indian Government's Standard Treatment Guidelines (Livestock & Pets)
- BSN Medical Veterinary Case Study Booklet
- Veterinary Clinical Pathology reports (academic cases)
These were processed using PyMuPDF
and sentence-transformers
.
import fitz # PyMuPDF
def extract_text_from_pdf(pdf_path):
doc = fitz.open(pdf_path)
text = ""
for page in doc:
text += page.get_text()
return text
Once text was extracted, I chunked the paragraphs and embedded them:
from sentence_transformers import SentenceTransformer
# Chunking
chunks = [para for para in text.split(". ") if len(para) > 50]
# Embedding
embed_model = SentenceTransformer("all-MiniLM-L6-v2")
embeddings = [embed_model.encode(c, convert_to_numpy=True) for c in chunks]
π§ Gemini + RAG Workflow
Hereβs how it works:
- π User submits a symptom query
- π Most relevant document chunks are retrieved using embeddings
- π§ Gemini is prompted with few-shot examples + document context
- π§Ύ Gemini generates a structured diagnosis like:
{
"problem_category": "health",
"preliminary_diagnosis": "Gastrointestinal upset likely due to spoiled food",
"suggested_action": "Provide hydration, switch to bland diet, consult vet if persists",
"recommended_services": ["Vet Consultation", "Diet Review"],
"urgency": "Medium"
}
User query β converted to vector β top chunks retrieved by cosine similarity:
from sklearn.metrics.pairwise import cosine_similarity
query_vec = embed_model.encode(user_query).reshape(1, -1)
sims = cosine_similarity(query_vec, embeddings)[0]
top_idxs = sims.argsort()[-3:][::-1]
retrieved_context = "\n".join([chunks[i] for i in top_idxs])
π§ Output Evaluation
To measure how close Geminiβs suggestion was to a vet plan, I used cosine similarity:
from sklearn.metrics.pairwise import cosine_similarity
gemini_vec = embed_model.encode(gemini_output)
expert_vec = embed_model.encode(vet_plan)
score = cosine_similarity([gemini_vec], [expert_vec])[0][0]
π Challenges Faced
- Gemini often returned JSON inside code blocks β had to clean with custom parser
- Chunking was tricky for noisy scanned PDFs
- Retrieval quality directly affected diagnosis quality
π Future Improvements
Extend support to include diet, vaccination, and grooming
π Kaggle Notebook Link
https://www.kaggle.com/code/shashank0907/petcare-ai-assistant
Top comments (0)