Difference between revisions of "Client-side libraries for personalized product filtering and ranking"
Line 48: | Line 48: | ||
} | } | ||
</pre> | </pre> | ||
+ | |||
+ | == Product Attributes == | ||
+ | |||
+ | For each product, the server returns a match value for each attribute in a standardized format. | ||
+ | |||
+ | See [[Product Attributes]]. | ||
+ | |||
+ | == Scoring == | ||
+ | |||
+ | On the client side, a library computes a score for each product returned by a search: | ||
+ | |||
+ | === Input and output values === | ||
+ | |||
+ | * Input values for scoring | ||
+ | ** Locally saved user preferences | ||
+ | ** Product attributes returned by the server API | ||
+ | * Output value | ||
+ | ** Score | ||
+ | |||
+ | === Algorithm === | ||
+ | |||
+ | * for each requirement in user preferences | ||
+ | ** if requirement is mandatory, score = score + match * 4 | ||
+ | *** and exclude product is match is less than 20% | ||
+ | *** or mark product as unknown if the attribute value is unknown (e.g. the server is missing some data to compute the match for the attribute) | ||
+ | ** if requirement is very important, score = score + match * 2 | ||
+ | ** if requirement is important, score = score + match | ||
+ | |||
+ | === Implementation === | ||
+ | |||
+ | * Flutter | ||
+ | * Javascript | ||
+ | ** UI to locally save user preferences - https://github.com/openfoodfacts/openfoodfacts-server/issues/4119 | ||
+ | ** Javascript library to score a product based on locally saved user preferences + product attributes from the API - https://github.com/openfoodfacts/openfoodfacts-server/issues/4120** | ||
[[Category:Project:Personalized_Search]] | [[Category:Project:Personalized_Search]] | ||
[[Category:ProductOpener]] | [[Category:ProductOpener]] |
Revision as of 09:22, 8 September 2020
Summary
Client-side libraries for personalized product filtering and ranking is the 3rd of the 4 sub-tasks of the Project:Personalized_Search funded by the NGI0 Discovery Fund managed by NlNet.
Overview
Diagram source: https://vecta.io/app/edit/-M2XyVv8ZoaLNrW-zQoT
- The Open Food Facts mobile app (and 3rd party apps) make generic search requests that do not contain user preferences
- The server returns a big number of generic results
- The app uses the user preferences stored locally to personalize the search results
User preferences
The user preferences are stored locally on the client (mobile app or browser).
User preferences format
To make it easier to develop libraries to show / edit / store preferences, and to use them to rank products, we define a standard format to save user preferences.
The preferences are saved in name / value pairs (hash table / associative array) of attribute ids mapping to string values.
The list of attribute ids will be sent by the server, along with localized names, descriptions, warnings etc.
String values:
- "unset" : the user has not set a preference for the attribute (in ranking, treated like "not_important")
- "not_important"
- "important"
- "very_important"
- "mandatory"
The user preferences structure may not contain all possible attributes (e.g. if the server adds new attributes). In that case unexisting values are considered "unset".
Notes:
- String values are used instead of 0, 1, 2, 3, 4 etc. so that the JSON is clearer to understand for humans, and so that we have the flexibility to add other values later (e.g. "somewhat_important")
Example
{ "nutriscore": "very_important", "nova": "not_important", "labels_organic": "very_important", "labels_fair_trade": "important" }
Product Attributes
For each product, the server returns a match value for each attribute in a standardized format.
See Product Attributes.
Scoring
On the client side, a library computes a score for each product returned by a search:
Input and output values
- Input values for scoring
- Locally saved user preferences
- Product attributes returned by the server API
- Output value
- Score
Algorithm
- for each requirement in user preferences
- if requirement is mandatory, score = score + match * 4
- and exclude product is match is less than 20%
- or mark product as unknown if the attribute value is unknown (e.g. the server is missing some data to compute the match for the attribute)
- if requirement is very important, score = score + match * 2
- if requirement is important, score = score + match
- if requirement is mandatory, score = score + match * 4
Implementation
- Flutter
- Javascript
- UI to locally save user preferences - https://github.com/openfoodfacts/openfoodfacts-server/issues/4119
- Javascript library to score a product based on locally saved user preferences + product attributes from the API - https://github.com/openfoodfacts/openfoodfacts-server/issues/4120**