Description
The recommendation algorithm produces non-deterministic results when multiple projects have the same score. This causes inconsistent project recommendations for the same user inputs across different requests or server restarts.
Affected File
utils/recommender.py
Problem
In the get_recommendations() function (lines 94-124), after scoring all projects, the sorting only uses the score as the key:
scored_projects.sort(key=lambda item: item["score"], reverse=True)
When two or more projects have identical scores, Python's sort is unstable - the relative order of equal-scoring items depends on their original order in the list, which can vary based on:
- The order they appear in
projects.json
- Previous modifications to the JSON file
- File system ordering
Real-world Impact
Users with the same skillset, level, interest, and time availability may get different top 3 recommendations on:
- Different days
- After the JSON file is modified (even unrelated changes)
- Across different server instances
This makes testing difficult and confuses users who expect consistent results.
Expected Behavior
When scores are tied, there should be a consistent secondary sort key (e.g., project ID or name alphabetically) to ensure deterministic results.
Suggested Fix
Add secondary sort criteria in get_recommendations():
scored_projects.sort(key=lambda item: (item["score"], item["project"].get("id", 0)), reverse=True)
Or sort by project title as secondary:
scored_projects.sort(key=lambda item: (item["score"], item["project"].get("title", "")), reverse=True)
Description
The recommendation algorithm produces non-deterministic results when multiple projects have the same score. This causes inconsistent project recommendations for the same user inputs across different requests or server restarts.
Affected File
utils/recommender.pyProblem
In the
get_recommendations()function (lines 94-124), after scoring all projects, the sorting only uses the score as the key:When two or more projects have identical scores, Python's sort is unstable - the relative order of equal-scoring items depends on their original order in the list, which can vary based on:
projects.jsonReal-world Impact
Users with the same skillset, level, interest, and time availability may get different top 3 recommendations on:
This makes testing difficult and confuses users who expect consistent results.
Expected Behavior
When scores are tied, there should be a consistent secondary sort key (e.g., project ID or name alphabetically) to ensure deterministic results.
Suggested Fix
Add secondary sort criteria in
get_recommendations():Or sort by project title as secondary: