-
Notifications
You must be signed in to change notification settings - Fork 32
Recipe Modeler
The modeler—used by KitchenPC's “What can I make?” experience—searches for a set of recipes that balances ratings, preferences, restrictions, and efficient use of pantry ingredients.
It requires DBContextCapabilities.RecipeModeler (or All) and loads an in-memory graph. Measure startup and memory with production-scale recipe data before enabling it in a web process.
Model result = context.Modeler
.WithAnonymous
.NumRecipes(5)
.Scale(50)
.Generate();Generate returns recipe IDs, remaining pantry values, and a score. Scale controls the balance used by the modeling session; validate it at the application boundary.
CompiledModel result = context.Modeler
.WithAnonymous
.NumRecipes(5)
.Compile();Compile adds RecipeBrief values and aggregation data useful for rendering recipes and what the user will need.
var bananas = context.ParseIngredientUsage("12 bananas");
var carrots = context.ParseIngredientUsage("carrots");
var result = context.Modeler
.WithProfile(profile => profile
.AddPantryItem(bananas.Usage)
.AddPantryItem(carrots.Usage)
.AddBlacklistedIngredient(Ingredient.FromId(eggId))
.FavoriteTags(RecipeTag.Dessert | RecipeTag.GlutenFree)
.AvoidRecipe(previousRecipeId))
.NumRecipes(5)
.Compile();A profile can also provide ratings, favorite ingredients, allowed tags, and a user ID. Implement IUserProfile when preferences come from your own service, or use the fluent ProfileCreator for an ad hoc request.
NLP is not intrinsically required by the modeler: it accepts normalized PantryItem/IngredientUsage data. Enable IngredientParsing too only if your application accepts free-form pantry text.
- The algorithm's usefulness depends on recipe diversity, ingredient metadata, ratings, and realistic quantities.
- A tiny sample with 30 recipes may not satisfy restrictive profiles.
- Treat “no result” as an ordinary outcome and let users relax constraints.
- Do not rebuild the graph per request.
- Consider a dedicated worker or service if production graph size makes web startup undesirable.
KitchenPC is MIT licensed. Runnable applications live in KitchenPC/Samples.