{"id":6672,"library":"implicit","title":"Implicit Collaborative Filtering","description":"Implicit is a Python library that provides fast Python implementations of popular collaborative filtering recommendation algorithms for implicit feedback datasets. It includes models like Alternating Least Squares (ALS), BPR (Bayesian Personalized Ranking), and various Nearest-Neighbours models. The library leverages Cython, NumPy, and SciPy for performance, with optional GPU acceleration using CUDA. The current version is 0.7.2, and new versions are released periodically, often every few months, with a focus on performance, new features, and bug fixes.","status":"active","version":"0.7.2","language":"python","source_language":"en","source_url":"https://github.com/benfred/implicit/","tags":["recommendation-systems","collaborative-filtering","machine-learning","implicit-feedback","als","bpr","gpu-acceleration"],"install":[{"cmd":"pip install implicit","lang":"bash","label":"CPU-only installation"},{"cmd":"pip install implicit[gpu]","lang":"bash","label":"GPU-enabled installation (requires CUDA Toolkit)"}],"dependencies":[{"reason":"Core numerical operations and array handling.","package":"numpy","optional":false},{"reason":"Sparse matrix operations (e.g., csr_matrix) are fundamental inputs.","package":"scipy","optional":false},{"reason":"Used for detecting and controlling the number of threads used by BLAS/LAPACK libraries to prevent oversubscription.","package":"threadpoolctl","optional":false},{"reason":"Required for GPU acceleration with the 'gpu' extra. Requires a compatible CUDA Toolkit installation.","package":"cupy","optional":true}],"imports":[{"symbol":"AlternatingLeastSquares","correct":"from implicit.als import AlternatingLeastSquares"},{"symbol":"CosineRecommender","correct":"from implicit.nearest_neighbours import CosineRecommender"},{"symbol":"BM25Recommender","correct":"from implicit.nearest_neighbours import BM25Recommender"},{"note":"The FactorizationMachines model was moved to factorization_machines in older versions, but the primary module is now implicit.fm.  Ensure you use the correct module path for your installed version. As of 0.7.x, implicit.factorization_machines is correct.","wrong":"from implicit.fm import FactorizationMachines","symbol":"FactorizationMachines","correct":"from implicit.factorization_machines import FactorizationMachines"}],"quickstart":{"code":"import numpy as np\nfrom scipy.sparse import csr_matrix\nfrom implicit.als import AlternatingLeastSquares\n\n# Sample data: user-item interactions (user_id, item_id, strength)\ndata = np.array([1, 1, 1, 1, 1, 1])\nrows = np.array([0, 0, 1, 1, 2, 2]) # User IDs\ncols = np.array([0, 1, 1, 2, 0, 2]) # Item IDs\n\n# Create a sparse user-item matrix (users x items)\n# This is typically a CSR matrix for performance and compatibility.\nuser_items = csr_matrix((data, (rows, cols)), dtype=np.float32)\n\n# Initialize and train the AlternatingLeastSquares model\nmodel = AlternatingLeastSquares(factors=64, regularization=0.01, iterations=20, random_state=42)\nmodel.fit(user_items) # Model expects user_items (users x items) matrix\n\n# Recommend items for a specific user (e.g., user 0)\nuser_id = 0\n# The recommend method takes the user_id and the user_items matrix for that user.\nrecommended_items, scores = model.recommend(user_id, user_items[user_id])\n\nprint(f\"Recommended items for user {user_id}: {recommended_items}\")\nprint(f\"Scores: {scores}\")\n\n# Get similar items for a specific item (e.g., item 0)\nitem_id = 0\nsimilar_items, scores = model.similar_items(item_id)\nprint(f\"Items similar to item {item_id}: {similar_items}\")\nprint(f\"Scores: {scores}\")","lang":"python","description":"This quickstart demonstrates how to train an AlternatingLeastSquares model on a sparse user-item interaction matrix and then generate recommendations for a user and find similar items. The input matrix must be a `scipy.sparse.csr_matrix`."},"warnings":[{"fix":"Specifically, `model.fit()` now expects a `user_items` matrix (users x items) instead of `item_users`. Additionally, recommendation methods (`model.recommend()`, `model.similar_items()`) now return NumPy arrays instead of lists of tuples. Consult the v0.5.0 release notes and current documentation.","message":"The API for `implicit` underwent substantial breaking changes in v0.5.0. Code written for versions prior to 0.5.0 will need to be rewritten.","severity":"breaking","affected_versions":"<0.5.0"},{"fix":"Always convert your interaction data into a `scipy.sparse.csr_matrix` (Compressed Sparse Row) before passing it to `model.fit()`. For example, `user_items = csr_matrix(your_data)`.","message":"Model training methods (e.g., `model.fit()`) often require input matrices to be in `scipy.sparse.csr_matrix` format for optimal performance and correctness.","severity":"gotcha","affected_versions":"All"},{"fix":"Install with `pip install implicit[gpu]`. Ensure your NVIDIA drivers and CUDA Toolkit version are compatible with `CuPy`, the underlying library used for GPU computation. Refer to the CuPy documentation for system requirements.","message":"Using GPU acceleration requires specific setup, including installing the `implicit[gpu]` extra and having a compatible CUDA Toolkit installed and configured on your system.","severity":"gotcha","affected_versions":"All"},{"fix":"Implicit uses `threadpoolctl` to help manage BLAS threading. However, if you encounter performance issues, explicitly control the number of threads for BLAS/OpenMP via environment variables (e.g., `OMP_NUM_THREADS`, `MKL_NUM_THREADS`) or by using `threadpoolctl` directly.","message":"When running on multi-core CPUs with BLAS/LAPACK libraries (like OpenBLAS, MKL), implicit threading can sometimes lead to oversubscription and performance degradation.","severity":"gotcha","affected_versions":"All"}],"env_vars":null,"search_vec":"'0.7.2':61 'acceler':54,98 'al':31,94 'algorithm':19 'altern':28 'bayesian':33 'bpr':32,95 'bug':80 'collabor':2,16,86 'collaborative-filt':85 'cuda':56 'current':58 'cython':45 'dataset':23 'everi':69 'fast':11 'featur':78 'feedback':22,93 'filter':3,17,87 'fix':81 'focus':74 'gpu':53,97 'gpu-acceler':96 'implement':13 'implicit':1,4,21,92 'implicit-feedback':91 'includ':25 'learn':90 'least':29 'leverag':44 'librari':8,43 'like':27 'machin':89 'machine-learn':88 'model':26,41 'month':71 'nearest':39 'nearest-neighbour':38 'neighbour':40 'new':63,77 'numpi':46 'often':68 'option':52 'perform':50,76 'period':67 'person':34 'popular':15 'provid':10 'python':7,12 'rank':35 'recommend':18,83 'recommendation-system':82 'releas':66 'scipi':48 'squar':30 'system':84 'use':55 'various':37 'version':59,64","created_at":"2026-04-15T18:37:59.251155+00:00","updated_at":"2026-04-16T15:43:07.477762+00:00","problems":[{"fix":"Install the library using pip: `pip install implicit` or, for GPU support or specific configurations, `conda install -c conda-forge implicit` (CPU only) or `conda install -c conda-forge implicit implicit-proc=*=gpu` (CPU+GPU).","cause":"The 'implicit' library is not installed in the current Python environment or the environment where the code is being run.","error":"ModuleNotFoundError: No module named 'implicit'"},{"fix":"Import `AlternatingLeastSquares` specifically from `implicit.als`: `from implicit.als import AlternatingLeastSquares`.","cause":"The `ALS` class is not directly available under the top-level `implicit` module. It resides within the `implicit.als` submodule. This can also happen if a local file is named 'implicit.py', shadowing the actual library.","error":"AttributeError: module 'implicit' has no attribute 'als'"},{"fix":"Ensure the NVIDIA CUDA Toolkit is installed (version 11 or later is required for implicit v0.7.2) and that `nvcc` is on your system's PATH. Reinstall `implicit` with GPU support, potentially setting the `CUDAHOME` environment variable if `nvcc` is not automatically found. For conda users, install with `conda install -c conda-forge implicit implicit-proc=*=gpu`.","cause":"This error occurs when `implicit` is configured to use a GPU (`use_gpu=True`), but the CUDA extension for the library has not been successfully built or cannot be found. This often indicates missing CUDA toolkit dependencies or incorrect environment variable settings during installation.","error":"ImportError: No module named 'implicit.cuda._cuda'"},{"fix":"Ensure that the `user_items` matrix passed to `model.recommend(userid, user_items)` is a slice of your full user-item matrix corresponding *only* to the `userid` being processed, or a matrix with the correct dimensions if recommending for multiple users. For a single user, `user_item_data[userid]` is typically used.","cause":"When calling the `model.recommend()` method, the `user_items` sparse matrix provided as input does not have the correct shape. It expects a matrix where the number of rows matches the number of users for whom recommendations are being generated.","error":"ValueError: user_items must contain 1 row for every user in userids"},{"fix":"Ensure all dependencies are up-to-date and compatible with `implicit` 0.7.2. Try updating SciPy (`pip install --upgrade scipy`) and NumPy. Verify that the input matrices (e.g., `user_items` and `test_user_items`) are correctly formatted as sparse matrices (e.g., `csr_matrix` or `coo_matrix`) and contain appropriate data types before passing them to the evaluation functions.","cause":"This error typically arises when using evaluation functions like `mean_average_precision_at_k` and is often related to an internal data type or memory view issue, potentially a version incompatibility between `implicit` and its dependencies (like NumPy or SciPy), or how data is being passed to the evaluation function.","error":"AttributeError: 'implicit.evaluation._memoryviewslice' object has no attribute 'dtype'"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"0.7.3","cli_name":"","cli_version":null,"type":"library","homepage":"https://implicit.readthedocs.io","github":null,"docs":null,"changelog":null,"pypi":"https://pypi.org/project/implicit/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["ai-ml"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-28","last_verified":"2026-06-28","next_check":"2026-07-28","install_tag":null}}