Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions examples/simple-rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ name = "sqlite-vec-demo"
edition = "2021"

[dependencies]
sqlite-vec={version="0.0.1-alpha.7"}
rusqlite = {version="0.31.0", features=["bundled"]}
zerocopy = "0.7.33"
sqlite-vec = "0.1.6"
rusqlite = { version = "0.37.0", features = ["bundled"] }
zerocopy = "0.8.27"

[[bin]]
name="demo"
path="demo.rs"
name = "demo"
path = "demo.rs"
2 changes: 1 addition & 1 deletion examples/simple-rust/demo.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use rusqlite::{ffi::sqlite3_auto_extension, Connection, Result};
use sqlite_vec::sqlite3_vec_init;
use zerocopy::AsBytes;
use zerocopy::IntoBytes;

fn main() -> Result<()> {
unsafe {
Expand Down
11 changes: 6 additions & 5 deletions site/using/rust.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ Then, you can verify your installation was successful by embedding your first ve
```rs
use sqlite_vec::sqlite3_vec_init;
use rusqlite::{ffi::sqlite3_auto_extension, Result};
use zerocopy::AsBytes;
use zerocopy::IntoBytes;

fn main()-> Result<()> {
fn main() -> Result<()> {
unsafe {
sqlite3_auto_extension(Some(std::mem::transmute(sqlite3_vec_init as *const ())));
}
Expand All @@ -40,7 +40,7 @@ fn main()-> Result<()> {
let v: Vec<f32> = vec![0.1, 0.2, 0.3];

let (vec_version, embedding): (String, String) = db.query_row(
"select vec_version(), vec_to_json(?)",
"SELECT vec_version(), vec_to_json(?)",
&[v.as_bytes()],
|x| Ok((x.get(0)?, x.get(1)?)),
)?;
Expand All @@ -56,10 +56,11 @@ for a more complete Rust demo.

## Working with vectors in Rust

If your vectors are provided as a `Vec<f32>` type, the [`zerocopy` crate](https://crates.io/crates/zerocopy) is recommended, specifically `zerocopy::AsBytes`. This will allow you to pass in vectors into `sqlite-vec` without any copying.
If your vectors are provided as a `Vec<f32>` type, the [`zerocopy` crate](https://crates.io/crates/zerocopy) is recommended, specifically `zerocopy::IntoBytes::as_bytes()`. This will allow you to pass in vectors into `sqlite-vec` without any copying.

```rs
let query: Vec<f32> = vec![0.1, 0.2, 0.3, 0.4];
let mut stmt = db.prepare("SELECT vec_length(?)")?;
stmt.execute(&[item.1.as_bytes()])?;
let len: usize = stmt.query_one(&[query.as_bytes()], |row| row.get(0))?;
println!("length={}", len);
```