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.
Created an initial pull request for the rule system. Issue #1483
Main PR contents:
newsflash_features
table (with Alembic)is_urban
RequestParams
)rank
field and the range [0.0-1.0]Details
Basics
The rules feature couples each newsflash object with a features object. The features object is generated once per newsflash (per version, more on that later). The features are stored in the DB, both for avoiding constant re-generation and for later analysis and debugging. The generated features are used by each widget for grading its own relevance to the newsflash. The widget generation system sorts the widget by descending relevance - from highest to lowest (based on the ranking by the rule system).
Features
The features are a set of enrichment values which are used by the widgets' ranking code. The features themselves are generated by a
FeatureGenerator
object. The Feature Generator receives a newsflash and outputs aNewsflashFeatures
object, which is stored to the DB. Aside from the enrichment fields and the coupled newsflash ID, theNewsflashFeatures
object has some metadata - creation timestamp and version.Features Version
The version is a numeric constant which denotes the current feature code version. It is a monotonically increasing integer. For example, it may be
1
, but after a modification was made to fix a feature's generation logic, it is incremented to2
. An incrementation MUST take place whenever a change is made to the feature generation code or schema.When retrieving the stored features for a newsflash, only the latest row with the matching version to the constant in the app's code is fetched, ensuring compatibility.
Generation flow
When a Newsflash object is retrieved from the DB, the existence of a matching
NewsflashFeatures
with a version matching the current value in the app's code is checked. If a features object is found, it is fetched. Otherwise, it is generated and persisted. This flow ensures that whenever the features generation version changes, any existing features objects are invalidated and new ones are generated on-demand - once per newsflash. Keeping the existing rows allows us to perform comparative analysis between features generated by different versions.TBD in Next PRs
is_urban
feature by @dinasv