Skip to content

Can I model a vector type using pgvector? #1041

Discussion options

You must be logged in to vote

I made it custom for now.

pg_vector.rs custom type file

use sea_orm_migration::sea_query::types::Iden;
use std::fmt;

// default vector size
pub const DEFAULT_VECTOR_SIZE: usize = 1536;

// define a vector type
pub type VectorEmbedding = Vec<f32>;

// SeaORM vector type definition
pub struct PGVectorType<const SIZE: usize>;

// implement Iden for SeaORM
impl<const SIZE: usize> Iden for PGVectorType<SIZE> {
    fn unquoted(&self, s: &mut dyn fmt::Write) {
        write!(s, "VECTOR({})", SIZE).unwrap(); // Dynamically set the dimension, default is 1536
    }
}

in the migrations file

                    .col(
                        ColumnDef::new(Chunks::Embedding)
                            

Replies: 3 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@Daniel-A-Gutierrez
Comment options

Answer selected by Daniel-A-Gutierrez
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants