ckanext-recommendation provides item recommendations for CKAN.
The first version builds item-based collaborative filtering models from
normalized implicit interactions, with ckanext-likes implemented as the
first production-ready source adapter. The future normalized table source is
present only as an architectural stub and is not runnable yet.
Compatibility with core CKAN versions:
| CKAN version | Compatible? |
|---|---|
| 2.11 | yes |
To install ckanext-recommendation:
-
Activate your CKAN virtual environment, for example:
. /usr/lib/ckan/default/bin/activate
-
Clone the source and install it on the virtualenv
git clone https://github.com/DataShades/ckanext-recommendation.git cd ckanext-recommendation pip install -e . pip install -r requirements.txt
-
Install and enable
ckanext-likes, then apply its migrations. The current MVP useslikesas the only production-ready interaction source:pip install ckanext-likes ckan db upgrade -p likes
-
Add
recommendationto theckan.pluginssetting in your CKAN config file (by default the config file is located at/etc/ckan/default/ckan.ini). -
Restart CKAN. For example if you've deployed CKAN with Apache on Ubuntu:
sudo service apache2 reload
Key configuration options:
ckanext.recommendation.enabled = true
ckanext.recommendation.source = likes
ckanext.recommendation.sources = likes
ckanext.recommendation.algorithm = item_cf
ckanext.recommendation.object_types = package
ckanext.recommendation.default_object_type = package
ckanext.recommendation.type_show_actions = {"package": "package_show", "resource": "resource_show"}
ckanext.recommendation.max_limit = 20
ckanext.recommendation.default_limit = 10
ckanext.recommendation.min_interactions_per_item = 1
ckanext.recommendation.min_interactions_per_user = 1
ckanext.recommendation.similarity = cosine
ckanext.recommendation.include_scores_default = false
ckanext.recommendation.cache_enabled = true
ckanext.recommendation.cache_backend = memory
ckanext.recommendation.cache_ttl = 3600
ckanext.recommendation.likes.signal_weight = 1.0
ckanext.recommendation.likes.require_extension = true
ckanext.recommendation.allow_user_id_override = false
ckanext.recommendation.exclude_already_interacted = true
All options are declared with defaults in
ckanext/recommendation/config_declaration.yaml, and the extension reads them
via tk.config["..."].
ckanext.recommendation.type_show_actions is the explicit contract between
recommendation object_type values and CKAN visibility checks. Custom object
types must be mapped to their corresponding CKAN *_show action names.
Source notes:
likesis the current production-ready source.tableis a reserved stub for the future normalized interaction store and will report itself as unavailable until implemented.compositeis the glue layer for combining concrete sources.
The public API is action-based:
recommendation_item_suggestionsrecommendation_user_suggestionsrecommendation_status_showrecommendation_rebuild
Returns datasets similar to a subject item using item-based collaborative filtering.
Required parameters:
id: subject object idtype: recommendation object type, eg.package
Optional parameters:
limitoffsetexclude_idsinclude_scores
Behavior:
- validates that the subject object exists and is visible to the current user
- filters out recommended objects that are deleted, missing or not accessible
- uses
ckanext.recommendation.type_show_actionsto resolve visibility checks
Example:
ckan action recommendation_item_suggestions id=<dataset_id> type=package
Returns personalized recommendations for a user profile by aggregating neighbors of the items the user has already interacted with.
Optional parameters:
user_idtypeslimitoffsetexclude_idsinclude_scores
Behavior:
- if
user_idis omitted, the current authenticated user is used - non-sysadmin users may only request their own recommendations unless
ckanext.recommendation.allow_user_id_override = true - sysadmins may request recommendations for any user
- inaccessible or deleted objects are filtered from the response
Example:
ckan action recommendation_user_suggestions user_id=<user_id> types=package
Returns diagnostic information about the recommendation subsystem.
The response includes:
- whether the extension is enabled
- active source and per-source status details
- configured object types
type_show_actionsmapping- cache status
- model cache status for configured object type variants
Example:
ckan action recommendation_status_show
Forces model rebuild and returns resulting model statistics.
Optional parameters:
typessource
Behavior:
- sysadmin-only
- bypasses existing cached model and stores a freshly rebuilt one
- returns cache key, source status and model stats such as interaction count, user count, item count and similarity edges
Example:
ckan action recommendation_rebuild types=package
Recommendation actions return a common envelope:
source: resolved interaction source namealgorithm: recommendation algorithm idsubject: request subject, eg. item id/type or user idcount: number of returned resultsresults: list of{id, type}objects, with optionalscore
For manual verification you can seed a deterministic recommendation dataset:
ckan recommendation seed-demo-data
To recreate likes for the same fixed demo matrix:
ckan recommendation seed-demo-data --reset
The command creates demo users, datasets and ckanext-likes records from a
fixed in-code matrix so that item similarity, personalized recommendations,
bridge users, sparse items and low-profile users can all be checked quickly.
To install ckanext-recommendation for development, activate your CKAN virtualenv and do:
git clone https://github.com/DataShades/ckanext-recommendation.git
cd ckanext-recommendation
pip install -e .
pip install -r dev-requirements.txt
To run the tests, do:
pytest --ckan-ini=test.ini
If ckanext-recommendation should be available on PyPI you can follow these steps to publish a new version:
-
Update the version number in the
pyproject.tomlfile. See PEP 440 for how to choose version numbers. -
Make sure you have the latest version of necessary packages:
pip install --upgrade setuptools wheel twine
-
Create a source and binary distributions of the new version:
python -m build && twine check dist/*Fix any errors you get.
-
Upload the source distribution to PyPI:
twine upload dist/* -
Commit any outstanding changes:
git commit -a git push -
Tag the new release of the project on GitHub with the version number from the
setup.pyfile. For example if the version number insetup.pyis 0.0.1 then do:git tag 0.0.1 git push --tags