Repository navigation
Move recommendation algorithm into the application layer - #90
Merged
Merged
Conversation
The recommendation algorithm previously lived entirely in a single PostgreSQL function. This moves scoring, the overlap gate, weighting, and ranking into a new C# RecommendationService, leaving the database to expose only data primitives (candidate ingredient sets, favorites, cook dates, summaries) via migration 018. The pure ScoreCandidates method has no DB dependency, so the policy is directly unit-testable. Also adjusts the algorithm itself: - Remove the ownership signal entirely. - Require >=2 shared ingredients before a recipe is recommended (a hard gate for everyone; favorite/novelty only re-rank within that set). - Renormalize weights to sum to 1.0: similarity 0.70, favorite 0.18, novelty 0.12. Drops ownedByUser from the DTO, TS type, and admin score breakdown. Adds pure unit tests for the scoring policy and updates the integration tests for the new weights and gate. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #89.
Summary
Relocates the recipe recommendation algorithm from a single PostgreSQL function into the C# application, and adjusts the algorithm: the ownership signal is gone and a recipe must share at least 2 ingredients with the source to be recommended.
Why: the database is great at indexes and set-membership lookups, but the recommendation policy (scoring, weighting, thresholds, ranking) is easier to read, unit-test, and evolve in application code without a migration. The DB now exposes primitives; the app composes them.
Changes
Database — new migration
018_recommendation_primitives.sql:cooktime.recommend_recipes.get_candidate_ingredient_sets,get_user_favorite_recipe_ids,get_user_last_cooked,get_recipe_summaries.Application — new
RecommendationService:ScoreCandidates(...)does Jaccard similarity, the >=2-overlap gate, weighting, and ranking with no DB access (directly unit-testable).CookTimeDBdropsGetRecipeRecommendationsAsync, gains the four primitive fetch methods.RecommendationService; the service performs the existence check (null-> 404).Algorithm changes
Contract + frontend —
ownedByUser/ "Your recipe" removed from the DTO, the TS type, and the admin score breakdown.Docs — blog post updated to describe the app-side algorithm, the overlap gate, and new weights.
Tests
scripts/test-> 47/47 pass (43 existing + 4 new pure unit tests inTestRecommendationService).scripts/test --lint-> 0 errors.Test plan
🤖 Generated with Claude Code