Skip to content

Commit 7d66e30

Browse files
committed
Improved examples [skip ci]
1 parent 09253f9 commit 7d66e30

4 files changed

Lines changed: 12 additions & 12 deletions

File tree

examples/citus/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ publish = false
77
[dependencies]
88
pgvector = { path = "../..", features = ["postgres"] }
99
postgres = "0.19"
10-
rand = "0.8"
10+
rand = "0.9"
1111

1212
[profile.dev]
1313
opt-level = 1

examples/citus/src/main.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ fn main() -> Result<(), Box<dyn Error>> {
99
// generate random data
1010
let rows = 100000;
1111
let dimensions = 128;
12-
let mut rng = rand::thread_rng();
12+
let mut rng = rand::rng();
1313
let embeddings: Vec<Vec<f32>> = (0..rows)
14-
.map(|_| (0..dimensions).map(|_| rng.gen()).collect())
14+
.map(|_| (0..dimensions).map(|_| rng.random()).collect())
1515
.collect();
16-
let categories: Vec<i64> = (0..rows).map(|_| rng.gen_range(1..=100)).collect();
16+
let categories: Vec<i64> = (0..rows).map(|_| rng.random_range(1..=100)).collect();
1717
let queries: Vec<Vec<f32>> = (0..10)
18-
.map(|_| (0..dimensions).map(|_| rng.gen()).collect())
18+
.map(|_| (0..dimensions).map(|_| rng.random()).collect())
1919
.collect();
2020

2121
// enable extensions

examples/loading/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ publish = false
77
[dependencies]
88
pgvector = { path = "../..", features = ["postgres"] }
99
postgres = "0.19"
10-
rand = "0.8"
10+
rand = "0.9"
1111

1212
[profile.dev]
1313
opt-level = 1

examples/loading/src/main.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ fn main() -> Result<(), Box<dyn Error>> {
1010
// generate random data
1111
let rows = 1000000;
1212
let dimensions = 128;
13-
let mut rng = rand::thread_rng();
13+
let mut rng = rand::rng();
1414
let embeddings: Vec<Vec<f32>> = (0..rows)
15-
.map(|_| (0..dimensions).map(|_| rng.gen()).collect())
15+
.map(|_| (0..dimensions).map(|_| rng.random()).collect())
1616
.collect();
1717

1818
// enable extension
@@ -32,7 +32,7 @@ fn main() -> Result<(), Box<dyn Error>> {
3232

3333
// load data
3434
println!("Loading {} rows", embeddings.len());
35-
let vector_type = vector_type(&mut client)?;
35+
let vector_type = get_type(&mut client, "vector")?;
3636
let writer = client.copy_in("COPY items (embedding) FROM STDIN WITH (FORMAT BINARY)")?;
3737
let mut writer = BinaryCopyInWriter::new(writer, &[vector_type]);
3838
for (i, embedding) in embeddings.into_iter().enumerate() {
@@ -64,10 +64,10 @@ fn main() -> Result<(), Box<dyn Error>> {
6464
Ok(())
6565
}
6666

67-
fn vector_type(client: &mut Client) -> Result<Type, Box<dyn Error>> {
68-
let row = client.query_one("SELECT pg_type.oid, nspname AS schema FROM pg_type INNER JOIN pg_namespace ON pg_namespace.oid = pg_type.typnamespace WHERE typname = 'vector'", &[])?;
67+
fn get_type(client: &mut Client, name: &str) -> Result<Type, Box<dyn Error>> {
68+
let row = client.query_one("SELECT pg_type.oid, nspname AS schema FROM pg_type INNER JOIN pg_namespace ON pg_namespace.oid = pg_type.typnamespace WHERE typname = $1", &[&name])?;
6969
Ok(Type::new(
70-
"vector".into(),
70+
name.into(),
7171
row.get("oid"),
7272
Kind::Simple,
7373
row.get("schema"),

0 commit comments

Comments
 (0)