pgvector-rust
pgvector support for Rust
Supports Rust-Postgres and Diesel
Getting Started
Follow the instructions for your database library:
Rust-Postgres
Add this line to your application’s Cargo.toml
under [dependencies]
:
= { = "0.1", = ["postgres"] }
Create a vector from a Vec<f32>
let vec = from;
Insert a vector
client.execute?;
Get the nearest neighbor
let row = client.query_one?;
Retrieve a vector
let row = client.query_one?;
let vec: Vector = row.get;
Use Option
if the value could be NULL
let res: = row.get;
Convert a vector to a Vec<f32>
let f32_vec = vec.to_vec;
Diesel
Add this line to your application’s Cargo.toml
under [dependencies]
:
= { = "0.1", = ["diesel"], = false }
And add this line to your application’s diesel.toml
under [print_schema]
:
= ["diesel::sql_types::*", "pgvector::sql_types::*"]
Create a migration
with up.sql
:
CREATE EXTENSION vector
and down.sql
:
DROP EXTENSION vector
Run the migration
diesel migration run
You can now use the vector
type in future migrations
3)
)
(
factors VECTOR(
For models, use:
Create a vector from a Vec<f32>
let factors = from;
Insert a vector
let new_item = Item ;
insert_into
.values
.get_result
.expect
Convert a vector to a Vec<f32>
let f32_factors = factors.to_vec;
History
View the changelog
Contributing
Everyone is encouraged to help improve this project. Here are a few ways you can help:
- Report bugs
- Fix bugs and submit pull requests
- Write, clarify, or fix documentation
- Suggest or add new features
To get started with development: