Registry / ai-ml / implicit

implicit

JSON →
library0.7.3pypypi✓ verified 84d ago

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.

pip install implicit
INSTALL
IMPORT
SIG · IMPLICIT
I
implicit
ai-mlpythonv0.7.3
Install
8.0s avg
Import
Disk
289MB
Pass rate
5/ 10
Env Coverage5 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.7.3 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.940 runs
build_error
glibc
py 3.103.940 runs
installs and imports cleanly · install 8.0s · import 0.000s · 297MB
289MB installed
● package 289MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

AlternatingLeastSquares
from implicit.als import AlternatingLeastSquares
CosineRecommender
from implicit.nearest_neighbours import CosineRecommender
BM25Recommender
from implicit.nearest_neighbours import BM25Recommender
FactorizationMachines
from implicit.factorization_machines import FactorizationMachines
from implicit.fm import FactorizationMachines
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.

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`.

import numpy as np from scipy.sparse import csr_matrix from implicit.als import AlternatingLeastSquares # Sample data: user-item interactions (user_id, item_id, strength) data = np.array([1, 1, 1, 1, 1, 1]) rows = np.array([0, 0, 1, 1, 2, 2]) # User IDs cols = np.array([0, 1, 1, 2, 0, 2]) # Item IDs # Create a sparse user-item matrix (users x items) # This is typically a CSR matrix for performance and compatibility. user_items = csr_matrix((data, (rows, cols)), dtype=np.float32) # Initialize and train the AlternatingLeastSquares model model = AlternatingLeastSquares(factors=64, regularization=0.01, iterations=20, random_state=42) model.fit(user_items) # Model expects user_items (users x items) matrix # Recommend items for a specific user (e.g., user 0) user_id = 0 # The recommend method takes the user_id and the user_items matrix for that user. recommended_items, scores = model.recommend(user_id, user_items[user_id]) print(f"Recommended items for user {user_id}: {recommended_items}") print(f"Scores: {scores}") # Get similar items for a specific item (e.g., item 0) item_id = 0 similar_items, scores = model.similar_items(item_id) print(f"Items similar to item {item_id}: {similar_items}") print(f"Scores: {scores}")
Debug
Known issues
breakingThe 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.
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.
affects: <0.5.0
gotchaModel training methods (e.g., `model.fit()`) often require input matrices to be in `scipy.sparse.csr_matrix` format for optimal performance and correctness.
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)`.
affects: All
gotchaUsing GPU acceleration requires specific setup, including installing the `implicit[gpu]` extra and having a compatible CUDA Toolkit installed and configured on your system.
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.
affects: All
gotchaWhen running on multi-core CPUs with BLAS/LAPACK libraries (like OpenBLAS, MKL), implicit threading can sometimes lead to oversubscription and performance degradation.
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.
affects: All
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'implicit'
The 'implicit' library is not installed in the current Python environment or the environment where the code is being run.
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).
AttributeError: module 'implicit' has no attribute 'als'
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.
fix
Import `AlternatingLeastSquares` specifically from `implicit.als`: `from implicit.als import AlternatingLeastSquares`.
ImportError: No module named 'implicit.cuda._cuda'
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.
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`.
ValueError: user_items must contain 1 row for every user in userids
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.
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.
AttributeError: 'implicit.evaluation._memoryviewslice' object has no attribute 'dtype'
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.
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.
Upgrade
Version history
0.7.3latest on PyPI · released May 8, 2026
Audit
Dependencies
numpyrequiredCore numerical operations and array handling.
scipyrequiredSparse matrix operations (e.g., csr_matrix) are fundamental inputs.
threadpoolctlrequiredUsed for detecting and controlling the number of threads used by BLAS/LAPACK libraries to prevent oversubscription.
cupyoptionalRequired for GPU acceleration with the 'gpu' extra. Requires a compatible CUDA Toolkit installation.
Agent activity
10 hits · last 30 days
node
10
Resources
implicit — pip install implicit · libregistry