Skip to content

Commit 0093baa

Browse files
committed
Updated Disco example [skip ci]
1 parent 5804516 commit 0093baa

2 files changed

Lines changed: 6 additions & 5 deletions

File tree

examples/disco/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ edition = "2021"
55
publish = false
66

77
[dependencies]
8-
discorec = "0.2"
8+
discorec = "0.3"
99
pgvector = { path = "../..", features = ["postgres"] }
1010
postgres = "0.19"
1111

examples/disco/src/main.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use discorec::{Dataset, RecommenderBuilder};
1+
use discorec::RecommenderBuilder;
22
use pgvector::Vector;
33
use postgres::{Client, NoTls};
44
use std::collections::HashMap;
@@ -66,7 +66,8 @@ fn main() -> Result<(), Box<dyn Error>> {
6666
Ok(())
6767
}
6868

69-
fn load_movielens(path: &Path) -> Result<Dataset<i32, String>, Box<dyn Error>> {
69+
#[allow(clippy::type_complexity)]
70+
fn load_movielens(path: &Path) -> Result<Vec<(i32, String, f32)>, Box<dyn Error>> {
7071
// read movies
7172
let mut movies = HashMap::with_capacity(2000);
7273
let movies_file = File::open(path.join("u.item"))?;
@@ -81,7 +82,7 @@ fn load_movielens(path: &Path) -> Result<Dataset<i32, String>, Box<dyn Error>> {
8182
}
8283

8384
// read ratings and create dataset
84-
let mut data = Dataset::with_capacity(100000);
85+
let mut data = Vec::with_capacity(100000);
8586
let ratings_file = File::open(path.join("u.data"))?;
8687
let rdr = BufReader::new(ratings_file);
8788
for line in rdr.lines() {
@@ -90,7 +91,7 @@ fn load_movielens(path: &Path) -> Result<Dataset<i32, String>, Box<dyn Error>> {
9091
let user_id = row.next().unwrap().parse()?;
9192
let item_id = movies.get(row.next().unwrap()).unwrap().to_string();
9293
let rating = row.next().unwrap().parse()?;
93-
data.push(user_id, item_id, rating);
94+
data.push((user_id, item_id, rating));
9495
}
9596

9697
Ok(data)

0 commit comments

Comments
 (0)