-
Notifications
You must be signed in to change notification settings - Fork 0
Description
Category
New Feature
Target Platform
Common (both platforms)
Feature Description
Follow up of #48
I'd like to provide a curated list of basic foods the user can search for, on top of adding raw calories. What I envision is a simple text field in the intake mask where the user writes queries like "160g broccoli", "2 cups of milk", "150g cheese", "a bowl of egg fried rice" and the nutrients display gets filled automatically. For missing foods, the user should be able to add those manually, maybe on a separate mask.
Proposed Solution / Mockup
This could work by providing a module for the app that contains a sqlite3 database, pupulated with food items scraped from USDA sources, published to public domain. In the beginning, the foundation foods should be enough.
Setup:
- Interpolate data, removing duplicate entries by consolidating them into a standard measurement unit (calories per 100g).
- The original unit information should not be lost. It makes sense to measure liquids in ml or cups instead of grams. The USDA data provides information about food categories ("Dairy and Egg products", "Sweets", ...) as well as measure units linked against food times. This can be used for both internally mapping and contextual unit display for user input.
- To make the search work, food items need to be vectorized, e.g. through a sentence transformer model to create embeddings, allowing a cosine similarity search. Embeddings should be normalized into a separate table.
- I have this sentence transformer in mind:
all-MiniLM-L6-v2
User Input:
- It should be made obvious that the search needs to follow a specific pattern. I'd prefer a text field but feasability needs to be explored.
- Text needs to be broken down into:
- a multiplier (e.g. one, 210, a, ...)
- a unit (e.g. cup, loaf, g, quart, ...)
- a food item (e.g. sugar, bread, milk, ...)
- Similarity search is invoked with the food item
- Should the result meet a certain threshold, nutrient information is taken from the table row, using the unit and multiplier for further calculation.
- Should multiple results meet a similar threshold, the user should be prompted to choose manually.
Data structure:
- food_item: Contains name and nutrient information
- food_embedding: 1:1 relation to food_item, contains the vector and food_item id.
- food_unit_conversion: 1:N relation to food_item, contains appropriate measurements (cup, quart, ...) and the 100g equivalent
- generic_unit_conversion: A fallback if unexpected units for a specific food type was entered. There might be a better solution than that but it should suffice to get started.
I don't want to make this part of the core project. The smarter way would be providing it as a module that can be loaded into the app. I have my doubts about the model size which is somewhere between 20-98 MB depending on the format which would be pretty heavy on the initial bundle size.
Problem Statement (Optional)
No response
Alternatives Considered (Optional)
Alternatively, this could be provided as a service but I want the app to work offline.