{"id":15651049,"url":"https://github.com/ankane/disco-rust","last_synced_at":"2025-11-17T14:19:46.504Z","repository":{"id":46593519,"uuid":"433752010","full_name":"ankane/disco-rust","owner":"ankane","description":"Recommendations for Rust using collaborative filtering","archived":false,"fork":false,"pushed_at":"2025-03-15T17:44:49.000Z","size":60,"stargazers_count":41,"open_issues_count":1,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-31T11:01:38.093Z","etag":null,"topics":["recommendation-engine","recommender-system"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ankane.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-12-01T08:56:14.000Z","updated_at":"2025-03-19T10:26:39.000Z","dependencies_parsed_at":"2024-10-03T12:38:17.334Z","dependency_job_id":"17bff500-4ad9-4dfb-9bf9-503bcf5bc0e2","html_url":"https://github.com/ankane/disco-rust","commit_stats":{"total_commits":59,"total_committers":1,"mean_commits":59.0,"dds":0.0,"last_synced_commit":"40bd5083f9dca3d309cc83469db10bdf254c4494"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ankane%2Fdisco-rust","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ankane%2Fdisco-rust/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ankane%2Fdisco-rust/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ankane%2Fdisco-rust/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ankane","download_url":"https://codeload.github.com/ankane/disco-rust/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247648874,"owners_count":20972944,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["recommendation-engine","recommender-system"],"created_at":"2024-10-03T12:36:47.279Z","updated_at":"2025-11-17T14:19:46.485Z","avatar_url":"https://github.com/ankane.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Disco Rust\n\n🔥 Recommendations for Rust using collaborative filtering\n\n- Supports user-based and item-based recommendations\n- Works with explicit and implicit feedback\n- Uses high-performance matrix factorization\n\n🎉 Zero dependencies\n\n[![Build Status](https://github.com/ankane/disco-rust/actions/workflows/build.yml/badge.svg)](https://github.com/ankane/disco-rust/actions)\n\n## Installation\n\nAdd this line to your application’s `Cargo.toml` under `[dependencies]`:\n\n```toml\ndiscorec = \"0.2\"\n```\n\n## Getting Started\n\nPrep your data in the format `user_id, item_id, value`\n\n```rust\nuse discorec::{Dataset, Recommender};\n\nlet mut data = Dataset::new();\ndata.push(\"user_a\", \"item_a\", 5.0);\ndata.push(\"user_a\", \"item_b\", 3.5);\ndata.push(\"user_b\", \"item_a\", 4.0);\n```\n\nIDs can be integers, strings, or any other hashable data type\n\n```rust\ndata.push(1, \"item_a\".to_string(), 5.0);\n```\n\nIf users rate items directly, this is known as explicit feedback. Fit the recommender with:\n\n```rust\nlet recommender = Recommender::fit_explicit(\u0026data);\n```\n\nIf users don’t rate items directly (for instance, they’re purchasing items or reading posts), this is known as implicit feedback. Use `1.0` or a value like number of purchases or page views for the dataset, and fit the recommender with:\n\n```rust\nlet recommender = Recommender::fit_implicit(\u0026data);\n```\n\nGet user-based recommendations - “users like you also liked”\n\n```rust\nrecommender.user_recs(\u0026user_id, 5);\n```\n\nGet item-based recommendations - “users who liked this item also liked”\n\n```rust\nrecommender.item_recs(\u0026item_id, 5);\n```\n\nGet the predicted rating for a specific user and item\n\n```rust\nrecommender.predict(\u0026user_id, \u0026item_id);\n```\n\nGet similar users\n\n```rust\nrecommender.similar_users(\u0026user_id, 5);\n```\n\n## Examples\n\n### MovieLens\n\nDownload the [MovieLens 100K dataset](https://grouplens.org/datasets/movielens/100k/) and use:\n\n```rust\nuse discorec::{Dataset, RecommenderBuilder};\nuse std::fs::File;\nuse std::io::{BufRead, BufReader};\n\nfn main() {\n    let mut train_set = Dataset::with_capacity(80000);\n    let mut valid_set = Dataset::with_capacity(20000);\n\n    let file = File::open(\"path/to/ml-100k/u.data\").unwrap();\n    let rdr = BufReader::new(file);\n    for (i, line) in rdr.lines().enumerate() {\n        let line = line.unwrap();\n        let mut row = line.split('\\t');\n\n        let user_id: i32 = row.next().unwrap().parse().unwrap();\n        let item_id: i32 = row.next().unwrap().parse().unwrap();\n        let rating: f32 = row.next().unwrap().parse().unwrap();\n\n        let dataset = if i \u003c 80000 { \u0026mut train_set } else { \u0026mut valid_set };\n        dataset.push(user_id, item_id, rating);\n    }\n\n    let recommender = RecommenderBuilder::new()\n        .factors(20)\n        .fit_explicit(\u0026train_set);\n    println!(\"RMSE: {:?}\", recommender.rmse(\u0026valid_set));\n}\n```\n\n## Storing Recommendations\n\nSave recommendations to your database.\n\nAlternatively, you can store only the factors and use a library like [pgvector-rust](https://github.com/pgvector/pgvector-rust). See an [example](https://github.com/pgvector/pgvector-rust/blob/master/examples/disco/src/main.rs).\n\n## Algorithms\n\nDisco uses high-performance matrix factorization.\n\n- For explicit feedback, it uses the [stochastic gradient method with twin learners](https://www.csie.ntu.edu.tw/~cjlin/papers/libmf/mf_adaptive_pakdd.pdf)\n- For implicit feedback, it uses the [conjugate gradient method](https://www.benfrederickson.com/fast-implicit-matrix-factorization/)\n\nSpecify the number of factors and iterations\n\n```rust\nRecommenderBuilder::new()\n    .factors(8)\n    .iterations(20)\n    .fit_explicit(\u0026train_set);\n```\n\n## Progress\n\nPass a callback to show progress\n\n```rust\nRecommenderBuilder::new()\n    .callback(|info| println!(\"{:?}\", info))\n    .fit_explicit(\u0026train_set);\n```\n\nNote: `train_loss` and `valid_loss` are not available for implicit feedback\n\n## Validation\n\nPass a validation set with explicit feedback\n\n```rust\nRecommenderBuilder::new()\n    .callback(|info| println!(\"{:?}\", info))\n    .fit_eval_explicit(\u0026train_set, \u0026valid_set);\n```\n\nThe loss function is RMSE\n\n## Cold Start\n\nCollaborative filtering suffers from the [cold start problem](https://en.wikipedia.org/wiki/Cold_start_(recommender_systems)). It’s unable to make good recommendations without data on a user or item, which is problematic for new users and items.\n\n```rust\nrecommender.user_recs(\u0026new_user_id, 5); // returns empty array\n```\n\nThere are a number of ways to deal with this, but here are some common ones:\n\n- For user-based recommendations, show new users the most popular items\n- For item-based recommendations, make content-based recommendations\n\n## Reference\n\nGet ids\n\n```rust\nrecommender.user_ids();\nrecommender.item_ids();\n```\n\nGet the global mean\n\n```rust\nrecommender.global_mean();\n```\n\nGet factors\n\n```rust\nrecommender.user_factors(\u0026user_id);\nrecommender.item_factors(\u0026item_id);\n```\n\n## References\n\n- [A Learning-rate Schedule for Stochastic Gradient Methods to Matrix Factorization](https://www.csie.ntu.edu.tw/~cjlin/papers/libmf/mf_adaptive_pakdd.pdf)\n- [Faster Implicit Matrix Factorization](https://www.benfrederickson.com/fast-implicit-matrix-factorization/)\n\n## History\n\nView the [changelog](https://github.com/ankane/disco-rust/blob/master/CHANGELOG.md)\n\n## Contributing\n\nEveryone is encouraged to help improve this project. Here are a few ways you can help:\n\n- [Report bugs](https://github.com/ankane/disco-rust/issues)\n- Fix bugs and [submit pull requests](https://github.com/ankane/disco-rust/pulls)\n- Write, clarify, or fix documentation\n- Suggest or add new features\n\nTo get started with development:\n\n```sh\ngit clone https://github.com/ankane/disco-rust.git\ncd disco-rust\ncargo test\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fankane%2Fdisco-rust","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fankane%2Fdisco-rust","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fankane%2Fdisco-rust/lists"}