pgvector.rs

pgvector support for Rust

Supports the postgres crate

Build Status

Installation

Add this line your application’s Cargo.toml under [dependencies]:

toml pgvector = "0.1"

Getting Started

Create a vector from a Vec<f32>

rust let vec = pgvector::Vector::from(vec![1.0, 2.0, 3.0]);

Insert a vector

rust client.execute("INSERT INTO table (column) VALUES ($1)", &[&vec])?;

Get the nearest neighbor

rust let row = client.query_one("SELECT * FROM table ORDER BY column <-> $1 LIMIT 1", &[&vec])?;

Retrieve a vector

rust let row = client.query_one("SELECT column FROM table LIMIT 1", &[])?; let vec: pgvector::Vector = row.get(0);

Use Option if the value could be NULL

rust let res: Option<pgvector::Vector> = row.get(0);

Convert a vector to a Vec<f32>

rust let f32_vec = vec.to_vec();

History

View the changelog

Contributing

Everyone is encouraged to help improve this project. Here are a few ways you can help:

To get started with development:

sh git clone https://github.com/ankane/pgvector.rs.git cd pgvector.rs cargo test