-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Labels
featureIntroduces a new and complete featureIntroduces a new and complete feature
Description
name: LLM Rag pipeline for Recommendation
title: "[FEAT] - Rag Recommendation Pipeline"
labels: feature, backlog
assignees: @mdeekshita @SHarg9876 @keshavgoel787
Summary
LLM-powered RAG pipeline that auto-suggests ingredients and trigger bucket tags
Motivation
Likely that users are unaware of buckets and potential ingredient triggers, so suggestions can be a really powerful feature!
Requirements
Acceptance Criteria
Sub-task 1: Tag & Bucket Models
-
Tagmodel created with fields:id(UUID),name(String),is_system(bool — True if LLM-suggested, False if user-defined),created_at -
FoodLogTagjoin table created linkingfood_logs.id→tags.id - System tags seeded for core trigger buckets: gluten, FODMAPs, nightshades, histamines, added sugar, artificial additives, dairy, FDA Big 9 allergens
-
TagCreateandTagResponseschemas created -
SuggestedIngredientResponseschema created with fields:name(String),buckets(list of String) -
FoodLogResponseupdated to includesuggested_tagsandsuggested_ingredients: list[SuggestedIngredientResponse]fields
Sub-task 2: Tag Endpoints
-
POST /food-log/{food_log_id}/tags— confirms and persists tags to a food log -
POST /tags— creates a custom user-defined tag (is_system=False) -
GET /tags— returns all available tags for a user to pick from - Unconfirmed tags must not be persisted until user explicitly confirms
Sub-task 3: Vector Store & RAG Infrastructure
- pgvector extension enabled on Supabase
-
KnowledgeChunkmodel created with fields:id(UUID),content(Text),embedding(Vector),source(String) - Embedding generation utility using Gemini
models/text-embedding-004 - Similarity search function that takes a food name query, returns top N relevant chunks from the knowledge store
- Seeding script scaffolded with TODOs for document sources (Monash FODMAP, FDA Big 9, AIP framework) — actual content to be added once sources are confirmed
Sub-task 4: RAG Tagging Service
-
RAGTaggingServicecreated that follows the same constructor pattern asFoodService - Given a food name and its
ingredientsJSONB field, runs similarity search to retrieve relevant trigger context chunks - LLM prompt built with: food name, ingredients, retrieved context chunks — instructs LLM to suggest likely ingredients and classify each into trigger buckets without hallucinating unlikely ingredients
- Returns structured response:
suggested_ingredients: list[SuggestedIngredientResponse] - Hooked into food log creation flow — suggestions returned in response, not auto-saved
Out of Scope
- Frontend confirmation UI — backend only
- Actual seeding of knowledge documents — scaffolded only, content TBD
- Apriori analysis — separate ticket
- Barcode scan or external food API integration
Technical Approach
Affected Areas
backend/models/tag.py(new) —TagandFoodLogTagmodelsbackend/models/knowledge_chunk.py(new) — vector store modelbackend/models/food_log.py— add relationship toFoodLogTagbackend/schemas/tag.py(new) —TagCreate,TagResponse,SuggestedIngredientResponsebackend/schemas/food.py— addsuggested_tagsandsuggested_ingredientstoFoodLogResponsebackend/services/tagging_service.py(new) — tag business logicbackend/services/rag_tagging_service.py(new) — RAG + LLM suggestion logicbackend/repositories/food_repository.py— add tag persistence methodsbackend/repositories/tag_repository.py(new)backend/routers/food_router.py— update create endpointbackend/routers/tag_router.py(new) — register inmain.py
Dependencies
Food,FoodLogmodels existFoodService,FoodRepositorypatterns exist- pgvector must be enabled on Supabase before sub-task 3 begins (I might have to update the docker image for the test db for this I'll look into this though)
Testing Notes
Follow existing integration test patterns in backend/tests/integration/
- LLM suggestion — given a
Foodwith populatedingredientsJSONB, correct trigger bucket tags and suggested ingredients returned - Sparse ingredients —
Foodwithingredients=Noneshould return reasonable suggestions from food name alone without hallucinating - RAG retrieval — similarity search should return relevant chunks for a given food query
- Tag confirmation — unconfirmed tags must not appear in DB after food log creation
- Suggested ingredients — must never be persisted, only returned in response
- Custom tag creation —
is_system=Falsetag persists and appears inGET /tags - Duplicate tags — saving same tag to a food log twice should not create duplicate join table entries
Additional Context
Reactions are currently unavailable
Metadata
Metadata
Labels
featureIntroduces a new and complete featureIntroduces a new and complete feature