diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 30307dd71..0236daaae 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -99,7 +99,7 @@ jobs: sudo apt-get -y install ruby-dev libarchive-tools sudo gem install --no-document fpm mkdir ./artifacts - cargo pgrx package + ./ci_package.sh if [[ "${{ matrix.arch }}" == "aarch64" ]]; then cargo build --target aarch64-unknown-linux-gnu --release --features "pg${{ matrix.version }}" --no-default-features mv ./target/aarch64-unknown-linux-gnu/release/libvectors.so ./target/release/vectors-pg${{ matrix.version }}/usr/lib/postgresql/${{ matrix.version }}/lib/vectors.so @@ -116,6 +116,8 @@ jobs: --package ../vectors-pg${{ matrix.version }}_${{ github.event.inputs.version }}_${{ matrix.platform }}.deb \ --architecture ${{ matrix.platform }} \ . + env: + VERSION: ${{ matrix.version }} - name: Upload Release uses: actions/upload-release-asset@v1 env: @@ -167,9 +169,9 @@ jobs: strategy: matrix: include: - - { version: 14, latest: false } - - { version: 15, latest: false } - - { version: 16, latest: true } + - { version: 14 } + - { version: 15 } + - { version: 16 } steps: - name: Checkout uses: actions/checkout@v3 diff --git a/README.md b/README.md index 246f04ffc..2be1f8204 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,7 @@ docker run \ --name pgvecto-rs-demo \ -e POSTGRES_PASSWORD=mysecretpassword \ -p 5432:5432 \ - -d tensorchord/pgvecto-rs:pg16-latest + -d tensorchord/pgvecto-rs:pg16-v0.1.13 ``` ## Development with envd diff --git a/crates/c/build.rs b/crates/c/build.rs index dad66331b..8d822e592 100644 --- a/crates/c/build.rs +++ b/crates/c/build.rs @@ -2,7 +2,7 @@ fn main() { println!("cargo:rerun-if-changed=src/c.h"); println!("cargo:rerun-if-changed=src/c.c"); cc::Build::new() - .compiler("/usr/bin/clang-16") + .compiler("clang-16") .file("./src/c.c") .opt_level(3) .debug(true) diff --git a/crates/c/src/lib.rs b/crates/c/src/lib.rs index 9c3d869be..9120e6607 100644 --- a/crates/c/src/lib.rs +++ b/crates/c/src/lib.rs @@ -1,5 +1,3 @@ -#![feature(linkage)] - mod c; #[allow(unused_imports)] diff --git a/crates/service/src/prelude/error.rs b/crates/service/src/prelude/error.rs index fbefffe71..19ccf092d 100644 --- a/crates/service/src/prelude/error.rs +++ b/crates/service/src/prelude/error.rs @@ -62,15 +62,29 @@ The given vector is invalid for input. ADVICE: Check if dimensions and scalar type of the vector is matched with the index.\ ")] Unmatched2, + #[error("\ +IPC connection is closed unexpected. +ADVICE: The error is raisen by background worker errors. \ +Please check the full PostgreSQL log to get more information.\ +")] + Ipc, + #[error("\ +The extension is upgraded. However, the index files is outdated. +ADVICE: Please read `https://github.com/tensorchord/pgvecto.rs/blob/main/docs/upgrade.md`.\ +")] + Upgrade, } -pub trait FriendlyErrorLike { - fn friendly(self) -> !; +pub trait FriendlyErrorLike: Sized { + fn convert(self) -> FriendlyError; + fn friendly(self) -> ! { + panic!("pgvecto.rs: {}", self.convert()); + } } impl FriendlyErrorLike for FriendlyError { - fn friendly(self) -> ! { - panic!("pgvecto.rs: {}", self); + fn convert(self) -> FriendlyError { + self } } diff --git a/crates/service/src/worker/metadata.rs b/crates/service/src/worker/metadata.rs new file mode 100644 index 000000000..e79f6cba4 --- /dev/null +++ b/crates/service/src/worker/metadata.rs @@ -0,0 +1,46 @@ +use serde::{Deserialize, Serialize}; +use std::error::Error; +use std::path::Path; +use thiserror::Error; + +#[derive(Debug, Error)] +pub enum MetadataError { + #[error("Invalid version.")] + InvalidVersion, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct Metadata { + #[serde(default)] + pub version: Option, + #[serde(default)] + pub soft_version: Option, +} + +impl Metadata { + const VERSION: u64 = 1; + const SOFT_VERSION: u64 = 1; +} + +impl Metadata { + pub fn write(path: impl AsRef) { + let metadata = Metadata { + version: Some(Self::VERSION), + soft_version: Some(Self::SOFT_VERSION), + }; + let contents = serde_json::to_string(&metadata).unwrap(); + std::fs::write(path, contents).unwrap(); + } + pub fn read(path: impl AsRef) -> Result<(), Box> { + use MetadataError::*; + let contents = std::fs::read_to_string(path)?; + let metadata = serde_json::from_str::(&contents)?; + if Self::VERSION != metadata.version.ok_or(InvalidVersion)? { + return Err(Box::new(InvalidVersion)); + } + if Self::SOFT_VERSION <= metadata.soft_version.ok_or(InvalidVersion)? { + return Err(Box::new(InvalidVersion)); + } + Ok(()) + } +} diff --git a/crates/service/src/worker/mod.rs b/crates/service/src/worker/mod.rs index 908a2841a..016799510 100644 --- a/crates/service/src/worker/mod.rs +++ b/crates/service/src/worker/mod.rs @@ -1,4 +1,5 @@ pub mod instance; +pub mod metadata; use self::instance::Instance; use crate::index::IndexOptions; @@ -16,14 +17,6 @@ use std::collections::HashMap; use std::path::PathBuf; use std::sync::Arc; -fn magic() -> &'static [u8] { - &[1, 4, 53, 23, 34, 92, 34, 23] -} - -fn check(data: &[u8]) -> bool { - magic() == data -} - pub struct Worker { path: PathBuf, protect: Mutex, @@ -33,7 +26,6 @@ pub struct Worker { impl Worker { pub fn create(path: PathBuf) -> Arc { std::fs::create_dir(&path).unwrap(); - std::fs::write(path.join("magic"), magic()).unwrap(); std::fs::create_dir(path.join("indexes")).unwrap(); let startup = FileAtomic::create(path.join("startup"), WorkerStartup::new()); let indexes = HashMap::new(); @@ -42,17 +34,18 @@ impl Worker { }); let protect = WorkerProtect { startup, indexes }; sync_dir(&path); + self::metadata::Metadata::write(path.join("metadata")); Arc::new(Worker { path, protect: Mutex::new(protect), view: ArcSwap::new(view), }) } + pub fn check(path: PathBuf) -> bool { + self::metadata::Metadata::read(path.join("metadata")).is_ok() + } pub fn open(path: PathBuf) -> Arc { let startup = FileAtomic::::open(path.join("startup")); - if !check(&std::fs::read(path.join("magic")).unwrap_or_default()) { - panic!("Please delete the directory pg_vectors in Postgresql data folder. The files are created by older versions of postgresql or broken."); - } clean( path.join("indexes"), startup.get().indexes.keys().map(|s| s.to_string()), diff --git a/docs/installation.md b/docs/installation.md index 49a9bd6e6..c71f8a36a 100644 --- a/docs/installation.md +++ b/docs/installation.md @@ -5,7 +5,7 @@ We have prebuild image at [tensorchord/pgvecto-rs](https://hub.docker.com/r/tensorchord/pgvecto-rs). You can try it with ``` -docker run --name pgvecto-rs-demo -e POSTGRES_PASSWORD=mysecretpassword -p 5432:5432 -d tensorchord/pgvecto-rs:pg16-latest +docker run --name pgvecto-rs-demo -e POSTGRES_PASSWORD=mysecretpassword -p 5432:5432 -d tensorchord/pgvecto-rs:pg16-v0.1.13 ``` Connect to the database and enable the extension. diff --git a/docs/upgrade.md b/docs/upgrade.md new file mode 100644 index 000000000..be42023c2 --- /dev/null +++ b/docs/upgrade.md @@ -0,0 +1,51 @@ +# Upgrade + +## `The extension is upgraded. However, the index files is outdated.` + +You may see this error if you upgrade the extension. On this condition, you should follow these steps: + +* Delete the old index folder. + +You can delete the folder with this command: + +```shell +rm -rf $(psql -U postgres -tAqX -c $'SELECT CONCAT(CURRENT_SETTING(\'data_directory\'), \'/pg_vectors\');') +``` + +If you are using Docker, you can just delete `pg_vectors` folder under the volume directory too. + +You need to restart PostgreSQL. + +* Reindex. + +You can list all indexes that needed to be reindexed with this command: + +```sql +SELECT + I.oid AS indexrelid, + I.relname AS indexname +FROM pg_index X + JOIN pg_class I ON I.oid = X.indexrelid + JOIN pg_am A ON A.oid = I.relam +WHERE A.amname = 'vectors'; +``` + +If you get the result like this: + +``` + indexrelid | indexname +------------+------------ + 17988 | t_val_idx + 17989 | t_val_idx1 + 17990 | t_val_idx2 + 17991 | t_val_idx3 +``` + +You will reindex them with this SQL: + +```sql +REINDEX INDEX t_val_idx; +REINDEX INDEX t_val_idx1; +REINDEX INDEX t_val_idx2; +REINDEX INDEX t_val_idx3; +``` diff --git a/scripts/ci_package.sh b/scripts/ci_package.sh new file mode 100755 index 000000000..5a46735c2 --- /dev/null +++ b/scripts/ci_package.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash +set -e + +cargo pgrx package diff --git a/sql/install/vectors--0.1.0.sql b/sql/install/vectors--0.1.0.sql new file mode 100644 index 000000000..14a653007 --- /dev/null +++ b/sql/install/vectors--0.1.0.sql @@ -0,0 +1,371 @@ +/* +This file is auto generated by pgrx. + +The ordering of items is not stable, it is driven by a dependency graph. +*/ + +-- src/lib.rs:24 +-- bootstrap +CREATE TYPE vector; + + +-- src/postgres/index.rs:639 +-- vectors::postgres::index::vectors_unload +CREATE FUNCTION "vectors_unload"( + "oid" oid /* pgrx_pg_sys::submodules::oids::Oid */ +) RETURNS void +STRICT +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'vectors_unload_wrapper'; + +-- src/postgres/index.rs:633 +-- vectors::postgres::index::vectors_load +CREATE FUNCTION "vectors_load"( + "oid" oid /* pgrx_pg_sys::submodules::oids::Oid */ +) RETURNS void +STRICT +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'vectors_load_wrapper'; + +-- src/postgres/datatype.rs:424 +-- vectors::postgres::datatype::vector_typmod_out +CREATE FUNCTION "vector_typmod_out"( + "typmod" INT /* i32 */ +) RETURNS cstring /* alloc::ffi::c_str::CString */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'vector_typmod_out_wrapper'; + +-- src/postgres/datatype.rs:411 +-- vectors::postgres::datatype::vector_typmod_in +CREATE FUNCTION "vector_typmod_in"( + "list" cstring[] /* pgrx::datum::array::Array<&core::ffi::c_str::CStr> */ +) RETURNS INT /* i32 */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'vector_typmod_in_wrapper'; + +-- src/postgres/datatype.rs:397 +-- vectors::postgres::datatype::vector_out +CREATE FUNCTION "vector_out"( + "vector" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS cstring /* alloc::ffi::c_str::CString */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'vector_out_wrapper'; + +-- src/postgres/datatype.rs:349 +-- vectors::postgres::datatype::vector_in +CREATE FUNCTION "vector_in"( + "input" cstring, /* &core::ffi::c_str::CStr */ + "_oid" oid, /* pgrx_pg_sys::submodules::oids::Oid */ + "typmod" INT /* i32 */ +) RETURNS vector /* vectors::postgres::datatype::VectorOutput */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'vector_in_wrapper'; + +-- src/udf.rs:9 +-- vectors::udf::ai_embedding_vector +CREATE FUNCTION "ai_embedding_vector"( + "input" TEXT /* alloc::string::String */ +) RETURNS double precision[] /* alloc::vec::Vec */ +STRICT +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'ai_embedding_vector_wrapper'; + +-- src/postgres/datatype.rs:73 +-- creates: +-- Type(vectors::postgres::datatype::Vector) + +-- requires: +-- vector_in +-- vector_out +-- vector_typmod_in +-- vector_typmod_out + + +CREATE TYPE vector ( + INPUT = vector_in, + OUTPUT = vector_out, + TYPMOD_IN = vector_typmod_in, + TYPMOD_OUT = vector_typmod_out, + STORAGE = EXTENDED, + INTERNALLENGTH = VARIABLE, + ALIGNMENT = double +); + + +-- src/postgres/datatype.rs:485 +-- vectors::postgres::datatype::operator_gt +-- requires: +-- vector +CREATE FUNCTION "operator_gt"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS bool /* bool */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_gt_wrapper'; + +-- src/postgres/datatype.rs:485 +-- vectors::postgres::datatype::operator_gt +CREATE OPERATOR > ( + PROCEDURE="operator_gt", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector, /* vectors::postgres::datatype::VectorInput */ + COMMUTATOR = <, + NEGATOR = <=, + RESTRICT = scalargtsel, + JOIN = scalargtjoinsel +); + +-- src/postgres/datatype.rs:463 +-- vectors::postgres::datatype::operator_lt +-- requires: +-- vector +CREATE FUNCTION "operator_lt"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS bool /* bool */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_lt_wrapper'; + +-- src/postgres/datatype.rs:463 +-- vectors::postgres::datatype::operator_lt +CREATE OPERATOR < ( + PROCEDURE="operator_lt", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector, /* vectors::postgres::datatype::VectorInput */ + COMMUTATOR = >, + NEGATOR = >=, + RESTRICT = scalarltsel, + JOIN = scalarltjoinsel +); + +-- src/postgres/datatype.rs:534 +-- vectors::postgres::datatype::operator_dot +-- requires: +-- vector +CREATE FUNCTION "operator_dot"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS real /* vectors::utils::scalar::Scalar */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_dot_wrapper'; + +-- src/postgres/datatype.rs:534 +-- vectors::postgres::datatype::operator_dot +CREATE OPERATOR <#> ( + PROCEDURE="operator_dot", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector, /* vectors::postgres::datatype::VectorInput */ + COMMUTATOR = <#> +); + +-- src/postgres/datatype.rs:518 +-- vectors::postgres::datatype::operator_neq +-- requires: +-- vector +CREATE FUNCTION "operator_neq"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS bool /* bool */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_neq_wrapper'; + +-- src/postgres/datatype.rs:518 +-- vectors::postgres::datatype::operator_neq +CREATE OPERATOR <> ( + PROCEDURE="operator_neq", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector, /* vectors::postgres::datatype::VectorInput */ + COMMUTATOR = <>, + NEGATOR = =, + RESTRICT = eqsel, + JOIN = eqjoinsel +); + +-- src/postgres/datatype.rs:496 +-- vectors::postgres::datatype::operator_gte +-- requires: +-- vector +CREATE FUNCTION "operator_gte"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS bool /* bool */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_gte_wrapper'; + +-- src/postgres/datatype.rs:496 +-- vectors::postgres::datatype::operator_gte +CREATE OPERATOR >= ( + PROCEDURE="operator_gte", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector, /* vectors::postgres::datatype::VectorInput */ + COMMUTATOR = <=, + NEGATOR = <, + RESTRICT = scalargtsel, + JOIN = scalargtjoinsel +); + +-- src/postgres/datatype.rs:542 +-- vectors::postgres::datatype::operator_l2 +-- requires: +-- vector +CREATE FUNCTION "operator_l2"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS real /* vectors::utils::scalar::Scalar */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_l2_wrapper'; + +-- src/postgres/datatype.rs:542 +-- vectors::postgres::datatype::operator_l2 +CREATE OPERATOR <-> ( + PROCEDURE="operator_l2", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector, /* vectors::postgres::datatype::VectorInput */ + COMMUTATOR = <-> +); + +-- src/postgres/index.rs:87 +-- vectors::postgres::index::vectors_amhandler + + CREATE OR REPLACE FUNCTION vectors_amhandler(internal) RETURNS index_am_handler + PARALLEL SAFE IMMUTABLE STRICT LANGUAGE c AS 'MODULE_PATHNAME', 'vectors_amhandler_wrapper'; + CREATE ACCESS METHOD vectors TYPE INDEX HANDLER vectors_amhandler; + COMMENT ON ACCESS METHOD vectors IS 'pgvecto.rs index access method'; + + + + +-- src/postgres/datatype.rs:435 +-- vectors::postgres::datatype::operator_add +-- requires: +-- vector +CREATE FUNCTION "operator_add"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS vector /* vectors::postgres::datatype::VectorOutput */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_add_wrapper'; + +-- src/postgres/datatype.rs:435 +-- vectors::postgres::datatype::operator_add +CREATE OPERATOR + ( + PROCEDURE="operator_add", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector, /* vectors::postgres::datatype::VectorInput */ + COMMUTATOR = + +); + +-- src/postgres/datatype.rs:507 +-- vectors::postgres::datatype::operator_eq +-- requires: +-- vector +CREATE FUNCTION "operator_eq"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS bool /* bool */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_eq_wrapper'; + +-- src/postgres/datatype.rs:507 +-- vectors::postgres::datatype::operator_eq +CREATE OPERATOR = ( + PROCEDURE="operator_eq", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector, /* vectors::postgres::datatype::VectorInput */ + COMMUTATOR = =, + NEGATOR = <>, + RESTRICT = eqsel, + JOIN = eqjoinsel +); + +-- src/postgres/datatype.rs:447 +-- vectors::postgres::datatype::operator_minus +-- requires: +-- vector +CREATE FUNCTION "operator_minus"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS vector /* vectors::postgres::datatype::VectorOutput */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_minus_wrapper'; + +-- src/postgres/datatype.rs:447 +-- vectors::postgres::datatype::operator_minus +CREATE OPERATOR - ( + PROCEDURE="operator_minus", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector /* vectors::postgres::datatype::VectorInput */ +); + +-- src/postgres/datatype.rs:474 +-- vectors::postgres::datatype::operator_lte +-- requires: +-- vector +CREATE FUNCTION "operator_lte"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS bool /* bool */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_lte_wrapper'; + +-- src/postgres/datatype.rs:474 +-- vectors::postgres::datatype::operator_lte +CREATE OPERATOR <= ( + PROCEDURE="operator_lte", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector, /* vectors::postgres::datatype::VectorInput */ + COMMUTATOR = >=, + NEGATOR = >, + RESTRICT = scalarltsel, + JOIN = scalarltjoinsel +); + +-- src/postgres/datatype.rs:526 +-- vectors::postgres::datatype::operator_cosine +-- requires: +-- vector +CREATE FUNCTION "operator_cosine"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS real /* vectors::utils::scalar::Scalar */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_cosine_wrapper'; + +-- src/postgres/datatype.rs:526 +-- vectors::postgres::datatype::operator_cosine +CREATE OPERATOR <=> ( + PROCEDURE="operator_cosine", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector, /* vectors::postgres::datatype::VectorInput */ + COMMUTATOR = <=> +); + +-- src/lib.rs:25 +-- finalize +CREATE OPERATOR CLASS l2_ops + FOR TYPE vector USING vectors AS + OPERATOR 1 <-> (vector, vector) FOR ORDER BY float_ops; + +CREATE OPERATOR CLASS dot_ops + FOR TYPE vector USING vectors AS + OPERATOR 1 <#> (vector, vector) FOR ORDER BY float_ops; + +CREATE OPERATOR CLASS cosine_ops + FOR TYPE vector USING vectors AS + OPERATOR 1 <=> (vector, vector) FOR ORDER BY float_ops; + diff --git a/sql/install/vectors--0.1.1.sql b/sql/install/vectors--0.1.1.sql new file mode 100644 index 000000000..3ff588dfd --- /dev/null +++ b/sql/install/vectors--0.1.1.sql @@ -0,0 +1,399 @@ +/* +This file is auto generated by pgrx. + +The ordering of items is not stable, it is driven by a dependency graph. +*/ + +-- src/lib.rs:25 +-- bootstrap +CREATE TYPE vector; + + +-- src/postgres/functions.rs:14 +-- vectors::postgres::functions::vectors_unload +CREATE FUNCTION "vectors_unload"( + "oid" oid /* pgrx_pg_sys::submodules::oids::Oid */ +) RETURNS void +STRICT +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'vectors_unload_wrapper'; + +-- src/postgres/functions.rs:5 +-- vectors::postgres::functions::vectors_load +CREATE FUNCTION "vectors_load"( + "oid" oid /* pgrx_pg_sys::submodules::oids::Oid */ +) RETURNS void +STRICT +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'vectors_load_wrapper'; + +-- src/postgres/datatype.rs:424 +-- vectors::postgres::datatype::vector_typmod_out +CREATE FUNCTION "vector_typmod_out"( + "typmod" INT /* i32 */ +) RETURNS cstring /* alloc::ffi::c_str::CString */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'vector_typmod_out_wrapper'; + +-- src/postgres/datatype.rs:411 +-- vectors::postgres::datatype::vector_typmod_in +CREATE FUNCTION "vector_typmod_in"( + "list" cstring[] /* pgrx::datum::array::Array<&core::ffi::c_str::CStr> */ +) RETURNS INT /* i32 */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'vector_typmod_in_wrapper'; + +-- src/postgres/datatype.rs:397 +-- vectors::postgres::datatype::vector_out +CREATE FUNCTION "vector_out"( + "vector" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS cstring /* alloc::ffi::c_str::CString */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'vector_out_wrapper'; + +-- src/postgres/datatype.rs:349 +-- vectors::postgres::datatype::vector_in +CREATE FUNCTION "vector_in"( + "input" cstring, /* &core::ffi::c_str::CStr */ + "_oid" oid, /* pgrx_pg_sys::submodules::oids::Oid */ + "typmod" INT /* i32 */ +) RETURNS vector /* vectors::postgres::datatype::VectorOutput */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'vector_in_wrapper'; + +-- src/postgres/casts.rs:17 +-- vectors::postgres::casts::cast_vector_to_array +CREATE FUNCTION "cast_vector_to_array"( + "vector" vector, /* vectors::postgres::datatype::VectorInput */ + "_typmod" INT, /* i32 */ + "_explicit" bool /* bool */ +) RETURNS real[] /* alloc::vec::Vec */ +STRICT +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'cast_vector_to_array_wrapper'; + +-- src/postgres/casts.rs:5 +-- vectors::postgres::casts::cast_array_to_vector +CREATE FUNCTION "cast_array_to_vector"( + "array" real[], /* pgrx::datum::array::Array */ + "typmod" INT, /* i32 */ + "_explicit" bool /* bool */ +) RETURNS vector /* vectors::postgres::datatype::VectorOutput */ +STRICT +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'cast_array_to_vector_wrapper'; + +-- src/embedding/udf.rs:11 +-- vectors::embedding::udf::ai_embedding_vector +CREATE FUNCTION "ai_embedding_vector"( + "input" TEXT /* alloc::string::String */ +) RETURNS vector /* vectors::postgres::datatype::VectorOutput */ +STRICT +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'ai_embedding_vector_wrapper'; + +-- src/postgres/datatype.rs:73 +-- creates: +-- Type(vectors::postgres::datatype::Vector) + +-- requires: +-- vector_in +-- vector_out +-- vector_typmod_in +-- vector_typmod_out + + +CREATE TYPE vector ( + INPUT = vector_in, + OUTPUT = vector_out, + TYPMOD_IN = vector_typmod_in, + TYPMOD_OUT = vector_typmod_out, + STORAGE = EXTENDED, + INTERNALLENGTH = VARIABLE, + ALIGNMENT = double +); + + +-- src/postgres/index.rs:34 +-- vectors::postgres::index::vectors_amhandler + + CREATE OR REPLACE FUNCTION vectors_amhandler(internal) RETURNS index_am_handler + PARALLEL SAFE IMMUTABLE STRICT LANGUAGE c AS 'MODULE_PATHNAME', 'vectors_amhandler_wrapper'; + CREATE ACCESS METHOD vectors TYPE INDEX HANDLER vectors_amhandler; + COMMENT ON ACCESS METHOD vectors IS 'pgvecto.rs index access method'; + + + + +-- src/postgres/operators.rs:80 +-- vectors::postgres::operators::operator_eq +-- requires: +-- vector +CREATE FUNCTION "operator_eq"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS bool /* bool */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_eq_wrapper'; + +-- src/postgres/operators.rs:80 +-- vectors::postgres::operators::operator_eq +CREATE OPERATOR = ( + PROCEDURE="operator_eq", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector, /* vectors::postgres::datatype::VectorInput */ + COMMUTATOR = =, + NEGATOR = <>, + RESTRICT = eqsel, + JOIN = eqjoinsel +); + +-- src/postgres/operators.rs:47 +-- vectors::postgres::operators::operator_lte +-- requires: +-- vector +CREATE FUNCTION "operator_lte"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS bool /* bool */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_lte_wrapper'; + +-- src/postgres/operators.rs:47 +-- vectors::postgres::operators::operator_lte +CREATE OPERATOR <= ( + PROCEDURE="operator_lte", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector, /* vectors::postgres::datatype::VectorInput */ + COMMUTATOR = >=, + NEGATOR = >, + RESTRICT = scalarltsel, + JOIN = scalarltjoinsel +); + +-- src/postgres/operators.rs:69 +-- vectors::postgres::operators::operator_gte +-- requires: +-- vector +CREATE FUNCTION "operator_gte"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS bool /* bool */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_gte_wrapper'; + +-- src/postgres/operators.rs:69 +-- vectors::postgres::operators::operator_gte +CREATE OPERATOR >= ( + PROCEDURE="operator_gte", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector, /* vectors::postgres::datatype::VectorInput */ + COMMUTATOR = <=, + NEGATOR = <, + RESTRICT = scalargtsel, + JOIN = scalargtjoinsel +); + +-- src/postgres/operators.rs:58 +-- vectors::postgres::operators::operator_gt +-- requires: +-- vector +CREATE FUNCTION "operator_gt"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS bool /* bool */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_gt_wrapper'; + +-- src/postgres/operators.rs:58 +-- vectors::postgres::operators::operator_gt +CREATE OPERATOR > ( + PROCEDURE="operator_gt", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector, /* vectors::postgres::datatype::VectorInput */ + COMMUTATOR = <, + NEGATOR = <=, + RESTRICT = scalargtsel, + JOIN = scalargtjoinsel +); + +-- src/postgres/operators.rs:36 +-- vectors::postgres::operators::operator_lt +-- requires: +-- vector +CREATE FUNCTION "operator_lt"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS bool /* bool */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_lt_wrapper'; + +-- src/postgres/operators.rs:36 +-- vectors::postgres::operators::operator_lt +CREATE OPERATOR < ( + PROCEDURE="operator_lt", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector, /* vectors::postgres::datatype::VectorInput */ + COMMUTATOR = >, + NEGATOR = >=, + RESTRICT = scalarltsel, + JOIN = scalarltjoinsel +); + +-- src/postgres/operators.rs:8 +-- vectors::postgres::operators::operator_add +-- requires: +-- vector +CREATE FUNCTION "operator_add"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS vector /* vectors::postgres::datatype::VectorOutput */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_add_wrapper'; + +-- src/postgres/operators.rs:8 +-- vectors::postgres::operators::operator_add +CREATE OPERATOR + ( + PROCEDURE="operator_add", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector, /* vectors::postgres::datatype::VectorInput */ + COMMUTATOR = + +); + +-- src/postgres/operators.rs:115 +-- vectors::postgres::operators::operator_l2 +-- requires: +-- vector +CREATE FUNCTION "operator_l2"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS real /* vectors::prelude::scalar::Scalar */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_l2_wrapper'; + +-- src/postgres/operators.rs:115 +-- vectors::postgres::operators::operator_l2 +CREATE OPERATOR <-> ( + PROCEDURE="operator_l2", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector, /* vectors::postgres::datatype::VectorInput */ + COMMUTATOR = <-> +); + +-- src/postgres/operators.rs:107 +-- vectors::postgres::operators::operator_dot +-- requires: +-- vector +CREATE FUNCTION "operator_dot"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS real /* vectors::prelude::scalar::Scalar */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_dot_wrapper'; + +-- src/postgres/operators.rs:107 +-- vectors::postgres::operators::operator_dot +CREATE OPERATOR <#> ( + PROCEDURE="operator_dot", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector, /* vectors::postgres::datatype::VectorInput */ + COMMUTATOR = <#> +); + +-- src/postgres/operators.rs:99 +-- vectors::postgres::operators::operator_cosine +-- requires: +-- vector +CREATE FUNCTION "operator_cosine"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS real /* vectors::prelude::scalar::Scalar */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_cosine_wrapper'; + +-- src/postgres/operators.rs:99 +-- vectors::postgres::operators::operator_cosine +CREATE OPERATOR <=> ( + PROCEDURE="operator_cosine", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector, /* vectors::postgres::datatype::VectorInput */ + COMMUTATOR = <=> +); + +-- src/postgres/operators.rs:91 +-- vectors::postgres::operators::operator_neq +-- requires: +-- vector +CREATE FUNCTION "operator_neq"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS bool /* bool */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_neq_wrapper'; + +-- src/postgres/operators.rs:91 +-- vectors::postgres::operators::operator_neq +CREATE OPERATOR <> ( + PROCEDURE="operator_neq", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector, /* vectors::postgres::datatype::VectorInput */ + COMMUTATOR = <>, + NEGATOR = =, + RESTRICT = eqsel, + JOIN = eqjoinsel +); + +-- src/postgres/operators.rs:20 +-- vectors::postgres::operators::operator_minus +-- requires: +-- vector +CREATE FUNCTION "operator_minus"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS vector /* vectors::postgres::datatype::VectorOutput */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_minus_wrapper'; + +-- src/postgres/operators.rs:20 +-- vectors::postgres::operators::operator_minus +CREATE OPERATOR - ( + PROCEDURE="operator_minus", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector /* vectors::postgres::datatype::VectorInput */ +); + +-- src/lib.rs:26 +-- finalize +CREATE CAST (real[] AS vector) + WITH FUNCTION cast_array_to_vector(real[], integer, boolean) AS IMPLICIT; + +CREATE CAST (vector AS real[]) + WITH FUNCTION cast_vector_to_array(vector, integer, boolean) AS IMPLICIT; + +CREATE OPERATOR CLASS l2_ops + FOR TYPE vector USING vectors AS + OPERATOR 1 <-> (vector, vector) FOR ORDER BY float_ops; + +CREATE OPERATOR CLASS dot_ops + FOR TYPE vector USING vectors AS + OPERATOR 1 <#> (vector, vector) FOR ORDER BY float_ops; + +CREATE OPERATOR CLASS cosine_ops + FOR TYPE vector USING vectors AS + OPERATOR 1 <=> (vector, vector) FOR ORDER BY float_ops; + diff --git a/sql/install/vectors--0.1.10.sql b/sql/install/vectors--0.1.10.sql new file mode 100644 index 000000000..3a50d5442 --- /dev/null +++ b/sql/install/vectors--0.1.10.sql @@ -0,0 +1,381 @@ +/* +This file is auto generated by pgrx. + +The ordering of items is not stable, it is driven by a dependency graph. +*/ + +-- src/lib.rs:16 +-- bootstrap +CREATE TYPE vector; + + +-- src/postgres/datatype.rs:450 +-- vectors::postgres::datatype::vector_typmod_out +CREATE FUNCTION "vector_typmod_out"( + "typmod" INT /* i32 */ +) RETURNS cstring /* alloc::ffi::c_str::CString */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'vector_typmod_out_wrapper'; + +-- src/postgres/datatype.rs:435 +-- vectors::postgres::datatype::vector_typmod_in +CREATE FUNCTION "vector_typmod_in"( + "list" cstring[] /* pgrx::datum::array::Array<&core::ffi::c_str::CStr> */ +) RETURNS INT /* i32 */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'vector_typmod_in_wrapper'; + +-- src/postgres/datatype.rs:421 +-- vectors::postgres::datatype::vector_out +CREATE FUNCTION "vector_out"( + "vector" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS cstring /* alloc::ffi::c_str::CString */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'vector_out_wrapper'; + +-- src/postgres/datatype.rs:348 +-- vectors::postgres::datatype::vector_in +CREATE FUNCTION "vector_in"( + "input" cstring, /* &core::ffi::c_str::CStr */ + "_oid" oid, /* pgrx_pg_sys::submodules::oids::Oid */ + "typmod" INT /* i32 */ +) RETURNS vector /* vectors::postgres::datatype::VectorOutput */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'vector_in_wrapper'; + +-- src/postgres/casts.rs:19 +-- vectors::postgres::casts::cast_vector_to_array +CREATE FUNCTION "cast_vector_to_array"( + "vector" vector, /* vectors::postgres::datatype::VectorInput */ + "_typmod" INT, /* i32 */ + "_explicit" bool /* bool */ +) RETURNS real[] /* alloc::vec::Vec */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'cast_vector_to_array_wrapper'; + +-- src/postgres/casts.rs:5 +-- vectors::postgres::casts::cast_array_to_vector +CREATE FUNCTION "cast_array_to_vector"( + "array" real[], /* pgrx::datum::array::Array */ + "typmod" INT, /* i32 */ + "_explicit" bool /* bool */ +) RETURNS vector /* vectors::postgres::datatype::VectorOutput */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'cast_array_to_vector_wrapper'; + +-- src/embedding/udf.rs:11 +-- vectors::embedding::udf::ai_embedding_vector +CREATE FUNCTION "ai_embedding_vector"( + "input" TEXT /* alloc::string::String */ +) RETURNS vector /* vectors::postgres::datatype::VectorOutput */ +STRICT +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'ai_embedding_vector_wrapper'; + +-- src/postgres/datatype.rs:72 +-- creates: +-- Type(vectors::postgres::datatype::Vector) + +-- requires: +-- vector_in +-- vector_out +-- vector_typmod_in +-- vector_typmod_out + + +CREATE TYPE vector ( + INPUT = vector_in, + OUTPUT = vector_out, + TYPMOD_IN = vector_typmod_in, + TYPMOD_OUT = vector_typmod_out, + STORAGE = EXTENDED, + INTERNALLENGTH = VARIABLE, + ALIGNMENT = double +); + + +-- src/postgres/operators.rs:82 +-- vectors::postgres::operators::operator_gt +-- requires: +-- vector +CREATE FUNCTION "operator_gt"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS bool /* bool */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_gt_wrapper'; + +-- src/postgres/operators.rs:82 +-- vectors::postgres::operators::operator_gt +CREATE OPERATOR > ( + PROCEDURE="operator_gt", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector, /* vectors::postgres::datatype::VectorInput */ + COMMUTATOR = <, + NEGATOR = <=, + RESTRICT = scalargtsel, + JOIN = scalargtjoinsel +); + +-- src/postgres/operators.rs:161 +-- vectors::postgres::operators::operator_dot +-- requires: +-- vector +CREATE FUNCTION "operator_dot"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS real /* vectors::prelude::scalar::Scalar */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_dot_wrapper'; + +-- src/postgres/operators.rs:161 +-- vectors::postgres::operators::operator_dot +CREATE OPERATOR <#> ( + PROCEDURE="operator_dot", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector, /* vectors::postgres::datatype::VectorInput */ + COMMUTATOR = <#> +); + +-- src/postgres/operators.rs:8 +-- vectors::postgres::operators::operator_add +-- requires: +-- vector +CREATE FUNCTION "operator_add"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS vector /* vectors::postgres::datatype::VectorOutput */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_add_wrapper'; + +-- src/postgres/operators.rs:8 +-- vectors::postgres::operators::operator_add +CREATE OPERATOR + ( + PROCEDURE="operator_add", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector, /* vectors::postgres::datatype::VectorInput */ + COMMUTATOR = + +); + +-- src/postgres/operators.rs:26 +-- vectors::postgres::operators::operator_minus +-- requires: +-- vector +CREATE FUNCTION "operator_minus"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS vector /* vectors::postgres::datatype::VectorOutput */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_minus_wrapper'; + +-- src/postgres/operators.rs:26 +-- vectors::postgres::operators::operator_minus +CREATE OPERATOR - ( + PROCEDURE="operator_minus", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector /* vectors::postgres::datatype::VectorInput */ +); + +-- src/postgres/operators.rs:65 +-- vectors::postgres::operators::operator_lte +-- requires: +-- vector +CREATE FUNCTION "operator_lte"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS bool /* bool */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_lte_wrapper'; + +-- src/postgres/operators.rs:65 +-- vectors::postgres::operators::operator_lte +CREATE OPERATOR <= ( + PROCEDURE="operator_lte", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector, /* vectors::postgres::datatype::VectorInput */ + COMMUTATOR = >=, + NEGATOR = >, + RESTRICT = scalarltsel, + JOIN = scalarltjoinsel +); + +-- src/postgres/operators.rs:147 +-- vectors::postgres::operators::operator_cosine +-- requires: +-- vector +CREATE FUNCTION "operator_cosine"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS real /* vectors::prelude::scalar::Scalar */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_cosine_wrapper'; + +-- src/postgres/operators.rs:147 +-- vectors::postgres::operators::operator_cosine +CREATE OPERATOR <=> ( + PROCEDURE="operator_cosine", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector, /* vectors::postgres::datatype::VectorInput */ + COMMUTATOR = <=> +); + +-- src/postgres/operators.rs:99 +-- vectors::postgres::operators::operator_gte +-- requires: +-- vector +CREATE FUNCTION "operator_gte"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS bool /* bool */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_gte_wrapper'; + +-- src/postgres/operators.rs:99 +-- vectors::postgres::operators::operator_gte +CREATE OPERATOR >= ( + PROCEDURE="operator_gte", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector, /* vectors::postgres::datatype::VectorInput */ + COMMUTATOR = <=, + NEGATOR = <, + RESTRICT = scalargtsel, + JOIN = scalargtjoinsel +); + +-- src/postgres/operators.rs:133 +-- vectors::postgres::operators::operator_neq +-- requires: +-- vector +CREATE FUNCTION "operator_neq"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS bool /* bool */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_neq_wrapper'; + +-- src/postgres/operators.rs:133 +-- vectors::postgres::operators::operator_neq +CREATE OPERATOR <> ( + PROCEDURE="operator_neq", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector, /* vectors::postgres::datatype::VectorInput */ + COMMUTATOR = <>, + NEGATOR = =, + RESTRICT = eqsel, + JOIN = eqjoinsel +); + +-- src/postgres/operators.rs:175 +-- vectors::postgres::operators::operator_l2 +-- requires: +-- vector +CREATE FUNCTION "operator_l2"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS real /* vectors::prelude::scalar::Scalar */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_l2_wrapper'; + +-- src/postgres/operators.rs:175 +-- vectors::postgres::operators::operator_l2 +CREATE OPERATOR <-> ( + PROCEDURE="operator_l2", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector, /* vectors::postgres::datatype::VectorInput */ + COMMUTATOR = <-> +); + +-- src/postgres/operators.rs:48 +-- vectors::postgres::operators::operator_lt +-- requires: +-- vector +CREATE FUNCTION "operator_lt"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS bool /* bool */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_lt_wrapper'; + +-- src/postgres/operators.rs:48 +-- vectors::postgres::operators::operator_lt +CREATE OPERATOR < ( + PROCEDURE="operator_lt", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector, /* vectors::postgres::datatype::VectorInput */ + COMMUTATOR = >, + NEGATOR = >=, + RESTRICT = scalarltsel, + JOIN = scalarltjoinsel +); + +-- src/postgres/operators.rs:116 +-- vectors::postgres::operators::operator_eq +-- requires: +-- vector +CREATE FUNCTION "operator_eq"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS bool /* bool */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_eq_wrapper'; + +-- src/postgres/operators.rs:116 +-- vectors::postgres::operators::operator_eq +CREATE OPERATOR = ( + PROCEDURE="operator_eq", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector, /* vectors::postgres::datatype::VectorInput */ + COMMUTATOR = =, + NEGATOR = <>, + RESTRICT = eqsel, + JOIN = eqjoinsel +); + +-- src/postgres/index.rs:34 +-- vectors::postgres::index::vectors_amhandler + + CREATE OR REPLACE FUNCTION vectors_amhandler(internal) RETURNS index_am_handler + PARALLEL SAFE IMMUTABLE STRICT LANGUAGE c AS 'MODULE_PATHNAME', 'vectors_amhandler_wrapper'; + CREATE ACCESS METHOD vectors TYPE INDEX HANDLER vectors_amhandler; + COMMENT ON ACCESS METHOD vectors IS 'pgvecto.rs index access method'; + + + + +-- src/lib.rs:17 +-- finalize +CREATE CAST (real[] AS vector) + WITH FUNCTION cast_array_to_vector(real[], integer, boolean) AS IMPLICIT; + +CREATE CAST (vector AS real[]) + WITH FUNCTION cast_vector_to_array(vector, integer, boolean) AS IMPLICIT; + +CREATE OPERATOR CLASS l2_ops + FOR TYPE vector USING vectors AS + OPERATOR 1 <-> (vector, vector) FOR ORDER BY float_ops; + +CREATE OPERATOR CLASS dot_ops + FOR TYPE vector USING vectors AS + OPERATOR 1 <#> (vector, vector) FOR ORDER BY float_ops; + +CREATE OPERATOR CLASS cosine_ops + FOR TYPE vector USING vectors AS + OPERATOR 1 <=> (vector, vector) FOR ORDER BY float_ops; + diff --git a/sql/install/vectors--0.1.11.sql b/sql/install/vectors--0.1.11.sql new file mode 100644 index 000000000..e673ab145 --- /dev/null +++ b/sql/install/vectors--0.1.11.sql @@ -0,0 +1,414 @@ +/* +This file is auto generated by pgrx. + +The ordering of items is not stable, it is driven by a dependency graph. +*/ + +-- src/lib.rs:16 +-- bootstrap +CREATE TYPE vector; + + +-- src/postgres/datatype.rs:450 +-- vectors::postgres::datatype::vector_typmod_out +CREATE FUNCTION "vector_typmod_out"( + "typmod" INT /* i32 */ +) RETURNS cstring /* alloc::ffi::c_str::CString */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'vector_typmod_out_wrapper'; + +-- src/postgres/datatype.rs:435 +-- vectors::postgres::datatype::vector_typmod_in +CREATE FUNCTION "vector_typmod_in"( + "list" cstring[] /* pgrx::datum::array::Array<&core::ffi::c_str::CStr> */ +) RETURNS INT /* i32 */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'vector_typmod_in_wrapper'; + +-- src/postgres/stat.rs:20 +-- vectors::postgres::stat::vector_stat +CREATE FUNCTION "vector_stat"( + "oid" oid /* pgrx_pg_sys::submodules::oids::Oid */ +) RETURNS VectorIndexInfo /* pgrx::heap_tuple::PgHeapTuple */ +STRICT VOLATILE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'vector_stat_wrapper'; + +-- src/postgres/datatype.rs:421 +-- vectors::postgres::datatype::vector_out +CREATE FUNCTION "vector_out"( + "vector" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS cstring /* alloc::ffi::c_str::CString */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'vector_out_wrapper'; + +-- src/postgres/datatype.rs:348 +-- vectors::postgres::datatype::vector_in +CREATE FUNCTION "vector_in"( + "input" cstring, /* &core::ffi::c_str::CStr */ + "_oid" oid, /* pgrx_pg_sys::submodules::oids::Oid */ + "typmod" INT /* i32 */ +) RETURNS vector /* vectors::postgres::datatype::VectorOutput */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'vector_in_wrapper'; + +-- src/postgres/casts.rs:19 +-- vectors::postgres::casts::cast_vector_to_array +CREATE FUNCTION "cast_vector_to_array"( + "vector" vector, /* vectors::postgres::datatype::VectorInput */ + "_typmod" INT, /* i32 */ + "_explicit" bool /* bool */ +) RETURNS real[] /* alloc::vec::Vec */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'cast_vector_to_array_wrapper'; + +-- src/postgres/casts.rs:5 +-- vectors::postgres::casts::cast_array_to_vector +CREATE FUNCTION "cast_array_to_vector"( + "array" real[], /* pgrx::datum::array::Array */ + "typmod" INT, /* i32 */ + "_explicit" bool /* bool */ +) RETURNS vector /* vectors::postgres::datatype::VectorOutput */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'cast_array_to_vector_wrapper'; + +-- src/embedding/udf.rs:11 +-- vectors::embedding::udf::ai_embedding_vector +CREATE FUNCTION "ai_embedding_vector"( + "input" TEXT /* alloc::string::String */ +) RETURNS vector /* vectors::postgres::datatype::VectorOutput */ +STRICT +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'ai_embedding_vector_wrapper'; + +-- src/postgres/stat.rs:4 +CREATE TYPE VectorIndexInfo AS ( + indexing BOOL, + idx_tuples INT, + idx_sealed_len INT, + idx_growing_len INT, + idx_write INT, + idx_sealed INT[], + idx_growing INT[], + idx_config TEXT +); + +-- src/postgres/datatype.rs:72 +-- creates: +-- Type(vectors::postgres::datatype::Vector) + +-- requires: +-- vector_in +-- vector_out +-- vector_typmod_in +-- vector_typmod_out + + +CREATE TYPE vector ( + INPUT = vector_in, + OUTPUT = vector_out, + TYPMOD_IN = vector_typmod_in, + TYPMOD_OUT = vector_typmod_out, + STORAGE = EXTENDED, + INTERNALLENGTH = VARIABLE, + ALIGNMENT = double +); + + +-- src/postgres/operators.rs:48 +-- vectors::postgres::operators::operator_lt +-- requires: +-- vector +CREATE FUNCTION "operator_lt"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS bool /* bool */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_lt_wrapper'; + +-- src/postgres/operators.rs:48 +-- vectors::postgres::operators::operator_lt +CREATE OPERATOR < ( + PROCEDURE="operator_lt", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector, /* vectors::postgres::datatype::VectorInput */ + COMMUTATOR = >, + NEGATOR = >=, + RESTRICT = scalarltsel, + JOIN = scalarltjoinsel +); + +-- src/postgres/operators.rs:116 +-- vectors::postgres::operators::operator_eq +-- requires: +-- vector +CREATE FUNCTION "operator_eq"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS bool /* bool */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_eq_wrapper'; + +-- src/postgres/operators.rs:116 +-- vectors::postgres::operators::operator_eq +CREATE OPERATOR = ( + PROCEDURE="operator_eq", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector, /* vectors::postgres::datatype::VectorInput */ + COMMUTATOR = =, + NEGATOR = <>, + RESTRICT = eqsel, + JOIN = eqjoinsel +); + +-- src/postgres/operators.rs:133 +-- vectors::postgres::operators::operator_neq +-- requires: +-- vector +CREATE FUNCTION "operator_neq"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS bool /* bool */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_neq_wrapper'; + +-- src/postgres/operators.rs:133 +-- vectors::postgres::operators::operator_neq +CREATE OPERATOR <> ( + PROCEDURE="operator_neq", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector, /* vectors::postgres::datatype::VectorInput */ + COMMUTATOR = <>, + NEGATOR = =, + RESTRICT = eqsel, + JOIN = eqjoinsel +); + +-- src/postgres/operators.rs:65 +-- vectors::postgres::operators::operator_lte +-- requires: +-- vector +CREATE FUNCTION "operator_lte"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS bool /* bool */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_lte_wrapper'; + +-- src/postgres/operators.rs:65 +-- vectors::postgres::operators::operator_lte +CREATE OPERATOR <= ( + PROCEDURE="operator_lte", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector, /* vectors::postgres::datatype::VectorInput */ + COMMUTATOR = >=, + NEGATOR = >, + RESTRICT = scalarltsel, + JOIN = scalarltjoinsel +); + +-- src/postgres/operators.rs:161 +-- vectors::postgres::operators::operator_dot +-- requires: +-- vector +CREATE FUNCTION "operator_dot"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS real /* vectors::prelude::scalar::Scalar */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_dot_wrapper'; + +-- src/postgres/operators.rs:161 +-- vectors::postgres::operators::operator_dot +CREATE OPERATOR <#> ( + PROCEDURE="operator_dot", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector, /* vectors::postgres::datatype::VectorInput */ + COMMUTATOR = <#> +); + +-- src/postgres/operators.rs:8 +-- vectors::postgres::operators::operator_add +-- requires: +-- vector +CREATE FUNCTION "operator_add"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS vector /* vectors::postgres::datatype::VectorOutput */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_add_wrapper'; + +-- src/postgres/operators.rs:8 +-- vectors::postgres::operators::operator_add +CREATE OPERATOR + ( + PROCEDURE="operator_add", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector, /* vectors::postgres::datatype::VectorInput */ + COMMUTATOR = + +); + +-- src/postgres/index.rs:34 +-- vectors::postgres::index::vectors_amhandler + + CREATE OR REPLACE FUNCTION vectors_amhandler(internal) RETURNS index_am_handler + PARALLEL SAFE IMMUTABLE STRICT LANGUAGE c AS 'MODULE_PATHNAME', 'vectors_amhandler_wrapper'; + CREATE ACCESS METHOD vectors TYPE INDEX HANDLER vectors_amhandler; + COMMENT ON ACCESS METHOD vectors IS 'pgvecto.rs index access method'; + + + + +-- src/postgres/operators.rs:99 +-- vectors::postgres::operators::operator_gte +-- requires: +-- vector +CREATE FUNCTION "operator_gte"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS bool /* bool */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_gte_wrapper'; + +-- src/postgres/operators.rs:99 +-- vectors::postgres::operators::operator_gte +CREATE OPERATOR >= ( + PROCEDURE="operator_gte", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector, /* vectors::postgres::datatype::VectorInput */ + COMMUTATOR = <=, + NEGATOR = <, + RESTRICT = scalargtsel, + JOIN = scalargtjoinsel +); + +-- src/postgres/operators.rs:26 +-- vectors::postgres::operators::operator_minus +-- requires: +-- vector +CREATE FUNCTION "operator_minus"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS vector /* vectors::postgres::datatype::VectorOutput */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_minus_wrapper'; + +-- src/postgres/operators.rs:26 +-- vectors::postgres::operators::operator_minus +CREATE OPERATOR - ( + PROCEDURE="operator_minus", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector /* vectors::postgres::datatype::VectorInput */ +); + +-- src/postgres/operators.rs:175 +-- vectors::postgres::operators::operator_l2 +-- requires: +-- vector +CREATE FUNCTION "operator_l2"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS real /* vectors::prelude::scalar::Scalar */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_l2_wrapper'; + +-- src/postgres/operators.rs:175 +-- vectors::postgres::operators::operator_l2 +CREATE OPERATOR <-> ( + PROCEDURE="operator_l2", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector, /* vectors::postgres::datatype::VectorInput */ + COMMUTATOR = <-> +); + +-- src/postgres/operators.rs:82 +-- vectors::postgres::operators::operator_gt +-- requires: +-- vector +CREATE FUNCTION "operator_gt"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS bool /* bool */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_gt_wrapper'; + +-- src/postgres/operators.rs:82 +-- vectors::postgres::operators::operator_gt +CREATE OPERATOR > ( + PROCEDURE="operator_gt", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector, /* vectors::postgres::datatype::VectorInput */ + COMMUTATOR = <, + NEGATOR = <=, + RESTRICT = scalargtsel, + JOIN = scalargtjoinsel +); + +-- src/postgres/operators.rs:147 +-- vectors::postgres::operators::operator_cosine +-- requires: +-- vector +CREATE FUNCTION "operator_cosine"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS real /* vectors::prelude::scalar::Scalar */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_cosine_wrapper'; + +-- src/postgres/operators.rs:147 +-- vectors::postgres::operators::operator_cosine +CREATE OPERATOR <=> ( + PROCEDURE="operator_cosine", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector, /* vectors::postgres::datatype::VectorInput */ + COMMUTATOR = <=> +); + +-- src/lib.rs:17 +-- finalize +CREATE CAST (real[] AS vector) + WITH FUNCTION cast_array_to_vector(real[], integer, boolean) AS IMPLICIT; + +CREATE CAST (vector AS real[]) + WITH FUNCTION cast_vector_to_array(vector, integer, boolean) AS IMPLICIT; + +CREATE OPERATOR CLASS l2_ops + FOR TYPE vector USING vectors AS + OPERATOR 1 <-> (vector, vector) FOR ORDER BY float_ops; + +CREATE OPERATOR CLASS dot_ops + FOR TYPE vector USING vectors AS + OPERATOR 1 <#> (vector, vector) FOR ORDER BY float_ops; + +CREATE OPERATOR CLASS cosine_ops + FOR TYPE vector USING vectors AS + OPERATOR 1 <=> (vector, vector) FOR ORDER BY float_ops; + +CREATE VIEW pg_vector_index_info AS + SELECT + C.oid AS tablerelid, + I.oid AS indexrelid, + C.relname AS tablename, + I.relname AS indexname, + (vector_stat(I.oid)).* + FROM pg_class C JOIN + pg_index X ON C.oid = X.indrelid JOIN + pg_class I ON I.oid = X.indexrelid JOIN + pg_am A ON A.oid = I.relam + WHERE A.amname = 'vectors'; diff --git a/sql/install/vectors--0.1.12.sql b/sql/install/vectors--0.1.12.sql new file mode 100644 index 000000000..36004c1f1 --- /dev/null +++ b/sql/install/vectors--0.1.12.sql @@ -0,0 +1,736 @@ + + + + + + + + + + + + + + + + + + +/* +This file is auto generated by pgrx. + +The ordering of items is not stable, it is driven by a dependency graph. +*/ + + +-- src/lib.rs:18 +-- bootstrap +CREATE TYPE vector; +CREATE TYPE vecf16; + + +-- src/index/views.rs:18 +-- vectors::index::views::vector_stat +CREATE FUNCTION "vector_stat"( + "oid" oid /* pgrx_pg_sys::submodules::oids::Oid */ +) RETURNS VectorIndexStat /* pgrx::heap_tuple::PgHeapTuple */ +STRICT VOLATILE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'vector_stat_wrapper'; + +-- src/datatype/vecf32.rs:332 +-- vectors::datatype::vecf32::vecf32_out +CREATE FUNCTION "vecf32_out"( + "vector" vector /* vectors::datatype::vecf32::Vecf32Input */ +) RETURNS cstring /* alloc::ffi::c_str::CString */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'vecf32_out_wrapper'; + +-- src/datatype/vecf32.rs:268 +-- vectors::datatype::vecf32::vecf32_in +CREATE FUNCTION "vecf32_in"( + "input" cstring, /* &core::ffi::c_str::CStr */ + "_oid" oid, /* pgrx_pg_sys::submodules::oids::Oid */ + "typmod" INT /* i32 */ +) RETURNS vector /* vectors::datatype::vecf32::Vecf32Output */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'vecf32_in_wrapper'; + +-- src/datatype/casts_f32.rs:24 +-- vectors::datatype::casts_f32::vecf32_cast_vector_to_array +CREATE FUNCTION "vecf32_cast_vector_to_array"( + "vector" vector, /* vectors::datatype::vecf32::Vecf32Input */ + "_typmod" INT, /* i32 */ + "_explicit" bool /* bool */ +) RETURNS real[] /* alloc::vec::Vec */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'vecf32_cast_vector_to_array_wrapper'; + +-- src/datatype/casts_f32.rs:6 +-- vectors::datatype::casts_f32::vecf32_cast_array_to_vector +CREATE FUNCTION "vecf32_cast_array_to_vector"( + "array" real[], /* pgrx::datum::array::Array */ + "typmod" INT, /* i32 */ + "_explicit" bool /* bool */ +) RETURNS vector /* vectors::datatype::vecf32::Vecf32Output */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'vecf32_cast_array_to_vector_wrapper'; + +-- src/datatype/vecf16.rs:332 +-- vectors::datatype::vecf16::vecf16_out +CREATE FUNCTION "vecf16_out"( + "vector" vecf16 /* vectors::datatype::vecf16::Vecf16Input */ +) RETURNS cstring /* alloc::ffi::c_str::CString */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'vecf16_out_wrapper'; + +-- src/datatype/vecf16.rs:268 +-- vectors::datatype::vecf16::vecf16_in +CREATE FUNCTION "vecf16_in"( + "input" cstring, /* &core::ffi::c_str::CStr */ + "_oid" oid, /* pgrx_pg_sys::submodules::oids::Oid */ + "typmod" INT /* i32 */ +) RETURNS vecf16 /* vectors::datatype::vecf16::Vecf16Output */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'vecf16_in_wrapper'; + +-- src/datatype/typmod.rs:71 +-- vectors::datatype::typmod::typmod_out +CREATE FUNCTION "typmod_out"( + "typmod" INT /* i32 */ +) RETURNS cstring /* alloc::ffi::c_str::CString */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'typmod_out_wrapper'; + +-- src/datatype/typmod.rs:56 +-- vectors::datatype::typmod::typmod_in +CREATE FUNCTION "typmod_in"( + "list" cstring[] /* pgrx::datum::array::Array<&core::ffi::c_str::CStr> */ +) RETURNS INT /* i32 */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'typmod_in_wrapper'; + +-- src/embedding/udf.rs:9 +-- vectors::embedding::udf::ai_embedding_vector +CREATE FUNCTION "ai_embedding_vector"( + "input" TEXT /* alloc::string::String */ +) RETURNS vector /* vectors::datatype::vecf32::Vecf32Output */ +STRICT +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'ai_embedding_vector_wrapper'; + +-- src/datatype/vecf32.rs:22 +-- creates: +-- Type(vectors::datatype::vecf32::Vecf32) + +-- requires: +-- vecf32_in +-- vecf32_out +-- typmod_in +-- typmod_out + + +CREATE TYPE vector ( + INPUT = vecf32_in, + OUTPUT = vecf32_out, + TYPMOD_IN = typmod_in, + TYPMOD_OUT = typmod_out, + STORAGE = EXTENDED, + INTERNALLENGTH = VARIABLE, + ALIGNMENT = double +); + + +-- src/datatype/operators_f32.rs:26 +-- vectors::datatype::operators_f32::vecf32_operator_minus +-- requires: +-- vecf32 +CREATE FUNCTION "vecf32_operator_minus"( + "lhs" vector, /* vectors::datatype::vecf32::Vecf32Input */ + "rhs" vector /* vectors::datatype::vecf32::Vecf32Input */ +) RETURNS vector /* vectors::datatype::vecf32::Vecf32Output */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'vecf32_operator_minus_wrapper'; + +-- src/datatype/operators_f32.rs:26 +-- vectors::datatype::operators_f32::vecf32_operator_minus +CREATE OPERATOR - ( + PROCEDURE="vecf32_operator_minus", + LEFTARG=vector, /* vectors::datatype::vecf32::Vecf32Input */ + RIGHTARG=vector /* vectors::datatype::vecf32::Vecf32Input */ +); + +-- src/datatype/operators_f32.rs:99 +-- vectors::datatype::operators_f32::vecf32_operator_gte +-- requires: +-- vecf32 +CREATE FUNCTION "vecf32_operator_gte"( + "lhs" vector, /* vectors::datatype::vecf32::Vecf32Input */ + "rhs" vector /* vectors::datatype::vecf32::Vecf32Input */ +) RETURNS bool /* bool */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'vecf32_operator_gte_wrapper'; + +-- src/datatype/operators_f32.rs:99 +-- vectors::datatype::operators_f32::vecf32_operator_gte +CREATE OPERATOR >= ( + PROCEDURE="vecf32_operator_gte", + LEFTARG=vector, /* vectors::datatype::vecf32::Vecf32Input */ + RIGHTARG=vector, /* vectors::datatype::vecf32::Vecf32Input */ + COMMUTATOR = <=, + NEGATOR = <, + RESTRICT = scalargtsel, + JOIN = scalargtjoinsel +); + +-- src/datatype/operators_f32.rs:65 +-- vectors::datatype::operators_f32::vecf32_operator_lte +-- requires: +-- vecf32 +CREATE FUNCTION "vecf32_operator_lte"( + "lhs" vector, /* vectors::datatype::vecf32::Vecf32Input */ + "rhs" vector /* vectors::datatype::vecf32::Vecf32Input */ +) RETURNS bool /* bool */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'vecf32_operator_lte_wrapper'; + +-- src/datatype/operators_f32.rs:65 +-- vectors::datatype::operators_f32::vecf32_operator_lte +CREATE OPERATOR <= ( + PROCEDURE="vecf32_operator_lte", + LEFTARG=vector, /* vectors::datatype::vecf32::Vecf32Input */ + RIGHTARG=vector, /* vectors::datatype::vecf32::Vecf32Input */ + COMMUTATOR = >=, + NEGATOR = >, + RESTRICT = scalarltsel, + JOIN = scalarltjoinsel +); + +-- src/datatype/operators_f32.rs:48 +-- vectors::datatype::operators_f32::vecf32_operator_lt +-- requires: +-- vecf32 +CREATE FUNCTION "vecf32_operator_lt"( + "lhs" vector, /* vectors::datatype::vecf32::Vecf32Input */ + "rhs" vector /* vectors::datatype::vecf32::Vecf32Input */ +) RETURNS bool /* bool */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'vecf32_operator_lt_wrapper'; + +-- src/datatype/operators_f32.rs:48 +-- vectors::datatype::operators_f32::vecf32_operator_lt +CREATE OPERATOR < ( + PROCEDURE="vecf32_operator_lt", + LEFTARG=vector, /* vectors::datatype::vecf32::Vecf32Input */ + RIGHTARG=vector, /* vectors::datatype::vecf32::Vecf32Input */ + COMMUTATOR = >, + NEGATOR = >=, + RESTRICT = scalarltsel, + JOIN = scalarltjoinsel +); + +-- src/datatype/operators_f32.rs:147 +-- vectors::datatype::operators_f32::vecf32_operator_cosine +-- requires: +-- vecf32 +CREATE FUNCTION "vecf32_operator_cosine"( + "lhs" vector, /* vectors::datatype::vecf32::Vecf32Input */ + "rhs" vector /* vectors::datatype::vecf32::Vecf32Input */ +) RETURNS real /* f32 */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'vecf32_operator_cosine_wrapper'; + +-- src/datatype/operators_f32.rs:147 +-- vectors::datatype::operators_f32::vecf32_operator_cosine +CREATE OPERATOR <=> ( + PROCEDURE="vecf32_operator_cosine", + LEFTARG=vector, /* vectors::datatype::vecf32::Vecf32Input */ + RIGHTARG=vector, /* vectors::datatype::vecf32::Vecf32Input */ + COMMUTATOR = <=> +); + +-- src/datatype/operators_f32.rs:8 +-- vectors::datatype::operators_f32::vecf32_operator_add +-- requires: +-- vecf32 +CREATE FUNCTION "vecf32_operator_add"( + "lhs" vector, /* vectors::datatype::vecf32::Vecf32Input */ + "rhs" vector /* vectors::datatype::vecf32::Vecf32Input */ +) RETURNS vector /* vectors::datatype::vecf32::Vecf32Output */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'vecf32_operator_add_wrapper'; + +-- src/datatype/operators_f32.rs:8 +-- vectors::datatype::operators_f32::vecf32_operator_add +CREATE OPERATOR + ( + PROCEDURE="vecf32_operator_add", + LEFTARG=vector, /* vectors::datatype::vecf32::Vecf32Input */ + RIGHTARG=vector, /* vectors::datatype::vecf32::Vecf32Input */ + COMMUTATOR = + +); + +-- src/datatype/operators_f32.rs:161 +-- vectors::datatype::operators_f32::vecf32_operator_dot +-- requires: +-- vecf32 +CREATE FUNCTION "vecf32_operator_dot"( + "lhs" vector, /* vectors::datatype::vecf32::Vecf32Input */ + "rhs" vector /* vectors::datatype::vecf32::Vecf32Input */ +) RETURNS real /* f32 */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'vecf32_operator_dot_wrapper'; + +-- src/datatype/operators_f32.rs:161 +-- vectors::datatype::operators_f32::vecf32_operator_dot +CREATE OPERATOR <#> ( + PROCEDURE="vecf32_operator_dot", + LEFTARG=vector, /* vectors::datatype::vecf32::Vecf32Input */ + RIGHTARG=vector, /* vectors::datatype::vecf32::Vecf32Input */ + COMMUTATOR = <#> +); + +-- src/index/am.rs:33 +-- vectors::index::am::vectors_amhandler + + CREATE OR REPLACE FUNCTION vectors_amhandler(internal) RETURNS index_am_handler + PARALLEL SAFE IMMUTABLE STRICT LANGUAGE c AS 'MODULE_PATHNAME', 'vectors_amhandler_wrapper'; + + + + +-- src/datatype/operators_f32.rs:175 +-- vectors::datatype::operators_f32::vecf32_operator_l2 +-- requires: +-- vecf32 +CREATE FUNCTION "vecf32_operator_l2"( + "lhs" vector, /* vectors::datatype::vecf32::Vecf32Input */ + "rhs" vector /* vectors::datatype::vecf32::Vecf32Input */ +) RETURNS real /* f32 */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'vecf32_operator_l2_wrapper'; + +-- src/datatype/operators_f32.rs:175 +-- vectors::datatype::operators_f32::vecf32_operator_l2 +CREATE OPERATOR <-> ( + PROCEDURE="vecf32_operator_l2", + LEFTARG=vector, /* vectors::datatype::vecf32::Vecf32Input */ + RIGHTARG=vector, /* vectors::datatype::vecf32::Vecf32Input */ + COMMUTATOR = <-> +); + +-- src/datatype/operators_f32.rs:82 +-- vectors::datatype::operators_f32::vecf32_operator_gt +-- requires: +-- vecf32 +CREATE FUNCTION "vecf32_operator_gt"( + "lhs" vector, /* vectors::datatype::vecf32::Vecf32Input */ + "rhs" vector /* vectors::datatype::vecf32::Vecf32Input */ +) RETURNS bool /* bool */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'vecf32_operator_gt_wrapper'; + +-- src/datatype/operators_f32.rs:82 +-- vectors::datatype::operators_f32::vecf32_operator_gt +CREATE OPERATOR > ( + PROCEDURE="vecf32_operator_gt", + LEFTARG=vector, /* vectors::datatype::vecf32::Vecf32Input */ + RIGHTARG=vector, /* vectors::datatype::vecf32::Vecf32Input */ + COMMUTATOR = <, + NEGATOR = <=, + RESTRICT = scalargtsel, + JOIN = scalargtjoinsel +); + +-- src/datatype/operators_f32.rs:116 +-- vectors::datatype::operators_f32::vecf32_operator_eq +-- requires: +-- vecf32 +CREATE FUNCTION "vecf32_operator_eq"( + "lhs" vector, /* vectors::datatype::vecf32::Vecf32Input */ + "rhs" vector /* vectors::datatype::vecf32::Vecf32Input */ +) RETURNS bool /* bool */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'vecf32_operator_eq_wrapper'; + +-- src/datatype/operators_f32.rs:116 +-- vectors::datatype::operators_f32::vecf32_operator_eq +CREATE OPERATOR = ( + PROCEDURE="vecf32_operator_eq", + LEFTARG=vector, /* vectors::datatype::vecf32::Vecf32Input */ + RIGHTARG=vector, /* vectors::datatype::vecf32::Vecf32Input */ + COMMUTATOR = =, + NEGATOR = <>, + RESTRICT = eqsel, + JOIN = eqjoinsel +); + +-- src/datatype/operators_f32.rs:133 +-- vectors::datatype::operators_f32::vecf32_operator_neq +-- requires: +-- vecf32 +CREATE FUNCTION "vecf32_operator_neq"( + "lhs" vector, /* vectors::datatype::vecf32::Vecf32Input */ + "rhs" vector /* vectors::datatype::vecf32::Vecf32Input */ +) RETURNS bool /* bool */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'vecf32_operator_neq_wrapper'; + +-- src/datatype/operators_f32.rs:133 +-- vectors::datatype::operators_f32::vecf32_operator_neq +CREATE OPERATOR <> ( + PROCEDURE="vecf32_operator_neq", + LEFTARG=vector, /* vectors::datatype::vecf32::Vecf32Input */ + RIGHTARG=vector, /* vectors::datatype::vecf32::Vecf32Input */ + COMMUTATOR = <>, + NEGATOR = =, + RESTRICT = eqsel, + JOIN = eqjoinsel +); + +-- src/datatype/vecf16.rs:22 +-- creates: +-- Type(vectors::datatype::vecf16::Vecf16) + +-- requires: +-- vecf16_in +-- vecf16_out +-- typmod_in +-- typmod_out + + +CREATE TYPE vecf16 ( + INPUT = vecf16_in, + OUTPUT = vecf16_out, + TYPMOD_IN = typmod_in, + TYPMOD_OUT = typmod_out, + STORAGE = EXTENDED, + INTERNALLENGTH = VARIABLE, + ALIGNMENT = double +); + + +-- src/datatype/operators_f16.rs:133 +-- vectors::datatype::operators_f16::vecf16_operator_neq +-- requires: +-- vecf16 +CREATE FUNCTION "vecf16_operator_neq"( + "lhs" vecf16, /* vectors::datatype::vecf16::Vecf16Input */ + "rhs" vecf16 /* vectors::datatype::vecf16::Vecf16Input */ +) RETURNS bool /* bool */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'vecf16_operator_neq_wrapper'; + +-- src/datatype/operators_f16.rs:133 +-- vectors::datatype::operators_f16::vecf16_operator_neq +CREATE OPERATOR <> ( + PROCEDURE="vecf16_operator_neq", + LEFTARG=vecf16, /* vectors::datatype::vecf16::Vecf16Input */ + RIGHTARG=vecf16, /* vectors::datatype::vecf16::Vecf16Input */ + COMMUTATOR = <>, + NEGATOR = =, + RESTRICT = eqsel, + JOIN = eqjoinsel +); + +-- src/datatype/operators_f16.rs:48 +-- vectors::datatype::operators_f16::vecf16_operator_lt +-- requires: +-- vecf16 +CREATE FUNCTION "vecf16_operator_lt"( + "lhs" vecf16, /* vectors::datatype::vecf16::Vecf16Input */ + "rhs" vecf16 /* vectors::datatype::vecf16::Vecf16Input */ +) RETURNS bool /* bool */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'vecf16_operator_lt_wrapper'; + +-- src/datatype/operators_f16.rs:48 +-- vectors::datatype::operators_f16::vecf16_operator_lt +CREATE OPERATOR < ( + PROCEDURE="vecf16_operator_lt", + LEFTARG=vecf16, /* vectors::datatype::vecf16::Vecf16Input */ + RIGHTARG=vecf16, /* vectors::datatype::vecf16::Vecf16Input */ + COMMUTATOR = >, + NEGATOR = >=, + RESTRICT = scalarltsel, + JOIN = scalarltjoinsel +); + +-- src/datatype/operators_f16.rs:175 +-- vectors::datatype::operators_f16::vecf16_operator_l2 +-- requires: +-- vecf16 +CREATE FUNCTION "vecf16_operator_l2"( + "lhs" vecf16, /* vectors::datatype::vecf16::Vecf16Input */ + "rhs" vecf16 /* vectors::datatype::vecf16::Vecf16Input */ +) RETURNS real /* f32 */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'vecf16_operator_l2_wrapper'; + +-- src/datatype/operators_f16.rs:175 +-- vectors::datatype::operators_f16::vecf16_operator_l2 +CREATE OPERATOR <-> ( + PROCEDURE="vecf16_operator_l2", + LEFTARG=vecf16, /* vectors::datatype::vecf16::Vecf16Input */ + RIGHTARG=vecf16, /* vectors::datatype::vecf16::Vecf16Input */ + COMMUTATOR = <-> +); + +-- src/datatype/operators_f16.rs:8 +-- vectors::datatype::operators_f16::vecf16_operator_add +-- requires: +-- vecf16 +CREATE FUNCTION "vecf16_operator_add"( + "lhs" vecf16, /* vectors::datatype::vecf16::Vecf16Input */ + "rhs" vecf16 /* vectors::datatype::vecf16::Vecf16Input */ +) RETURNS vecf16 /* vectors::datatype::vecf16::Vecf16Output */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'vecf16_operator_add_wrapper'; + +-- src/datatype/operators_f16.rs:8 +-- vectors::datatype::operators_f16::vecf16_operator_add +CREATE OPERATOR + ( + PROCEDURE="vecf16_operator_add", + LEFTARG=vecf16, /* vectors::datatype::vecf16::Vecf16Input */ + RIGHTARG=vecf16, /* vectors::datatype::vecf16::Vecf16Input */ + COMMUTATOR = + +); + +-- src/datatype/operators_f16.rs:26 +-- vectors::datatype::operators_f16::vecf16_operator_minus +-- requires: +-- vecf16 +CREATE FUNCTION "vecf16_operator_minus"( + "lhs" vecf16, /* vectors::datatype::vecf16::Vecf16Input */ + "rhs" vecf16 /* vectors::datatype::vecf16::Vecf16Input */ +) RETURNS vecf16 /* vectors::datatype::vecf16::Vecf16Output */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'vecf16_operator_minus_wrapper'; + +-- src/datatype/operators_f16.rs:26 +-- vectors::datatype::operators_f16::vecf16_operator_minus +CREATE OPERATOR - ( + PROCEDURE="vecf16_operator_minus", + LEFTARG=vecf16, /* vectors::datatype::vecf16::Vecf16Input */ + RIGHTARG=vecf16 /* vectors::datatype::vecf16::Vecf16Input */ +); + +-- src/datatype/operators_f16.rs:161 +-- vectors::datatype::operators_f16::vecf16_operator_dot +-- requires: +-- vecf16 +CREATE FUNCTION "vecf16_operator_dot"( + "lhs" vecf16, /* vectors::datatype::vecf16::Vecf16Input */ + "rhs" vecf16 /* vectors::datatype::vecf16::Vecf16Input */ +) RETURNS real /* f32 */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'vecf16_operator_dot_wrapper'; + +-- src/datatype/operators_f16.rs:161 +-- vectors::datatype::operators_f16::vecf16_operator_dot +CREATE OPERATOR <#> ( + PROCEDURE="vecf16_operator_dot", + LEFTARG=vecf16, /* vectors::datatype::vecf16::Vecf16Input */ + RIGHTARG=vecf16, /* vectors::datatype::vecf16::Vecf16Input */ + COMMUTATOR = <#> +); + +-- src/datatype/operators_f16.rs:82 +-- vectors::datatype::operators_f16::vecf16_operator_gt +-- requires: +-- vecf16 +CREATE FUNCTION "vecf16_operator_gt"( + "lhs" vecf16, /* vectors::datatype::vecf16::Vecf16Input */ + "rhs" vecf16 /* vectors::datatype::vecf16::Vecf16Input */ +) RETURNS bool /* bool */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'vecf16_operator_gt_wrapper'; + +-- src/datatype/operators_f16.rs:82 +-- vectors::datatype::operators_f16::vecf16_operator_gt +CREATE OPERATOR > ( + PROCEDURE="vecf16_operator_gt", + LEFTARG=vecf16, /* vectors::datatype::vecf16::Vecf16Input */ + RIGHTARG=vecf16, /* vectors::datatype::vecf16::Vecf16Input */ + COMMUTATOR = <, + NEGATOR = <=, + RESTRICT = scalargtsel, + JOIN = scalargtjoinsel +); + +-- src/datatype/operators_f16.rs:65 +-- vectors::datatype::operators_f16::vecf16_operator_lte +-- requires: +-- vecf16 +CREATE FUNCTION "vecf16_operator_lte"( + "lhs" vecf16, /* vectors::datatype::vecf16::Vecf16Input */ + "rhs" vecf16 /* vectors::datatype::vecf16::Vecf16Input */ +) RETURNS bool /* bool */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'vecf16_operator_lte_wrapper'; + +-- src/datatype/operators_f16.rs:65 +-- vectors::datatype::operators_f16::vecf16_operator_lte +CREATE OPERATOR <= ( + PROCEDURE="vecf16_operator_lte", + LEFTARG=vecf16, /* vectors::datatype::vecf16::Vecf16Input */ + RIGHTARG=vecf16, /* vectors::datatype::vecf16::Vecf16Input */ + COMMUTATOR = >=, + NEGATOR = >, + RESTRICT = scalarltsel, + JOIN = scalarltjoinsel +); + +-- src/datatype/operators_f16.rs:116 +-- vectors::datatype::operators_f16::vecf16_operator_eq +-- requires: +-- vecf16 +CREATE FUNCTION "vecf16_operator_eq"( + "lhs" vecf16, /* vectors::datatype::vecf16::Vecf16Input */ + "rhs" vecf16 /* vectors::datatype::vecf16::Vecf16Input */ +) RETURNS bool /* bool */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'vecf16_operator_eq_wrapper'; + +-- src/datatype/operators_f16.rs:116 +-- vectors::datatype::operators_f16::vecf16_operator_eq +CREATE OPERATOR = ( + PROCEDURE="vecf16_operator_eq", + LEFTARG=vecf16, /* vectors::datatype::vecf16::Vecf16Input */ + RIGHTARG=vecf16, /* vectors::datatype::vecf16::Vecf16Input */ + COMMUTATOR = =, + NEGATOR = <>, + RESTRICT = eqsel, + JOIN = eqjoinsel +); + +-- src/datatype/operators_f16.rs:147 +-- vectors::datatype::operators_f16::vecf16_operator_cosine +-- requires: +-- vecf16 +CREATE FUNCTION "vecf16_operator_cosine"( + "lhs" vecf16, /* vectors::datatype::vecf16::Vecf16Input */ + "rhs" vecf16 /* vectors::datatype::vecf16::Vecf16Input */ +) RETURNS real /* f32 */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'vecf16_operator_cosine_wrapper'; + +-- src/datatype/operators_f16.rs:147 +-- vectors::datatype::operators_f16::vecf16_operator_cosine +CREATE OPERATOR <=> ( + PROCEDURE="vecf16_operator_cosine", + LEFTARG=vecf16, /* vectors::datatype::vecf16::Vecf16Input */ + RIGHTARG=vecf16, /* vectors::datatype::vecf16::Vecf16Input */ + COMMUTATOR = <=> +); + +-- src/datatype/operators_f16.rs:99 +-- vectors::datatype::operators_f16::vecf16_operator_gte +-- requires: +-- vecf16 +CREATE FUNCTION "vecf16_operator_gte"( + "lhs" vecf16, /* vectors::datatype::vecf16::Vecf16Input */ + "rhs" vecf16 /* vectors::datatype::vecf16::Vecf16Input */ +) RETURNS bool /* bool */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'vecf16_operator_gte_wrapper'; + +-- src/datatype/operators_f16.rs:99 +-- vectors::datatype::operators_f16::vecf16_operator_gte +CREATE OPERATOR >= ( + PROCEDURE="vecf16_operator_gte", + LEFTARG=vecf16, /* vectors::datatype::vecf16::Vecf16Input */ + RIGHTARG=vecf16, /* vectors::datatype::vecf16::Vecf16Input */ + COMMUTATOR = <=, + NEGATOR = <, + RESTRICT = scalargtsel, + JOIN = scalargtjoinsel +); + +-- src/index/views.rs:4 +CREATE TYPE VectorIndexStat AS ( + idx_indexing BOOL, + idx_tuples BIGINT, + idx_sealed BIGINT[], + idx_growing BIGINT[], + idx_write BIGINT, + idx_options TEXT +); + +-- src/lib.rs:19 +-- finalize +CREATE CAST (real[] AS vector) + WITH FUNCTION vecf32_cast_array_to_vector(real[], integer, boolean) AS IMPLICIT; + +CREATE CAST (vector AS real[]) + WITH FUNCTION vecf32_cast_vector_to_array(vector, integer, boolean) AS IMPLICIT; + +CREATE ACCESS METHOD vectors TYPE INDEX HANDLER vectors_amhandler; +COMMENT ON ACCESS METHOD vectors IS 'pgvecto.rs index access method'; + +CREATE OPERATOR CLASS vector_l2_ops + FOR TYPE vector USING vectors AS + OPERATOR 1 <-> (vector, vector) FOR ORDER BY float_ops; + +CREATE OPERATOR CLASS vector_dot_ops + FOR TYPE vector USING vectors AS + OPERATOR 1 <#> (vector, vector) FOR ORDER BY float_ops; + +CREATE OPERATOR CLASS vector_cos_ops + FOR TYPE vector USING vectors AS + OPERATOR 1 <=> (vector, vector) FOR ORDER BY float_ops; + +CREATE OPERATOR CLASS vecf16_l2_ops + FOR TYPE vecf16 USING vectors AS + OPERATOR 1 <-> (vecf16, vecf16) FOR ORDER BY float_ops; + +CREATE OPERATOR CLASS vecf16_dot_ops + FOR TYPE vecf16 USING vectors AS + OPERATOR 1 <#> (vecf16, vecf16) FOR ORDER BY float_ops; + +CREATE OPERATOR CLASS vecf16_cos_ops + FOR TYPE vecf16 USING vectors AS + OPERATOR 1 <=> (vecf16, vecf16) FOR ORDER BY float_ops; + +CREATE VIEW pg_vector_index_info AS + SELECT + C.oid AS tablerelid, + I.oid AS indexrelid, + C.relname AS tablename, + I.relname AS indexname, + (vector_stat(I.relfilenode)).* + FROM pg_class C JOIN + pg_index X ON C.oid = X.indrelid JOIN + pg_class I ON I.oid = X.indexrelid JOIN + pg_am A ON A.oid = I.relam + WHERE A.amname = 'vectors'; + diff --git a/sql/install/vectors--0.1.13.sql b/sql/install/vectors--0.1.13.sql new file mode 100644 index 000000000..8477b7591 --- /dev/null +++ b/sql/install/vectors--0.1.13.sql @@ -0,0 +1,718 @@ +/* +This file is auto generated by pgrx. + +The ordering of items is not stable, it is driven by a dependency graph. +*/ + + +-- src/lib.rs:18 +-- bootstrap +CREATE TYPE vector; +CREATE TYPE vecf16; + + +-- src/index/views.rs:18 +-- vectors::index::views::vector_stat +CREATE FUNCTION "vector_stat"( + "oid" oid /* pgrx_pg_sys::submodules::oids::Oid */ +) RETURNS VectorIndexStat /* pgrx::heap_tuple::PgHeapTuple */ +STRICT VOLATILE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'vector_stat_wrapper'; + +-- src/datatype/vecf32.rs:332 +-- vectors::datatype::vecf32::vecf32_out +CREATE FUNCTION "vecf32_out"( + "vector" vector /* vectors::datatype::vecf32::Vecf32Input */ +) RETURNS cstring /* alloc::ffi::c_str::CString */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'vecf32_out_wrapper'; + +-- src/datatype/vecf32.rs:268 +-- vectors::datatype::vecf32::vecf32_in +CREATE FUNCTION "vecf32_in"( + "input" cstring, /* &core::ffi::c_str::CStr */ + "_oid" oid, /* pgrx_pg_sys::submodules::oids::Oid */ + "typmod" INT /* i32 */ +) RETURNS vector /* vectors::datatype::vecf32::Vecf32Output */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'vecf32_in_wrapper'; + +-- src/datatype/casts_f32.rs:24 +-- vectors::datatype::casts_f32::vecf32_cast_vector_to_array +CREATE FUNCTION "vecf32_cast_vector_to_array"( + "vector" vector, /* vectors::datatype::vecf32::Vecf32Input */ + "_typmod" INT, /* i32 */ + "_explicit" bool /* bool */ +) RETURNS real[] /* alloc::vec::Vec */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'vecf32_cast_vector_to_array_wrapper'; + +-- src/datatype/casts_f32.rs:6 +-- vectors::datatype::casts_f32::vecf32_cast_array_to_vector +CREATE FUNCTION "vecf32_cast_array_to_vector"( + "array" real[], /* pgrx::datum::array::Array */ + "typmod" INT, /* i32 */ + "_explicit" bool /* bool */ +) RETURNS vector /* vectors::datatype::vecf32::Vecf32Output */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'vecf32_cast_array_to_vector_wrapper'; + +-- src/datatype/vecf16.rs:332 +-- vectors::datatype::vecf16::vecf16_out +CREATE FUNCTION "vecf16_out"( + "vector" vecf16 /* vectors::datatype::vecf16::Vecf16Input */ +) RETURNS cstring /* alloc::ffi::c_str::CString */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'vecf16_out_wrapper'; + +-- src/datatype/vecf16.rs:268 +-- vectors::datatype::vecf16::vecf16_in +CREATE FUNCTION "vecf16_in"( + "input" cstring, /* &core::ffi::c_str::CStr */ + "_oid" oid, /* pgrx_pg_sys::submodules::oids::Oid */ + "typmod" INT /* i32 */ +) RETURNS vecf16 /* vectors::datatype::vecf16::Vecf16Output */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'vecf16_in_wrapper'; + +-- src/datatype/typmod.rs:71 +-- vectors::datatype::typmod::typmod_out +CREATE FUNCTION "typmod_out"( + "typmod" INT /* i32 */ +) RETURNS cstring /* alloc::ffi::c_str::CString */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'typmod_out_wrapper'; + +-- src/datatype/typmod.rs:56 +-- vectors::datatype::typmod::typmod_in +CREATE FUNCTION "typmod_in"( + "list" cstring[] /* pgrx::datum::array::Array<&core::ffi::c_str::CStr> */ +) RETURNS INT /* i32 */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'typmod_in_wrapper'; + +-- src/embedding/udf.rs:9 +-- vectors::embedding::udf::ai_embedding_vector +CREATE FUNCTION "ai_embedding_vector"( + "input" TEXT /* alloc::string::String */ +) RETURNS vector /* vectors::datatype::vecf32::Vecf32Output */ +STRICT +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'ai_embedding_vector_wrapper'; + +-- src/datatype/vecf16.rs:22 +-- creates: +-- Type(vectors::datatype::vecf16::Vecf16) + +-- requires: +-- vecf16_in +-- vecf16_out +-- typmod_in +-- typmod_out + + +CREATE TYPE vecf16 ( + INPUT = vecf16_in, + OUTPUT = vecf16_out, + TYPMOD_IN = typmod_in, + TYPMOD_OUT = typmod_out, + STORAGE = EXTENDED, + INTERNALLENGTH = VARIABLE, + ALIGNMENT = double +); + + +-- src/datatype/operators_f16.rs:99 +-- vectors::datatype::operators_f16::vecf16_operator_gte +-- requires: +-- vecf16 +CREATE FUNCTION "vecf16_operator_gte"( + "lhs" vecf16, /* vectors::datatype::vecf16::Vecf16Input */ + "rhs" vecf16 /* vectors::datatype::vecf16::Vecf16Input */ +) RETURNS bool /* bool */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'vecf16_operator_gte_wrapper'; + +-- src/datatype/operators_f16.rs:99 +-- vectors::datatype::operators_f16::vecf16_operator_gte +CREATE OPERATOR >= ( + PROCEDURE="vecf16_operator_gte", + LEFTARG=vecf16, /* vectors::datatype::vecf16::Vecf16Input */ + RIGHTARG=vecf16, /* vectors::datatype::vecf16::Vecf16Input */ + COMMUTATOR = <=, + NEGATOR = <, + RESTRICT = scalargtsel, + JOIN = scalargtjoinsel +); + +-- src/datatype/operators_f16.rs:175 +-- vectors::datatype::operators_f16::vecf16_operator_l2 +-- requires: +-- vecf16 +CREATE FUNCTION "vecf16_operator_l2"( + "lhs" vecf16, /* vectors::datatype::vecf16::Vecf16Input */ + "rhs" vecf16 /* vectors::datatype::vecf16::Vecf16Input */ +) RETURNS real /* f32 */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'vecf16_operator_l2_wrapper'; + +-- src/datatype/operators_f16.rs:175 +-- vectors::datatype::operators_f16::vecf16_operator_l2 +CREATE OPERATOR <-> ( + PROCEDURE="vecf16_operator_l2", + LEFTARG=vecf16, /* vectors::datatype::vecf16::Vecf16Input */ + RIGHTARG=vecf16, /* vectors::datatype::vecf16::Vecf16Input */ + COMMUTATOR = <-> +); + +-- src/datatype/operators_f16.rs:26 +-- vectors::datatype::operators_f16::vecf16_operator_minus +-- requires: +-- vecf16 +CREATE FUNCTION "vecf16_operator_minus"( + "lhs" vecf16, /* vectors::datatype::vecf16::Vecf16Input */ + "rhs" vecf16 /* vectors::datatype::vecf16::Vecf16Input */ +) RETURNS vecf16 /* vectors::datatype::vecf16::Vecf16Output */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'vecf16_operator_minus_wrapper'; + +-- src/datatype/operators_f16.rs:26 +-- vectors::datatype::operators_f16::vecf16_operator_minus +CREATE OPERATOR - ( + PROCEDURE="vecf16_operator_minus", + LEFTARG=vecf16, /* vectors::datatype::vecf16::Vecf16Input */ + RIGHTARG=vecf16 /* vectors::datatype::vecf16::Vecf16Input */ +); + +-- src/datatype/operators_f16.rs:8 +-- vectors::datatype::operators_f16::vecf16_operator_add +-- requires: +-- vecf16 +CREATE FUNCTION "vecf16_operator_add"( + "lhs" vecf16, /* vectors::datatype::vecf16::Vecf16Input */ + "rhs" vecf16 /* vectors::datatype::vecf16::Vecf16Input */ +) RETURNS vecf16 /* vectors::datatype::vecf16::Vecf16Output */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'vecf16_operator_add_wrapper'; + +-- src/datatype/operators_f16.rs:8 +-- vectors::datatype::operators_f16::vecf16_operator_add +CREATE OPERATOR + ( + PROCEDURE="vecf16_operator_add", + LEFTARG=vecf16, /* vectors::datatype::vecf16::Vecf16Input */ + RIGHTARG=vecf16, /* vectors::datatype::vecf16::Vecf16Input */ + COMMUTATOR = + +); + +-- src/datatype/operators_f16.rs:48 +-- vectors::datatype::operators_f16::vecf16_operator_lt +-- requires: +-- vecf16 +CREATE FUNCTION "vecf16_operator_lt"( + "lhs" vecf16, /* vectors::datatype::vecf16::Vecf16Input */ + "rhs" vecf16 /* vectors::datatype::vecf16::Vecf16Input */ +) RETURNS bool /* bool */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'vecf16_operator_lt_wrapper'; + +-- src/datatype/operators_f16.rs:48 +-- vectors::datatype::operators_f16::vecf16_operator_lt +CREATE OPERATOR < ( + PROCEDURE="vecf16_operator_lt", + LEFTARG=vecf16, /* vectors::datatype::vecf16::Vecf16Input */ + RIGHTARG=vecf16, /* vectors::datatype::vecf16::Vecf16Input */ + COMMUTATOR = >, + NEGATOR = >=, + RESTRICT = scalarltsel, + JOIN = scalarltjoinsel +); + +-- src/datatype/operators_f16.rs:116 +-- vectors::datatype::operators_f16::vecf16_operator_eq +-- requires: +-- vecf16 +CREATE FUNCTION "vecf16_operator_eq"( + "lhs" vecf16, /* vectors::datatype::vecf16::Vecf16Input */ + "rhs" vecf16 /* vectors::datatype::vecf16::Vecf16Input */ +) RETURNS bool /* bool */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'vecf16_operator_eq_wrapper'; + +-- src/datatype/operators_f16.rs:116 +-- vectors::datatype::operators_f16::vecf16_operator_eq +CREATE OPERATOR = ( + PROCEDURE="vecf16_operator_eq", + LEFTARG=vecf16, /* vectors::datatype::vecf16::Vecf16Input */ + RIGHTARG=vecf16, /* vectors::datatype::vecf16::Vecf16Input */ + COMMUTATOR = =, + NEGATOR = <>, + RESTRICT = eqsel, + JOIN = eqjoinsel +); + +-- src/datatype/operators_f16.rs:133 +-- vectors::datatype::operators_f16::vecf16_operator_neq +-- requires: +-- vecf16 +CREATE FUNCTION "vecf16_operator_neq"( + "lhs" vecf16, /* vectors::datatype::vecf16::Vecf16Input */ + "rhs" vecf16 /* vectors::datatype::vecf16::Vecf16Input */ +) RETURNS bool /* bool */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'vecf16_operator_neq_wrapper'; + +-- src/datatype/operators_f16.rs:133 +-- vectors::datatype::operators_f16::vecf16_operator_neq +CREATE OPERATOR <> ( + PROCEDURE="vecf16_operator_neq", + LEFTARG=vecf16, /* vectors::datatype::vecf16::Vecf16Input */ + RIGHTARG=vecf16, /* vectors::datatype::vecf16::Vecf16Input */ + COMMUTATOR = <>, + NEGATOR = =, + RESTRICT = eqsel, + JOIN = eqjoinsel +); + +-- src/datatype/operators_f16.rs:161 +-- vectors::datatype::operators_f16::vecf16_operator_dot +-- requires: +-- vecf16 +CREATE FUNCTION "vecf16_operator_dot"( + "lhs" vecf16, /* vectors::datatype::vecf16::Vecf16Input */ + "rhs" vecf16 /* vectors::datatype::vecf16::Vecf16Input */ +) RETURNS real /* f32 */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'vecf16_operator_dot_wrapper'; + +-- src/datatype/operators_f16.rs:161 +-- vectors::datatype::operators_f16::vecf16_operator_dot +CREATE OPERATOR <#> ( + PROCEDURE="vecf16_operator_dot", + LEFTARG=vecf16, /* vectors::datatype::vecf16::Vecf16Input */ + RIGHTARG=vecf16, /* vectors::datatype::vecf16::Vecf16Input */ + COMMUTATOR = <#> +); + +-- src/datatype/operators_f16.rs:82 +-- vectors::datatype::operators_f16::vecf16_operator_gt +-- requires: +-- vecf16 +CREATE FUNCTION "vecf16_operator_gt"( + "lhs" vecf16, /* vectors::datatype::vecf16::Vecf16Input */ + "rhs" vecf16 /* vectors::datatype::vecf16::Vecf16Input */ +) RETURNS bool /* bool */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'vecf16_operator_gt_wrapper'; + +-- src/datatype/operators_f16.rs:82 +-- vectors::datatype::operators_f16::vecf16_operator_gt +CREATE OPERATOR > ( + PROCEDURE="vecf16_operator_gt", + LEFTARG=vecf16, /* vectors::datatype::vecf16::Vecf16Input */ + RIGHTARG=vecf16, /* vectors::datatype::vecf16::Vecf16Input */ + COMMUTATOR = <, + NEGATOR = <=, + RESTRICT = scalargtsel, + JOIN = scalargtjoinsel +); + +-- src/datatype/operators_f16.rs:65 +-- vectors::datatype::operators_f16::vecf16_operator_lte +-- requires: +-- vecf16 +CREATE FUNCTION "vecf16_operator_lte"( + "lhs" vecf16, /* vectors::datatype::vecf16::Vecf16Input */ + "rhs" vecf16 /* vectors::datatype::vecf16::Vecf16Input */ +) RETURNS bool /* bool */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'vecf16_operator_lte_wrapper'; + +-- src/datatype/operators_f16.rs:65 +-- vectors::datatype::operators_f16::vecf16_operator_lte +CREATE OPERATOR <= ( + PROCEDURE="vecf16_operator_lte", + LEFTARG=vecf16, /* vectors::datatype::vecf16::Vecf16Input */ + RIGHTARG=vecf16, /* vectors::datatype::vecf16::Vecf16Input */ + COMMUTATOR = >=, + NEGATOR = >, + RESTRICT = scalarltsel, + JOIN = scalarltjoinsel +); + +-- src/datatype/operators_f16.rs:147 +-- vectors::datatype::operators_f16::vecf16_operator_cosine +-- requires: +-- vecf16 +CREATE FUNCTION "vecf16_operator_cosine"( + "lhs" vecf16, /* vectors::datatype::vecf16::Vecf16Input */ + "rhs" vecf16 /* vectors::datatype::vecf16::Vecf16Input */ +) RETURNS real /* f32 */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'vecf16_operator_cosine_wrapper'; + +-- src/datatype/operators_f16.rs:147 +-- vectors::datatype::operators_f16::vecf16_operator_cosine +CREATE OPERATOR <=> ( + PROCEDURE="vecf16_operator_cosine", + LEFTARG=vecf16, /* vectors::datatype::vecf16::Vecf16Input */ + RIGHTARG=vecf16, /* vectors::datatype::vecf16::Vecf16Input */ + COMMUTATOR = <=> +); + +-- src/datatype/vecf32.rs:22 +-- creates: +-- Type(vectors::datatype::vecf32::Vecf32) + +-- requires: +-- vecf32_in +-- vecf32_out +-- typmod_in +-- typmod_out + + +CREATE TYPE vector ( + INPUT = vecf32_in, + OUTPUT = vecf32_out, + TYPMOD_IN = typmod_in, + TYPMOD_OUT = typmod_out, + STORAGE = EXTENDED, + INTERNALLENGTH = VARIABLE, + ALIGNMENT = double +); + + +-- src/datatype/operators_f32.rs:48 +-- vectors::datatype::operators_f32::vecf32_operator_lt +-- requires: +-- vecf32 +CREATE FUNCTION "vecf32_operator_lt"( + "lhs" vector, /* vectors::datatype::vecf32::Vecf32Input */ + "rhs" vector /* vectors::datatype::vecf32::Vecf32Input */ +) RETURNS bool /* bool */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'vecf32_operator_lt_wrapper'; + +-- src/datatype/operators_f32.rs:48 +-- vectors::datatype::operators_f32::vecf32_operator_lt +CREATE OPERATOR < ( + PROCEDURE="vecf32_operator_lt", + LEFTARG=vector, /* vectors::datatype::vecf32::Vecf32Input */ + RIGHTARG=vector, /* vectors::datatype::vecf32::Vecf32Input */ + COMMUTATOR = >, + NEGATOR = >=, + RESTRICT = scalarltsel, + JOIN = scalarltjoinsel +); + +-- src/datatype/operators_f32.rs:99 +-- vectors::datatype::operators_f32::vecf32_operator_gte +-- requires: +-- vecf32 +CREATE FUNCTION "vecf32_operator_gte"( + "lhs" vector, /* vectors::datatype::vecf32::Vecf32Input */ + "rhs" vector /* vectors::datatype::vecf32::Vecf32Input */ +) RETURNS bool /* bool */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'vecf32_operator_gte_wrapper'; + +-- src/datatype/operators_f32.rs:99 +-- vectors::datatype::operators_f32::vecf32_operator_gte +CREATE OPERATOR >= ( + PROCEDURE="vecf32_operator_gte", + LEFTARG=vector, /* vectors::datatype::vecf32::Vecf32Input */ + RIGHTARG=vector, /* vectors::datatype::vecf32::Vecf32Input */ + COMMUTATOR = <=, + NEGATOR = <, + RESTRICT = scalargtsel, + JOIN = scalargtjoinsel +); + +-- src/index/am.rs:33 +-- vectors::index::am::vectors_amhandler + + CREATE OR REPLACE FUNCTION vectors_amhandler(internal) RETURNS index_am_handler + PARALLEL SAFE IMMUTABLE STRICT LANGUAGE c AS 'MODULE_PATHNAME', 'vectors_amhandler_wrapper'; + + + + +-- src/datatype/operators_f32.rs:175 +-- vectors::datatype::operators_f32::vecf32_operator_l2 +-- requires: +-- vecf32 +CREATE FUNCTION "vecf32_operator_l2"( + "lhs" vector, /* vectors::datatype::vecf32::Vecf32Input */ + "rhs" vector /* vectors::datatype::vecf32::Vecf32Input */ +) RETURNS real /* f32 */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'vecf32_operator_l2_wrapper'; + +-- src/datatype/operators_f32.rs:175 +-- vectors::datatype::operators_f32::vecf32_operator_l2 +CREATE OPERATOR <-> ( + PROCEDURE="vecf32_operator_l2", + LEFTARG=vector, /* vectors::datatype::vecf32::Vecf32Input */ + RIGHTARG=vector, /* vectors::datatype::vecf32::Vecf32Input */ + COMMUTATOR = <-> +); + +-- src/datatype/operators_f32.rs:65 +-- vectors::datatype::operators_f32::vecf32_operator_lte +-- requires: +-- vecf32 +CREATE FUNCTION "vecf32_operator_lte"( + "lhs" vector, /* vectors::datatype::vecf32::Vecf32Input */ + "rhs" vector /* vectors::datatype::vecf32::Vecf32Input */ +) RETURNS bool /* bool */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'vecf32_operator_lte_wrapper'; + +-- src/datatype/operators_f32.rs:65 +-- vectors::datatype::operators_f32::vecf32_operator_lte +CREATE OPERATOR <= ( + PROCEDURE="vecf32_operator_lte", + LEFTARG=vector, /* vectors::datatype::vecf32::Vecf32Input */ + RIGHTARG=vector, /* vectors::datatype::vecf32::Vecf32Input */ + COMMUTATOR = >=, + NEGATOR = >, + RESTRICT = scalarltsel, + JOIN = scalarltjoinsel +); + +-- src/datatype/operators_f32.rs:26 +-- vectors::datatype::operators_f32::vecf32_operator_minus +-- requires: +-- vecf32 +CREATE FUNCTION "vecf32_operator_minus"( + "lhs" vector, /* vectors::datatype::vecf32::Vecf32Input */ + "rhs" vector /* vectors::datatype::vecf32::Vecf32Input */ +) RETURNS vector /* vectors::datatype::vecf32::Vecf32Output */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'vecf32_operator_minus_wrapper'; + +-- src/datatype/operators_f32.rs:26 +-- vectors::datatype::operators_f32::vecf32_operator_minus +CREATE OPERATOR - ( + PROCEDURE="vecf32_operator_minus", + LEFTARG=vector, /* vectors::datatype::vecf32::Vecf32Input */ + RIGHTARG=vector /* vectors::datatype::vecf32::Vecf32Input */ +); + +-- src/datatype/operators_f32.rs:82 +-- vectors::datatype::operators_f32::vecf32_operator_gt +-- requires: +-- vecf32 +CREATE FUNCTION "vecf32_operator_gt"( + "lhs" vector, /* vectors::datatype::vecf32::Vecf32Input */ + "rhs" vector /* vectors::datatype::vecf32::Vecf32Input */ +) RETURNS bool /* bool */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'vecf32_operator_gt_wrapper'; + +-- src/datatype/operators_f32.rs:82 +-- vectors::datatype::operators_f32::vecf32_operator_gt +CREATE OPERATOR > ( + PROCEDURE="vecf32_operator_gt", + LEFTARG=vector, /* vectors::datatype::vecf32::Vecf32Input */ + RIGHTARG=vector, /* vectors::datatype::vecf32::Vecf32Input */ + COMMUTATOR = <, + NEGATOR = <=, + RESTRICT = scalargtsel, + JOIN = scalargtjoinsel +); + +-- src/datatype/operators_f32.rs:161 +-- vectors::datatype::operators_f32::vecf32_operator_dot +-- requires: +-- vecf32 +CREATE FUNCTION "vecf32_operator_dot"( + "lhs" vector, /* vectors::datatype::vecf32::Vecf32Input */ + "rhs" vector /* vectors::datatype::vecf32::Vecf32Input */ +) RETURNS real /* f32 */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'vecf32_operator_dot_wrapper'; + +-- src/datatype/operators_f32.rs:161 +-- vectors::datatype::operators_f32::vecf32_operator_dot +CREATE OPERATOR <#> ( + PROCEDURE="vecf32_operator_dot", + LEFTARG=vector, /* vectors::datatype::vecf32::Vecf32Input */ + RIGHTARG=vector, /* vectors::datatype::vecf32::Vecf32Input */ + COMMUTATOR = <#> +); + +-- src/datatype/operators_f32.rs:8 +-- vectors::datatype::operators_f32::vecf32_operator_add +-- requires: +-- vecf32 +CREATE FUNCTION "vecf32_operator_add"( + "lhs" vector, /* vectors::datatype::vecf32::Vecf32Input */ + "rhs" vector /* vectors::datatype::vecf32::Vecf32Input */ +) RETURNS vector /* vectors::datatype::vecf32::Vecf32Output */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'vecf32_operator_add_wrapper'; + +-- src/datatype/operators_f32.rs:8 +-- vectors::datatype::operators_f32::vecf32_operator_add +CREATE OPERATOR + ( + PROCEDURE="vecf32_operator_add", + LEFTARG=vector, /* vectors::datatype::vecf32::Vecf32Input */ + RIGHTARG=vector, /* vectors::datatype::vecf32::Vecf32Input */ + COMMUTATOR = + +); + +-- src/datatype/operators_f32.rs:147 +-- vectors::datatype::operators_f32::vecf32_operator_cosine +-- requires: +-- vecf32 +CREATE FUNCTION "vecf32_operator_cosine"( + "lhs" vector, /* vectors::datatype::vecf32::Vecf32Input */ + "rhs" vector /* vectors::datatype::vecf32::Vecf32Input */ +) RETURNS real /* f32 */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'vecf32_operator_cosine_wrapper'; + +-- src/datatype/operators_f32.rs:147 +-- vectors::datatype::operators_f32::vecf32_operator_cosine +CREATE OPERATOR <=> ( + PROCEDURE="vecf32_operator_cosine", + LEFTARG=vector, /* vectors::datatype::vecf32::Vecf32Input */ + RIGHTARG=vector, /* vectors::datatype::vecf32::Vecf32Input */ + COMMUTATOR = <=> +); + +-- src/datatype/operators_f32.rs:133 +-- vectors::datatype::operators_f32::vecf32_operator_neq +-- requires: +-- vecf32 +CREATE FUNCTION "vecf32_operator_neq"( + "lhs" vector, /* vectors::datatype::vecf32::Vecf32Input */ + "rhs" vector /* vectors::datatype::vecf32::Vecf32Input */ +) RETURNS bool /* bool */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'vecf32_operator_neq_wrapper'; + +-- src/datatype/operators_f32.rs:133 +-- vectors::datatype::operators_f32::vecf32_operator_neq +CREATE OPERATOR <> ( + PROCEDURE="vecf32_operator_neq", + LEFTARG=vector, /* vectors::datatype::vecf32::Vecf32Input */ + RIGHTARG=vector, /* vectors::datatype::vecf32::Vecf32Input */ + COMMUTATOR = <>, + NEGATOR = =, + RESTRICT = eqsel, + JOIN = eqjoinsel +); + +-- src/datatype/operators_f32.rs:116 +-- vectors::datatype::operators_f32::vecf32_operator_eq +-- requires: +-- vecf32 +CREATE FUNCTION "vecf32_operator_eq"( + "lhs" vector, /* vectors::datatype::vecf32::Vecf32Input */ + "rhs" vector /* vectors::datatype::vecf32::Vecf32Input */ +) RETURNS bool /* bool */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'vecf32_operator_eq_wrapper'; + +-- src/datatype/operators_f32.rs:116 +-- vectors::datatype::operators_f32::vecf32_operator_eq +CREATE OPERATOR = ( + PROCEDURE="vecf32_operator_eq", + LEFTARG=vector, /* vectors::datatype::vecf32::Vecf32Input */ + RIGHTARG=vector, /* vectors::datatype::vecf32::Vecf32Input */ + COMMUTATOR = =, + NEGATOR = <>, + RESTRICT = eqsel, + JOIN = eqjoinsel +); + +-- src/index/views.rs:4 +CREATE TYPE VectorIndexStat AS ( + idx_indexing BOOL, + idx_tuples BIGINT, + idx_sealed BIGINT[], + idx_growing BIGINT[], + idx_write BIGINT, + idx_options TEXT +); + +-- src/lib.rs:19 +-- finalize +CREATE CAST (real[] AS vector) + WITH FUNCTION vecf32_cast_array_to_vector(real[], integer, boolean) AS IMPLICIT; + +CREATE CAST (vector AS real[]) + WITH FUNCTION vecf32_cast_vector_to_array(vector, integer, boolean) AS IMPLICIT; + +CREATE ACCESS METHOD vectors TYPE INDEX HANDLER vectors_amhandler; +COMMENT ON ACCESS METHOD vectors IS 'pgvecto.rs index access method'; + +CREATE OPERATOR CLASS vector_l2_ops + FOR TYPE vector USING vectors AS + OPERATOR 1 <-> (vector, vector) FOR ORDER BY float_ops; + +CREATE OPERATOR CLASS vector_dot_ops + FOR TYPE vector USING vectors AS + OPERATOR 1 <#> (vector, vector) FOR ORDER BY float_ops; + +CREATE OPERATOR CLASS vector_cos_ops + FOR TYPE vector USING vectors AS + OPERATOR 1 <=> (vector, vector) FOR ORDER BY float_ops; + +CREATE OPERATOR CLASS vecf16_l2_ops + FOR TYPE vecf16 USING vectors AS + OPERATOR 1 <-> (vecf16, vecf16) FOR ORDER BY float_ops; + +CREATE OPERATOR CLASS vecf16_dot_ops + FOR TYPE vecf16 USING vectors AS + OPERATOR 1 <#> (vecf16, vecf16) FOR ORDER BY float_ops; + +CREATE OPERATOR CLASS vecf16_cos_ops + FOR TYPE vecf16 USING vectors AS + OPERATOR 1 <=> (vecf16, vecf16) FOR ORDER BY float_ops; + +CREATE VIEW pg_vector_index_info AS + SELECT + C.oid AS tablerelid, + I.oid AS indexrelid, + C.relname AS tablename, + I.relname AS indexname, + (vector_stat(I.relfilenode)).* + FROM pg_class C JOIN + pg_index X ON C.oid = X.indrelid JOIN + pg_class I ON I.oid = X.indexrelid JOIN + pg_am A ON A.oid = I.relam + WHERE A.amname = 'vectors'; + diff --git a/sql/install/vectors--0.1.2.sql b/sql/install/vectors--0.1.2.sql new file mode 100644 index 000000000..696517c8a --- /dev/null +++ b/sql/install/vectors--0.1.2.sql @@ -0,0 +1,399 @@ +/* +This file is auto generated by pgrx. + +The ordering of items is not stable, it is driven by a dependency graph. +*/ + +-- src/lib.rs:25 +-- bootstrap +CREATE TYPE vector; + + +-- src/postgres/functions.rs:14 +-- vectors::postgres::functions::vectors_unload +CREATE FUNCTION "vectors_unload"( + "oid" oid /* pgrx_pg_sys::submodules::oids::Oid */ +) RETURNS void +STRICT +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'vectors_unload_wrapper'; + +-- src/postgres/functions.rs:5 +-- vectors::postgres::functions::vectors_load +CREATE FUNCTION "vectors_load"( + "oid" oid /* pgrx_pg_sys::submodules::oids::Oid */ +) RETURNS void +STRICT +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'vectors_load_wrapper'; + +-- src/postgres/datatype.rs:424 +-- vectors::postgres::datatype::vector_typmod_out +CREATE FUNCTION "vector_typmod_out"( + "typmod" INT /* i32 */ +) RETURNS cstring /* alloc::ffi::c_str::CString */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'vector_typmod_out_wrapper'; + +-- src/postgres/datatype.rs:411 +-- vectors::postgres::datatype::vector_typmod_in +CREATE FUNCTION "vector_typmod_in"( + "list" cstring[] /* pgrx::datum::array::Array<&core::ffi::c_str::CStr> */ +) RETURNS INT /* i32 */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'vector_typmod_in_wrapper'; + +-- src/postgres/datatype.rs:397 +-- vectors::postgres::datatype::vector_out +CREATE FUNCTION "vector_out"( + "vector" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS cstring /* alloc::ffi::c_str::CString */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'vector_out_wrapper'; + +-- src/postgres/datatype.rs:349 +-- vectors::postgres::datatype::vector_in +CREATE FUNCTION "vector_in"( + "input" cstring, /* &core::ffi::c_str::CStr */ + "_oid" oid, /* pgrx_pg_sys::submodules::oids::Oid */ + "typmod" INT /* i32 */ +) RETURNS vector /* vectors::postgres::datatype::VectorOutput */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'vector_in_wrapper'; + +-- src/postgres/casts.rs:17 +-- vectors::postgres::casts::cast_vector_to_array +CREATE FUNCTION "cast_vector_to_array"( + "vector" vector, /* vectors::postgres::datatype::VectorInput */ + "_typmod" INT, /* i32 */ + "_explicit" bool /* bool */ +) RETURNS real[] /* alloc::vec::Vec */ +STRICT +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'cast_vector_to_array_wrapper'; + +-- src/postgres/casts.rs:5 +-- vectors::postgres::casts::cast_array_to_vector +CREATE FUNCTION "cast_array_to_vector"( + "array" real[], /* pgrx::datum::array::Array */ + "typmod" INT, /* i32 */ + "_explicit" bool /* bool */ +) RETURNS vector /* vectors::postgres::datatype::VectorOutput */ +STRICT +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'cast_array_to_vector_wrapper'; + +-- src/embedding/udf.rs:11 +-- vectors::embedding::udf::ai_embedding_vector +CREATE FUNCTION "ai_embedding_vector"( + "input" TEXT /* alloc::string::String */ +) RETURNS vector /* vectors::postgres::datatype::VectorOutput */ +STRICT +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'ai_embedding_vector_wrapper'; + +-- src/postgres/datatype.rs:73 +-- creates: +-- Type(vectors::postgres::datatype::Vector) + +-- requires: +-- vector_in +-- vector_out +-- vector_typmod_in +-- vector_typmod_out + + +CREATE TYPE vector ( + INPUT = vector_in, + OUTPUT = vector_out, + TYPMOD_IN = vector_typmod_in, + TYPMOD_OUT = vector_typmod_out, + STORAGE = EXTENDED, + INTERNALLENGTH = VARIABLE, + ALIGNMENT = double +); + + +-- src/postgres/operators.rs:80 +-- vectors::postgres::operators::operator_eq +-- requires: +-- vector +CREATE FUNCTION "operator_eq"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS bool /* bool */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_eq_wrapper'; + +-- src/postgres/operators.rs:80 +-- vectors::postgres::operators::operator_eq +CREATE OPERATOR = ( + PROCEDURE="operator_eq", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector, /* vectors::postgres::datatype::VectorInput */ + COMMUTATOR = =, + NEGATOR = <>, + RESTRICT = eqsel, + JOIN = eqjoinsel +); + +-- src/postgres/operators.rs:91 +-- vectors::postgres::operators::operator_neq +-- requires: +-- vector +CREATE FUNCTION "operator_neq"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS bool /* bool */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_neq_wrapper'; + +-- src/postgres/operators.rs:91 +-- vectors::postgres::operators::operator_neq +CREATE OPERATOR <> ( + PROCEDURE="operator_neq", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector, /* vectors::postgres::datatype::VectorInput */ + COMMUTATOR = <>, + NEGATOR = =, + RESTRICT = eqsel, + JOIN = eqjoinsel +); + +-- src/postgres/operators.rs:8 +-- vectors::postgres::operators::operator_add +-- requires: +-- vector +CREATE FUNCTION "operator_add"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS vector /* vectors::postgres::datatype::VectorOutput */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_add_wrapper'; + +-- src/postgres/operators.rs:8 +-- vectors::postgres::operators::operator_add +CREATE OPERATOR + ( + PROCEDURE="operator_add", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector, /* vectors::postgres::datatype::VectorInput */ + COMMUTATOR = + +); + +-- src/postgres/operators.rs:20 +-- vectors::postgres::operators::operator_minus +-- requires: +-- vector +CREATE FUNCTION "operator_minus"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS vector /* vectors::postgres::datatype::VectorOutput */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_minus_wrapper'; + +-- src/postgres/operators.rs:20 +-- vectors::postgres::operators::operator_minus +CREATE OPERATOR - ( + PROCEDURE="operator_minus", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector /* vectors::postgres::datatype::VectorInput */ +); + +-- src/postgres/operators.rs:69 +-- vectors::postgres::operators::operator_gte +-- requires: +-- vector +CREATE FUNCTION "operator_gte"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS bool /* bool */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_gte_wrapper'; + +-- src/postgres/operators.rs:69 +-- vectors::postgres::operators::operator_gte +CREATE OPERATOR >= ( + PROCEDURE="operator_gte", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector, /* vectors::postgres::datatype::VectorInput */ + COMMUTATOR = <=, + NEGATOR = <, + RESTRICT = scalargtsel, + JOIN = scalargtjoinsel +); + +-- src/postgres/index.rs:34 +-- vectors::postgres::index::vectors_amhandler + + CREATE OR REPLACE FUNCTION vectors_amhandler(internal) RETURNS index_am_handler + PARALLEL SAFE IMMUTABLE STRICT LANGUAGE c AS 'MODULE_PATHNAME', 'vectors_amhandler_wrapper'; + CREATE ACCESS METHOD vectors TYPE INDEX HANDLER vectors_amhandler; + COMMENT ON ACCESS METHOD vectors IS 'pgvecto.rs index access method'; + + + + +-- src/postgres/operators.rs:99 +-- vectors::postgres::operators::operator_cosine +-- requires: +-- vector +CREATE FUNCTION "operator_cosine"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS real /* vectors::prelude::scalar::Scalar */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_cosine_wrapper'; + +-- src/postgres/operators.rs:99 +-- vectors::postgres::operators::operator_cosine +CREATE OPERATOR <=> ( + PROCEDURE="operator_cosine", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector, /* vectors::postgres::datatype::VectorInput */ + COMMUTATOR = <=> +); + +-- src/postgres/operators.rs:36 +-- vectors::postgres::operators::operator_lt +-- requires: +-- vector +CREATE FUNCTION "operator_lt"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS bool /* bool */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_lt_wrapper'; + +-- src/postgres/operators.rs:36 +-- vectors::postgres::operators::operator_lt +CREATE OPERATOR < ( + PROCEDURE="operator_lt", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector, /* vectors::postgres::datatype::VectorInput */ + COMMUTATOR = >, + NEGATOR = >=, + RESTRICT = scalarltsel, + JOIN = scalarltjoinsel +); + +-- src/postgres/operators.rs:47 +-- vectors::postgres::operators::operator_lte +-- requires: +-- vector +CREATE FUNCTION "operator_lte"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS bool /* bool */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_lte_wrapper'; + +-- src/postgres/operators.rs:47 +-- vectors::postgres::operators::operator_lte +CREATE OPERATOR <= ( + PROCEDURE="operator_lte", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector, /* vectors::postgres::datatype::VectorInput */ + COMMUTATOR = >=, + NEGATOR = >, + RESTRICT = scalarltsel, + JOIN = scalarltjoinsel +); + +-- src/postgres/operators.rs:107 +-- vectors::postgres::operators::operator_dot +-- requires: +-- vector +CREATE FUNCTION "operator_dot"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS real /* vectors::prelude::scalar::Scalar */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_dot_wrapper'; + +-- src/postgres/operators.rs:107 +-- vectors::postgres::operators::operator_dot +CREATE OPERATOR <#> ( + PROCEDURE="operator_dot", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector, /* vectors::postgres::datatype::VectorInput */ + COMMUTATOR = <#> +); + +-- src/postgres/operators.rs:58 +-- vectors::postgres::operators::operator_gt +-- requires: +-- vector +CREATE FUNCTION "operator_gt"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS bool /* bool */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_gt_wrapper'; + +-- src/postgres/operators.rs:58 +-- vectors::postgres::operators::operator_gt +CREATE OPERATOR > ( + PROCEDURE="operator_gt", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector, /* vectors::postgres::datatype::VectorInput */ + COMMUTATOR = <, + NEGATOR = <=, + RESTRICT = scalargtsel, + JOIN = scalargtjoinsel +); + +-- src/postgres/operators.rs:115 +-- vectors::postgres::operators::operator_l2 +-- requires: +-- vector +CREATE FUNCTION "operator_l2"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS real /* vectors::prelude::scalar::Scalar */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_l2_wrapper'; + +-- src/postgres/operators.rs:115 +-- vectors::postgres::operators::operator_l2 +CREATE OPERATOR <-> ( + PROCEDURE="operator_l2", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector, /* vectors::postgres::datatype::VectorInput */ + COMMUTATOR = <-> +); + +-- src/lib.rs:26 +-- finalize +CREATE CAST (real[] AS vector) + WITH FUNCTION cast_array_to_vector(real[], integer, boolean) AS IMPLICIT; + +CREATE CAST (vector AS real[]) + WITH FUNCTION cast_vector_to_array(vector, integer, boolean) AS IMPLICIT; + +CREATE OPERATOR CLASS l2_ops + FOR TYPE vector USING vectors AS + OPERATOR 1 <-> (vector, vector) FOR ORDER BY float_ops; + +CREATE OPERATOR CLASS dot_ops + FOR TYPE vector USING vectors AS + OPERATOR 1 <#> (vector, vector) FOR ORDER BY float_ops; + +CREATE OPERATOR CLASS cosine_ops + FOR TYPE vector USING vectors AS + OPERATOR 1 <=> (vector, vector) FOR ORDER BY float_ops; + diff --git a/sql/install/vectors--0.1.3.sql b/sql/install/vectors--0.1.3.sql new file mode 100644 index 000000000..1cb6c35d1 --- /dev/null +++ b/sql/install/vectors--0.1.3.sql @@ -0,0 +1,399 @@ +/* +This file is auto generated by pgrx. + +The ordering of items is not stable, it is driven by a dependency graph. +*/ + +-- src/lib.rs:25 +-- bootstrap +CREATE TYPE vector; + + +-- src/postgres/functions.rs:14 +-- vectors::postgres::functions::vectors_unload +CREATE FUNCTION "vectors_unload"( + "oid" oid /* pgrx_pg_sys::submodules::oids::Oid */ +) RETURNS void +STRICT +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'vectors_unload_wrapper'; + +-- src/postgres/functions.rs:5 +-- vectors::postgres::functions::vectors_load +CREATE FUNCTION "vectors_load"( + "oid" oid /* pgrx_pg_sys::submodules::oids::Oid */ +) RETURNS void +STRICT +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'vectors_load_wrapper'; + +-- src/postgres/datatype.rs:424 +-- vectors::postgres::datatype::vector_typmod_out +CREATE FUNCTION "vector_typmod_out"( + "typmod" INT /* i32 */ +) RETURNS cstring /* alloc::ffi::c_str::CString */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'vector_typmod_out_wrapper'; + +-- src/postgres/datatype.rs:411 +-- vectors::postgres::datatype::vector_typmod_in +CREATE FUNCTION "vector_typmod_in"( + "list" cstring[] /* pgrx::datum::array::Array<&core::ffi::c_str::CStr> */ +) RETURNS INT /* i32 */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'vector_typmod_in_wrapper'; + +-- src/postgres/datatype.rs:397 +-- vectors::postgres::datatype::vector_out +CREATE FUNCTION "vector_out"( + "vector" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS cstring /* alloc::ffi::c_str::CString */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'vector_out_wrapper'; + +-- src/postgres/datatype.rs:349 +-- vectors::postgres::datatype::vector_in +CREATE FUNCTION "vector_in"( + "input" cstring, /* &core::ffi::c_str::CStr */ + "_oid" oid, /* pgrx_pg_sys::submodules::oids::Oid */ + "typmod" INT /* i32 */ +) RETURNS vector /* vectors::postgres::datatype::VectorOutput */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'vector_in_wrapper'; + +-- src/postgres/casts.rs:17 +-- vectors::postgres::casts::cast_vector_to_array +CREATE FUNCTION "cast_vector_to_array"( + "vector" vector, /* vectors::postgres::datatype::VectorInput */ + "_typmod" INT, /* i32 */ + "_explicit" bool /* bool */ +) RETURNS real[] /* alloc::vec::Vec */ +STRICT +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'cast_vector_to_array_wrapper'; + +-- src/postgres/casts.rs:5 +-- vectors::postgres::casts::cast_array_to_vector +CREATE FUNCTION "cast_array_to_vector"( + "array" real[], /* pgrx::datum::array::Array */ + "typmod" INT, /* i32 */ + "_explicit" bool /* bool */ +) RETURNS vector /* vectors::postgres::datatype::VectorOutput */ +STRICT +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'cast_array_to_vector_wrapper'; + +-- src/embedding/udf.rs:11 +-- vectors::embedding::udf::ai_embedding_vector +CREATE FUNCTION "ai_embedding_vector"( + "input" TEXT /* alloc::string::String */ +) RETURNS vector /* vectors::postgres::datatype::VectorOutput */ +STRICT +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'ai_embedding_vector_wrapper'; + +-- src/postgres/datatype.rs:73 +-- creates: +-- Type(vectors::postgres::datatype::Vector) + +-- requires: +-- vector_in +-- vector_out +-- vector_typmod_in +-- vector_typmod_out + + +CREATE TYPE vector ( + INPUT = vector_in, + OUTPUT = vector_out, + TYPMOD_IN = vector_typmod_in, + TYPMOD_OUT = vector_typmod_out, + STORAGE = EXTENDED, + INTERNALLENGTH = VARIABLE, + ALIGNMENT = double +); + + +-- src/postgres/operators.rs:47 +-- vectors::postgres::operators::operator_lte +-- requires: +-- vector +CREATE FUNCTION "operator_lte"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS bool /* bool */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_lte_wrapper'; + +-- src/postgres/operators.rs:47 +-- vectors::postgres::operators::operator_lte +CREATE OPERATOR <= ( + PROCEDURE="operator_lte", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector, /* vectors::postgres::datatype::VectorInput */ + COMMUTATOR = >=, + NEGATOR = >, + RESTRICT = scalarltsel, + JOIN = scalarltjoinsel +); + +-- src/postgres/operators.rs:99 +-- vectors::postgres::operators::operator_cosine +-- requires: +-- vector +CREATE FUNCTION "operator_cosine"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS real /* vectors::prelude::scalar::Scalar */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_cosine_wrapper'; + +-- src/postgres/operators.rs:99 +-- vectors::postgres::operators::operator_cosine +CREATE OPERATOR <=> ( + PROCEDURE="operator_cosine", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector, /* vectors::postgres::datatype::VectorInput */ + COMMUTATOR = <=> +); + +-- src/postgres/operators.rs:8 +-- vectors::postgres::operators::operator_add +-- requires: +-- vector +CREATE FUNCTION "operator_add"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS vector /* vectors::postgres::datatype::VectorOutput */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_add_wrapper'; + +-- src/postgres/operators.rs:8 +-- vectors::postgres::operators::operator_add +CREATE OPERATOR + ( + PROCEDURE="operator_add", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector, /* vectors::postgres::datatype::VectorInput */ + COMMUTATOR = + +); + +-- src/postgres/index.rs:34 +-- vectors::postgres::index::vectors_amhandler + + CREATE OR REPLACE FUNCTION vectors_amhandler(internal) RETURNS index_am_handler + PARALLEL SAFE IMMUTABLE STRICT LANGUAGE c AS 'MODULE_PATHNAME', 'vectors_amhandler_wrapper'; + CREATE ACCESS METHOD vectors TYPE INDEX HANDLER vectors_amhandler; + COMMENT ON ACCESS METHOD vectors IS 'pgvecto.rs index access method'; + + + + +-- src/postgres/operators.rs:58 +-- vectors::postgres::operators::operator_gt +-- requires: +-- vector +CREATE FUNCTION "operator_gt"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS bool /* bool */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_gt_wrapper'; + +-- src/postgres/operators.rs:58 +-- vectors::postgres::operators::operator_gt +CREATE OPERATOR > ( + PROCEDURE="operator_gt", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector, /* vectors::postgres::datatype::VectorInput */ + COMMUTATOR = <, + NEGATOR = <=, + RESTRICT = scalargtsel, + JOIN = scalargtjoinsel +); + +-- src/postgres/operators.rs:20 +-- vectors::postgres::operators::operator_minus +-- requires: +-- vector +CREATE FUNCTION "operator_minus"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS vector /* vectors::postgres::datatype::VectorOutput */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_minus_wrapper'; + +-- src/postgres/operators.rs:20 +-- vectors::postgres::operators::operator_minus +CREATE OPERATOR - ( + PROCEDURE="operator_minus", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector /* vectors::postgres::datatype::VectorInput */ +); + +-- src/postgres/operators.rs:80 +-- vectors::postgres::operators::operator_eq +-- requires: +-- vector +CREATE FUNCTION "operator_eq"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS bool /* bool */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_eq_wrapper'; + +-- src/postgres/operators.rs:80 +-- vectors::postgres::operators::operator_eq +CREATE OPERATOR = ( + PROCEDURE="operator_eq", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector, /* vectors::postgres::datatype::VectorInput */ + COMMUTATOR = =, + NEGATOR = <>, + RESTRICT = eqsel, + JOIN = eqjoinsel +); + +-- src/postgres/operators.rs:91 +-- vectors::postgres::operators::operator_neq +-- requires: +-- vector +CREATE FUNCTION "operator_neq"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS bool /* bool */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_neq_wrapper'; + +-- src/postgres/operators.rs:91 +-- vectors::postgres::operators::operator_neq +CREATE OPERATOR <> ( + PROCEDURE="operator_neq", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector, /* vectors::postgres::datatype::VectorInput */ + COMMUTATOR = <>, + NEGATOR = =, + RESTRICT = eqsel, + JOIN = eqjoinsel +); + +-- src/postgres/operators.rs:69 +-- vectors::postgres::operators::operator_gte +-- requires: +-- vector +CREATE FUNCTION "operator_gte"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS bool /* bool */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_gte_wrapper'; + +-- src/postgres/operators.rs:69 +-- vectors::postgres::operators::operator_gte +CREATE OPERATOR >= ( + PROCEDURE="operator_gte", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector, /* vectors::postgres::datatype::VectorInput */ + COMMUTATOR = <=, + NEGATOR = <, + RESTRICT = scalargtsel, + JOIN = scalargtjoinsel +); + +-- src/postgres/operators.rs:115 +-- vectors::postgres::operators::operator_l2 +-- requires: +-- vector +CREATE FUNCTION "operator_l2"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS real /* vectors::prelude::scalar::Scalar */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_l2_wrapper'; + +-- src/postgres/operators.rs:115 +-- vectors::postgres::operators::operator_l2 +CREATE OPERATOR <-> ( + PROCEDURE="operator_l2", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector, /* vectors::postgres::datatype::VectorInput */ + COMMUTATOR = <-> +); + +-- src/postgres/operators.rs:36 +-- vectors::postgres::operators::operator_lt +-- requires: +-- vector +CREATE FUNCTION "operator_lt"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS bool /* bool */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_lt_wrapper'; + +-- src/postgres/operators.rs:36 +-- vectors::postgres::operators::operator_lt +CREATE OPERATOR < ( + PROCEDURE="operator_lt", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector, /* vectors::postgres::datatype::VectorInput */ + COMMUTATOR = >, + NEGATOR = >=, + RESTRICT = scalarltsel, + JOIN = scalarltjoinsel +); + +-- src/postgres/operators.rs:107 +-- vectors::postgres::operators::operator_dot +-- requires: +-- vector +CREATE FUNCTION "operator_dot"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS real /* vectors::prelude::scalar::Scalar */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_dot_wrapper'; + +-- src/postgres/operators.rs:107 +-- vectors::postgres::operators::operator_dot +CREATE OPERATOR <#> ( + PROCEDURE="operator_dot", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector, /* vectors::postgres::datatype::VectorInput */ + COMMUTATOR = <#> +); + +-- src/lib.rs:26 +-- finalize +CREATE CAST (real[] AS vector) + WITH FUNCTION cast_array_to_vector(real[], integer, boolean) AS IMPLICIT; + +CREATE CAST (vector AS real[]) + WITH FUNCTION cast_vector_to_array(vector, integer, boolean) AS IMPLICIT; + +CREATE OPERATOR CLASS l2_ops + FOR TYPE vector USING vectors AS + OPERATOR 1 <-> (vector, vector) FOR ORDER BY float_ops; + +CREATE OPERATOR CLASS dot_ops + FOR TYPE vector USING vectors AS + OPERATOR 1 <#> (vector, vector) FOR ORDER BY float_ops; + +CREATE OPERATOR CLASS cosine_ops + FOR TYPE vector USING vectors AS + OPERATOR 1 <=> (vector, vector) FOR ORDER BY float_ops; + diff --git a/sql/install/vectors--0.1.4.sql b/sql/install/vectors--0.1.4.sql new file mode 100644 index 000000000..42e3fd9ea --- /dev/null +++ b/sql/install/vectors--0.1.4.sql @@ -0,0 +1,399 @@ +/* +This file is auto generated by pgrx. + +The ordering of items is not stable, it is driven by a dependency graph. +*/ + +-- src/lib.rs:25 +-- bootstrap +CREATE TYPE vector; + + +-- src/postgres/functions.rs:14 +-- vectors::postgres::functions::vectors_unload +CREATE FUNCTION "vectors_unload"( + "oid" oid /* pgrx_pg_sys::submodules::oids::Oid */ +) RETURNS void +STRICT +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'vectors_unload_wrapper'; + +-- src/postgres/functions.rs:5 +-- vectors::postgres::functions::vectors_load +CREATE FUNCTION "vectors_load"( + "oid" oid /* pgrx_pg_sys::submodules::oids::Oid */ +) RETURNS void +STRICT +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'vectors_load_wrapper'; + +-- src/postgres/datatype.rs:424 +-- vectors::postgres::datatype::vector_typmod_out +CREATE FUNCTION "vector_typmod_out"( + "typmod" INT /* i32 */ +) RETURNS cstring /* alloc::ffi::c_str::CString */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'vector_typmod_out_wrapper'; + +-- src/postgres/datatype.rs:411 +-- vectors::postgres::datatype::vector_typmod_in +CREATE FUNCTION "vector_typmod_in"( + "list" cstring[] /* pgrx::datum::array::Array<&core::ffi::c_str::CStr> */ +) RETURNS INT /* i32 */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'vector_typmod_in_wrapper'; + +-- src/postgres/datatype.rs:397 +-- vectors::postgres::datatype::vector_out +CREATE FUNCTION "vector_out"( + "vector" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS cstring /* alloc::ffi::c_str::CString */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'vector_out_wrapper'; + +-- src/postgres/datatype.rs:349 +-- vectors::postgres::datatype::vector_in +CREATE FUNCTION "vector_in"( + "input" cstring, /* &core::ffi::c_str::CStr */ + "_oid" oid, /* pgrx_pg_sys::submodules::oids::Oid */ + "typmod" INT /* i32 */ +) RETURNS vector /* vectors::postgres::datatype::VectorOutput */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'vector_in_wrapper'; + +-- src/postgres/casts.rs:17 +-- vectors::postgres::casts::cast_vector_to_array +CREATE FUNCTION "cast_vector_to_array"( + "vector" vector, /* vectors::postgres::datatype::VectorInput */ + "_typmod" INT, /* i32 */ + "_explicit" bool /* bool */ +) RETURNS real[] /* alloc::vec::Vec */ +STRICT +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'cast_vector_to_array_wrapper'; + +-- src/postgres/casts.rs:5 +-- vectors::postgres::casts::cast_array_to_vector +CREATE FUNCTION "cast_array_to_vector"( + "array" real[], /* pgrx::datum::array::Array */ + "typmod" INT, /* i32 */ + "_explicit" bool /* bool */ +) RETURNS vector /* vectors::postgres::datatype::VectorOutput */ +STRICT +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'cast_array_to_vector_wrapper'; + +-- src/embedding/udf.rs:11 +-- vectors::embedding::udf::ai_embedding_vector +CREATE FUNCTION "ai_embedding_vector"( + "input" TEXT /* alloc::string::String */ +) RETURNS vector /* vectors::postgres::datatype::VectorOutput */ +STRICT +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'ai_embedding_vector_wrapper'; + +-- src/postgres/datatype.rs:73 +-- creates: +-- Type(vectors::postgres::datatype::Vector) + +-- requires: +-- vector_in +-- vector_out +-- vector_typmod_in +-- vector_typmod_out + + +CREATE TYPE vector ( + INPUT = vector_in, + OUTPUT = vector_out, + TYPMOD_IN = vector_typmod_in, + TYPMOD_OUT = vector_typmod_out, + STORAGE = EXTENDED, + INTERNALLENGTH = VARIABLE, + ALIGNMENT = double +); + + +-- src/postgres/operators.rs:91 +-- vectors::postgres::operators::operator_neq +-- requires: +-- vector +CREATE FUNCTION "operator_neq"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS bool /* bool */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_neq_wrapper'; + +-- src/postgres/operators.rs:91 +-- vectors::postgres::operators::operator_neq +CREATE OPERATOR <> ( + PROCEDURE="operator_neq", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector, /* vectors::postgres::datatype::VectorInput */ + COMMUTATOR = <>, + NEGATOR = =, + RESTRICT = eqsel, + JOIN = eqjoinsel +); + +-- src/postgres/operators.rs:20 +-- vectors::postgres::operators::operator_minus +-- requires: +-- vector +CREATE FUNCTION "operator_minus"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS vector /* vectors::postgres::datatype::VectorOutput */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_minus_wrapper'; + +-- src/postgres/operators.rs:20 +-- vectors::postgres::operators::operator_minus +CREATE OPERATOR - ( + PROCEDURE="operator_minus", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector /* vectors::postgres::datatype::VectorInput */ +); + +-- src/postgres/operators.rs:47 +-- vectors::postgres::operators::operator_lte +-- requires: +-- vector +CREATE FUNCTION "operator_lte"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS bool /* bool */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_lte_wrapper'; + +-- src/postgres/operators.rs:47 +-- vectors::postgres::operators::operator_lte +CREATE OPERATOR <= ( + PROCEDURE="operator_lte", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector, /* vectors::postgres::datatype::VectorInput */ + COMMUTATOR = >=, + NEGATOR = >, + RESTRICT = scalarltsel, + JOIN = scalarltjoinsel +); + +-- src/postgres/operators.rs:8 +-- vectors::postgres::operators::operator_add +-- requires: +-- vector +CREATE FUNCTION "operator_add"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS vector /* vectors::postgres::datatype::VectorOutput */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_add_wrapper'; + +-- src/postgres/operators.rs:8 +-- vectors::postgres::operators::operator_add +CREATE OPERATOR + ( + PROCEDURE="operator_add", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector, /* vectors::postgres::datatype::VectorInput */ + COMMUTATOR = + +); + +-- src/postgres/index.rs:35 +-- vectors::postgres::index::vectors_amhandler + + CREATE OR REPLACE FUNCTION vectors_amhandler(internal) RETURNS index_am_handler + PARALLEL SAFE IMMUTABLE STRICT LANGUAGE c AS 'MODULE_PATHNAME', 'vectors_amhandler_wrapper'; + CREATE ACCESS METHOD vectors TYPE INDEX HANDLER vectors_amhandler; + COMMENT ON ACCESS METHOD vectors IS 'pgvecto.rs index access method'; + + + + +-- src/postgres/operators.rs:58 +-- vectors::postgres::operators::operator_gt +-- requires: +-- vector +CREATE FUNCTION "operator_gt"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS bool /* bool */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_gt_wrapper'; + +-- src/postgres/operators.rs:58 +-- vectors::postgres::operators::operator_gt +CREATE OPERATOR > ( + PROCEDURE="operator_gt", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector, /* vectors::postgres::datatype::VectorInput */ + COMMUTATOR = <, + NEGATOR = <=, + RESTRICT = scalargtsel, + JOIN = scalargtjoinsel +); + +-- src/postgres/operators.rs:36 +-- vectors::postgres::operators::operator_lt +-- requires: +-- vector +CREATE FUNCTION "operator_lt"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS bool /* bool */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_lt_wrapper'; + +-- src/postgres/operators.rs:36 +-- vectors::postgres::operators::operator_lt +CREATE OPERATOR < ( + PROCEDURE="operator_lt", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector, /* vectors::postgres::datatype::VectorInput */ + COMMUTATOR = >, + NEGATOR = >=, + RESTRICT = scalarltsel, + JOIN = scalarltjoinsel +); + +-- src/postgres/operators.rs:69 +-- vectors::postgres::operators::operator_gte +-- requires: +-- vector +CREATE FUNCTION "operator_gte"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS bool /* bool */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_gte_wrapper'; + +-- src/postgres/operators.rs:69 +-- vectors::postgres::operators::operator_gte +CREATE OPERATOR >= ( + PROCEDURE="operator_gte", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector, /* vectors::postgres::datatype::VectorInput */ + COMMUTATOR = <=, + NEGATOR = <, + RESTRICT = scalargtsel, + JOIN = scalargtjoinsel +); + +-- src/postgres/operators.rs:99 +-- vectors::postgres::operators::operator_cosine +-- requires: +-- vector +CREATE FUNCTION "operator_cosine"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS real /* vectors::prelude::scalar::Scalar */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_cosine_wrapper'; + +-- src/postgres/operators.rs:99 +-- vectors::postgres::operators::operator_cosine +CREATE OPERATOR <=> ( + PROCEDURE="operator_cosine", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector, /* vectors::postgres::datatype::VectorInput */ + COMMUTATOR = <=> +); + +-- src/postgres/operators.rs:107 +-- vectors::postgres::operators::operator_dot +-- requires: +-- vector +CREATE FUNCTION "operator_dot"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS real /* vectors::prelude::scalar::Scalar */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_dot_wrapper'; + +-- src/postgres/operators.rs:107 +-- vectors::postgres::operators::operator_dot +CREATE OPERATOR <#> ( + PROCEDURE="operator_dot", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector, /* vectors::postgres::datatype::VectorInput */ + COMMUTATOR = <#> +); + +-- src/postgres/operators.rs:115 +-- vectors::postgres::operators::operator_l2 +-- requires: +-- vector +CREATE FUNCTION "operator_l2"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS real /* vectors::prelude::scalar::Scalar */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_l2_wrapper'; + +-- src/postgres/operators.rs:115 +-- vectors::postgres::operators::operator_l2 +CREATE OPERATOR <-> ( + PROCEDURE="operator_l2", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector, /* vectors::postgres::datatype::VectorInput */ + COMMUTATOR = <-> +); + +-- src/postgres/operators.rs:80 +-- vectors::postgres::operators::operator_eq +-- requires: +-- vector +CREATE FUNCTION "operator_eq"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS bool /* bool */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_eq_wrapper'; + +-- src/postgres/operators.rs:80 +-- vectors::postgres::operators::operator_eq +CREATE OPERATOR = ( + PROCEDURE="operator_eq", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector, /* vectors::postgres::datatype::VectorInput */ + COMMUTATOR = =, + NEGATOR = <>, + RESTRICT = eqsel, + JOIN = eqjoinsel +); + +-- src/lib.rs:26 +-- finalize +CREATE CAST (real[] AS vector) + WITH FUNCTION cast_array_to_vector(real[], integer, boolean) AS IMPLICIT; + +CREATE CAST (vector AS real[]) + WITH FUNCTION cast_vector_to_array(vector, integer, boolean) AS IMPLICIT; + +CREATE OPERATOR CLASS l2_ops + FOR TYPE vector USING vectors AS + OPERATOR 1 <-> (vector, vector) FOR ORDER BY float_ops; + +CREATE OPERATOR CLASS dot_ops + FOR TYPE vector USING vectors AS + OPERATOR 1 <#> (vector, vector) FOR ORDER BY float_ops; + +CREATE OPERATOR CLASS cosine_ops + FOR TYPE vector USING vectors AS + OPERATOR 1 <=> (vector, vector) FOR ORDER BY float_ops; + diff --git a/sql/install/vectors--0.1.5.sql b/sql/install/vectors--0.1.5.sql new file mode 100644 index 000000000..2961bed10 --- /dev/null +++ b/sql/install/vectors--0.1.5.sql @@ -0,0 +1,381 @@ +/* +This file is auto generated by pgrx. + +The ordering of items is not stable, it is driven by a dependency graph. +*/ + +-- src/lib.rs:30 +-- bootstrap +CREATE TYPE vector; + + +-- src/postgres/datatype.rs:424 +-- vectors::postgres::datatype::vector_typmod_out +CREATE FUNCTION tensorchord."vector_typmod_out"( + "typmod" INT /* i32 */ +) RETURNS cstring /* alloc::ffi::c_str::CString */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'vector_typmod_out_wrapper'; + +-- src/postgres/datatype.rs:411 +-- vectors::postgres::datatype::vector_typmod_in +CREATE FUNCTION tensorchord."vector_typmod_in"( + "list" cstring[] /* pgrx::datum::array::Array<&core::ffi::c_str::CStr> */ +) RETURNS INT /* i32 */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'vector_typmod_in_wrapper'; + +-- src/postgres/datatype.rs:397 +-- vectors::postgres::datatype::vector_out +CREATE FUNCTION tensorchord."vector_out"( + "vector" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS cstring /* alloc::ffi::c_str::CString */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'vector_out_wrapper'; + +-- src/postgres/datatype.rs:349 +-- vectors::postgres::datatype::vector_in +CREATE FUNCTION tensorchord."vector_in"( + "input" cstring, /* &core::ffi::c_str::CStr */ + "_oid" oid, /* pgrx_pg_sys::submodules::oids::Oid */ + "typmod" INT /* i32 */ +) RETURNS vector /* vectors::postgres::datatype::VectorOutput */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'vector_in_wrapper'; + +-- src/postgres/casts.rs:17 +-- vectors::postgres::casts::cast_vector_to_array +CREATE FUNCTION tensorchord."cast_vector_to_array"( + "vector" vector, /* vectors::postgres::datatype::VectorInput */ + "_typmod" INT, /* i32 */ + "_explicit" bool /* bool */ +) RETURNS real[] /* alloc::vec::Vec */ +STRICT +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'cast_vector_to_array_wrapper'; + +-- src/postgres/casts.rs:5 +-- vectors::postgres::casts::cast_array_to_vector +CREATE FUNCTION tensorchord."cast_array_to_vector"( + "array" real[], /* pgrx::datum::array::Array */ + "typmod" INT, /* i32 */ + "_explicit" bool /* bool */ +) RETURNS vector /* vectors::postgres::datatype::VectorOutput */ +STRICT +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'cast_array_to_vector_wrapper'; + +-- src/embedding/udf.rs:11 +-- vectors::embedding::udf::ai_embedding_vector +CREATE FUNCTION tensorchord."ai_embedding_vector"( + "input" TEXT /* alloc::string::String */ +) RETURNS vector /* vectors::postgres::datatype::VectorOutput */ +STRICT +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'ai_embedding_vector_wrapper'; + +-- src/postgres/datatype.rs:73 +-- creates: +-- Type(vectors::postgres::datatype::Vector) + +-- requires: +-- vector_in +-- vector_out +-- vector_typmod_in +-- vector_typmod_out + + +CREATE TYPE vector ( + INPUT = vector_in, + OUTPUT = vector_out, + TYPMOD_IN = vector_typmod_in, + TYPMOD_OUT = vector_typmod_out, + STORAGE = EXTENDED, + INTERNALLENGTH = VARIABLE, + ALIGNMENT = double +); + + +-- src/postgres/operators.rs:36 +-- vectors::postgres::operators::operator_lt +-- requires: +-- vector +CREATE FUNCTION tensorchord."operator_lt"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS bool /* bool */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_lt_wrapper'; + +-- src/postgres/operators.rs:36 +-- vectors::postgres::operators::operator_lt +CREATE OPERATOR tensorchord.< ( + PROCEDURE=tensorchord."operator_lt", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector, /* vectors::postgres::datatype::VectorInput */ + COMMUTATOR = >, + NEGATOR = >=, + RESTRICT = scalarltsel, + JOIN = scalarltjoinsel +); + +-- src/postgres/operators.rs:20 +-- vectors::postgres::operators::operator_minus +-- requires: +-- vector +CREATE FUNCTION tensorchord."operator_minus"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS vector /* vectors::postgres::datatype::VectorOutput */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_minus_wrapper'; + +-- src/postgres/operators.rs:20 +-- vectors::postgres::operators::operator_minus +CREATE OPERATOR tensorchord.- ( + PROCEDURE=tensorchord."operator_minus", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector /* vectors::postgres::datatype::VectorInput */ +); + +-- src/postgres/operators.rs:80 +-- vectors::postgres::operators::operator_eq +-- requires: +-- vector +CREATE FUNCTION tensorchord."operator_eq"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS bool /* bool */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_eq_wrapper'; + +-- src/postgres/operators.rs:80 +-- vectors::postgres::operators::operator_eq +CREATE OPERATOR tensorchord.= ( + PROCEDURE=tensorchord."operator_eq", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector, /* vectors::postgres::datatype::VectorInput */ + COMMUTATOR = =, + NEGATOR = <>, + RESTRICT = eqsel, + JOIN = eqjoinsel +); + +-- src/postgres/operators.rs:69 +-- vectors::postgres::operators::operator_gte +-- requires: +-- vector +CREATE FUNCTION tensorchord."operator_gte"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS bool /* bool */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_gte_wrapper'; + +-- src/postgres/operators.rs:69 +-- vectors::postgres::operators::operator_gte +CREATE OPERATOR tensorchord.>= ( + PROCEDURE=tensorchord."operator_gte", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector, /* vectors::postgres::datatype::VectorInput */ + COMMUTATOR = <=, + NEGATOR = <, + RESTRICT = scalargtsel, + JOIN = scalargtjoinsel +); + +-- src/postgres/operators.rs:8 +-- vectors::postgres::operators::operator_add +-- requires: +-- vector +CREATE FUNCTION tensorchord."operator_add"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS vector /* vectors::postgres::datatype::VectorOutput */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_add_wrapper'; + +-- src/postgres/operators.rs:8 +-- vectors::postgres::operators::operator_add +CREATE OPERATOR tensorchord.+ ( + PROCEDURE=tensorchord."operator_add", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector, /* vectors::postgres::datatype::VectorInput */ + COMMUTATOR = + +); + +-- src/postgres/operators.rs:47 +-- vectors::postgres::operators::operator_lte +-- requires: +-- vector +CREATE FUNCTION tensorchord."operator_lte"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS bool /* bool */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_lte_wrapper'; + +-- src/postgres/operators.rs:47 +-- vectors::postgres::operators::operator_lte +CREATE OPERATOR tensorchord.<= ( + PROCEDURE=tensorchord."operator_lte", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector, /* vectors::postgres::datatype::VectorInput */ + COMMUTATOR = >=, + NEGATOR = >, + RESTRICT = scalarltsel, + JOIN = scalarltjoinsel +); + +-- src/postgres/operators.rs:91 +-- vectors::postgres::operators::operator_neq +-- requires: +-- vector +CREATE FUNCTION tensorchord."operator_neq"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS bool /* bool */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_neq_wrapper'; + +-- src/postgres/operators.rs:91 +-- vectors::postgres::operators::operator_neq +CREATE OPERATOR tensorchord.<> ( + PROCEDURE=tensorchord."operator_neq", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector, /* vectors::postgres::datatype::VectorInput */ + COMMUTATOR = <>, + NEGATOR = =, + RESTRICT = eqsel, + JOIN = eqjoinsel +); + +-- src/postgres/operators.rs:107 +-- vectors::postgres::operators::operator_dot +-- requires: +-- vector +CREATE FUNCTION tensorchord."operator_dot"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS real /* vectors::prelude::scalar::Scalar */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_dot_wrapper'; + +-- src/postgres/operators.rs:107 +-- vectors::postgres::operators::operator_dot +CREATE OPERATOR tensorchord.<#> ( + PROCEDURE=tensorchord."operator_dot", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector, /* vectors::postgres::datatype::VectorInput */ + COMMUTATOR = <#> +); + +-- src/postgres/operators.rs:58 +-- vectors::postgres::operators::operator_gt +-- requires: +-- vector +CREATE FUNCTION tensorchord."operator_gt"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS bool /* bool */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_gt_wrapper'; + +-- src/postgres/operators.rs:58 +-- vectors::postgres::operators::operator_gt +CREATE OPERATOR tensorchord.> ( + PROCEDURE=tensorchord."operator_gt", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector, /* vectors::postgres::datatype::VectorInput */ + COMMUTATOR = <, + NEGATOR = <=, + RESTRICT = scalargtsel, + JOIN = scalargtjoinsel +); + +-- src/postgres/index.rs:35 +-- vectors::postgres::index::vectors_amhandler + + CREATE OR REPLACE FUNCTION vectors_amhandler(internal) RETURNS index_am_handler + PARALLEL SAFE IMMUTABLE STRICT LANGUAGE c AS 'MODULE_PATHNAME', 'vectors_amhandler_wrapper'; + CREATE ACCESS METHOD vectors TYPE INDEX HANDLER vectors_amhandler; + COMMENT ON ACCESS METHOD vectors IS 'pgvecto.rs index access method'; + + + + +-- src/postgres/operators.rs:99 +-- vectors::postgres::operators::operator_cosine +-- requires: +-- vector +CREATE FUNCTION tensorchord."operator_cosine"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS real /* vectors::prelude::scalar::Scalar */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_cosine_wrapper'; + +-- src/postgres/operators.rs:99 +-- vectors::postgres::operators::operator_cosine +CREATE OPERATOR tensorchord.<=> ( + PROCEDURE=tensorchord."operator_cosine", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector, /* vectors::postgres::datatype::VectorInput */ + COMMUTATOR = <=> +); + +-- src/postgres/operators.rs:115 +-- vectors::postgres::operators::operator_l2 +-- requires: +-- vector +CREATE FUNCTION tensorchord."operator_l2"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS real /* vectors::prelude::scalar::Scalar */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_l2_wrapper'; + +-- src/postgres/operators.rs:115 +-- vectors::postgres::operators::operator_l2 +CREATE OPERATOR tensorchord.<-> ( + PROCEDURE=tensorchord."operator_l2", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector, /* vectors::postgres::datatype::VectorInput */ + COMMUTATOR = <-> +); + +-- src/lib.rs:31 +-- finalize +CREATE CAST (real[] AS vector) + WITH FUNCTION cast_array_to_vector(real[], integer, boolean) AS IMPLICIT; + +CREATE CAST (vector AS real[]) + WITH FUNCTION cast_vector_to_array(vector, integer, boolean) AS IMPLICIT; + +CREATE OPERATOR CLASS l2_ops + FOR TYPE vector USING vectors AS + OPERATOR 1 <-> (vector, vector) FOR ORDER BY float_ops; + +CREATE OPERATOR CLASS dot_ops + FOR TYPE vector USING vectors AS + OPERATOR 1 <#> (vector, vector) FOR ORDER BY float_ops; + +CREATE OPERATOR CLASS cosine_ops + FOR TYPE vector USING vectors AS + OPERATOR 1 <=> (vector, vector) FOR ORDER BY float_ops; + diff --git a/sql/install/vectors--0.1.6.sql b/sql/install/vectors--0.1.6.sql new file mode 100644 index 000000000..50c4ead56 --- /dev/null +++ b/sql/install/vectors--0.1.6.sql @@ -0,0 +1,381 @@ +/* +This file is auto generated by pgrx. + +The ordering of items is not stable, it is driven by a dependency graph. +*/ + +-- src/lib.rs:30 +-- bootstrap +CREATE TYPE vector; + + +-- src/postgres/datatype.rs:424 +-- vectors::postgres::datatype::vector_typmod_out +CREATE FUNCTION "vector_typmod_out"( + "typmod" INT /* i32 */ +) RETURNS cstring /* alloc::ffi::c_str::CString */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'vector_typmod_out_wrapper'; + +-- src/postgres/datatype.rs:411 +-- vectors::postgres::datatype::vector_typmod_in +CREATE FUNCTION "vector_typmod_in"( + "list" cstring[] /* pgrx::datum::array::Array<&core::ffi::c_str::CStr> */ +) RETURNS INT /* i32 */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'vector_typmod_in_wrapper'; + +-- src/postgres/datatype.rs:397 +-- vectors::postgres::datatype::vector_out +CREATE FUNCTION "vector_out"( + "vector" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS cstring /* alloc::ffi::c_str::CString */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'vector_out_wrapper'; + +-- src/postgres/datatype.rs:349 +-- vectors::postgres::datatype::vector_in +CREATE FUNCTION "vector_in"( + "input" cstring, /* &core::ffi::c_str::CStr */ + "_oid" oid, /* pgrx_pg_sys::submodules::oids::Oid */ + "typmod" INT /* i32 */ +) RETURNS vector /* vectors::postgres::datatype::VectorOutput */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'vector_in_wrapper'; + +-- src/postgres/casts.rs:17 +-- vectors::postgres::casts::cast_vector_to_array +CREATE FUNCTION "cast_vector_to_array"( + "vector" vector, /* vectors::postgres::datatype::VectorInput */ + "_typmod" INT, /* i32 */ + "_explicit" bool /* bool */ +) RETURNS real[] /* alloc::vec::Vec */ +STRICT +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'cast_vector_to_array_wrapper'; + +-- src/postgres/casts.rs:5 +-- vectors::postgres::casts::cast_array_to_vector +CREATE FUNCTION "cast_array_to_vector"( + "array" real[], /* pgrx::datum::array::Array */ + "typmod" INT, /* i32 */ + "_explicit" bool /* bool */ +) RETURNS vector /* vectors::postgres::datatype::VectorOutput */ +STRICT +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'cast_array_to_vector_wrapper'; + +-- src/embedding/udf.rs:11 +-- vectors::embedding::udf::ai_embedding_vector +CREATE FUNCTION "ai_embedding_vector"( + "input" TEXT /* alloc::string::String */ +) RETURNS vector /* vectors::postgres::datatype::VectorOutput */ +STRICT +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'ai_embedding_vector_wrapper'; + +-- src/postgres/datatype.rs:73 +-- creates: +-- Type(vectors::postgres::datatype::Vector) + +-- requires: +-- vector_in +-- vector_out +-- vector_typmod_in +-- vector_typmod_out + + +CREATE TYPE vector ( + INPUT = vector_in, + OUTPUT = vector_out, + TYPMOD_IN = vector_typmod_in, + TYPMOD_OUT = vector_typmod_out, + STORAGE = EXTENDED, + INTERNALLENGTH = VARIABLE, + ALIGNMENT = double +); + + +-- src/postgres/operators.rs:107 +-- vectors::postgres::operators::operator_dot +-- requires: +-- vector +CREATE FUNCTION "operator_dot"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS real /* vectors::prelude::scalar::Scalar */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_dot_wrapper'; + +-- src/postgres/operators.rs:107 +-- vectors::postgres::operators::operator_dot +CREATE OPERATOR <#> ( + PROCEDURE="operator_dot", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector, /* vectors::postgres::datatype::VectorInput */ + COMMUTATOR = <#> +); + +-- src/postgres/operators.rs:47 +-- vectors::postgres::operators::operator_lte +-- requires: +-- vector +CREATE FUNCTION "operator_lte"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS bool /* bool */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_lte_wrapper'; + +-- src/postgres/operators.rs:47 +-- vectors::postgres::operators::operator_lte +CREATE OPERATOR <= ( + PROCEDURE="operator_lte", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector, /* vectors::postgres::datatype::VectorInput */ + COMMUTATOR = >=, + NEGATOR = >, + RESTRICT = scalarltsel, + JOIN = scalarltjoinsel +); + +-- src/postgres/operators.rs:99 +-- vectors::postgres::operators::operator_cosine +-- requires: +-- vector +CREATE FUNCTION "operator_cosine"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS real /* vectors::prelude::scalar::Scalar */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_cosine_wrapper'; + +-- src/postgres/operators.rs:99 +-- vectors::postgres::operators::operator_cosine +CREATE OPERATOR <=> ( + PROCEDURE="operator_cosine", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector, /* vectors::postgres::datatype::VectorInput */ + COMMUTATOR = <=> +); + +-- src/postgres/operators.rs:8 +-- vectors::postgres::operators::operator_add +-- requires: +-- vector +CREATE FUNCTION "operator_add"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS vector /* vectors::postgres::datatype::VectorOutput */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_add_wrapper'; + +-- src/postgres/operators.rs:8 +-- vectors::postgres::operators::operator_add +CREATE OPERATOR + ( + PROCEDURE="operator_add", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector, /* vectors::postgres::datatype::VectorInput */ + COMMUTATOR = + +); + +-- src/postgres/index.rs:35 +-- vectors::postgres::index::vectors_amhandler + + CREATE OR REPLACE FUNCTION vectors_amhandler(internal) RETURNS index_am_handler + PARALLEL SAFE IMMUTABLE STRICT LANGUAGE c AS 'MODULE_PATHNAME', 'vectors_amhandler_wrapper'; + CREATE ACCESS METHOD vectors TYPE INDEX HANDLER vectors_amhandler; + COMMENT ON ACCESS METHOD vectors IS 'pgvecto.rs index access method'; + + + + +-- src/postgres/operators.rs:58 +-- vectors::postgres::operators::operator_gt +-- requires: +-- vector +CREATE FUNCTION "operator_gt"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS bool /* bool */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_gt_wrapper'; + +-- src/postgres/operators.rs:58 +-- vectors::postgres::operators::operator_gt +CREATE OPERATOR > ( + PROCEDURE="operator_gt", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector, /* vectors::postgres::datatype::VectorInput */ + COMMUTATOR = <, + NEGATOR = <=, + RESTRICT = scalargtsel, + JOIN = scalargtjoinsel +); + +-- src/postgres/operators.rs:69 +-- vectors::postgres::operators::operator_gte +-- requires: +-- vector +CREATE FUNCTION "operator_gte"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS bool /* bool */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_gte_wrapper'; + +-- src/postgres/operators.rs:69 +-- vectors::postgres::operators::operator_gte +CREATE OPERATOR >= ( + PROCEDURE="operator_gte", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector, /* vectors::postgres::datatype::VectorInput */ + COMMUTATOR = <=, + NEGATOR = <, + RESTRICT = scalargtsel, + JOIN = scalargtjoinsel +); + +-- src/postgres/operators.rs:20 +-- vectors::postgres::operators::operator_minus +-- requires: +-- vector +CREATE FUNCTION "operator_minus"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS vector /* vectors::postgres::datatype::VectorOutput */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_minus_wrapper'; + +-- src/postgres/operators.rs:20 +-- vectors::postgres::operators::operator_minus +CREATE OPERATOR - ( + PROCEDURE="operator_minus", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector /* vectors::postgres::datatype::VectorInput */ +); + +-- src/postgres/operators.rs:115 +-- vectors::postgres::operators::operator_l2 +-- requires: +-- vector +CREATE FUNCTION "operator_l2"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS real /* vectors::prelude::scalar::Scalar */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_l2_wrapper'; + +-- src/postgres/operators.rs:115 +-- vectors::postgres::operators::operator_l2 +CREATE OPERATOR <-> ( + PROCEDURE="operator_l2", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector, /* vectors::postgres::datatype::VectorInput */ + COMMUTATOR = <-> +); + +-- src/postgres/operators.rs:36 +-- vectors::postgres::operators::operator_lt +-- requires: +-- vector +CREATE FUNCTION "operator_lt"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS bool /* bool */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_lt_wrapper'; + +-- src/postgres/operators.rs:36 +-- vectors::postgres::operators::operator_lt +CREATE OPERATOR < ( + PROCEDURE="operator_lt", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector, /* vectors::postgres::datatype::VectorInput */ + COMMUTATOR = >, + NEGATOR = >=, + RESTRICT = scalarltsel, + JOIN = scalarltjoinsel +); + +-- src/postgres/operators.rs:91 +-- vectors::postgres::operators::operator_neq +-- requires: +-- vector +CREATE FUNCTION "operator_neq"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS bool /* bool */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_neq_wrapper'; + +-- src/postgres/operators.rs:91 +-- vectors::postgres::operators::operator_neq +CREATE OPERATOR <> ( + PROCEDURE="operator_neq", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector, /* vectors::postgres::datatype::VectorInput */ + COMMUTATOR = <>, + NEGATOR = =, + RESTRICT = eqsel, + JOIN = eqjoinsel +); + +-- src/postgres/operators.rs:80 +-- vectors::postgres::operators::operator_eq +-- requires: +-- vector +CREATE FUNCTION "operator_eq"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS bool /* bool */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_eq_wrapper'; + +-- src/postgres/operators.rs:80 +-- vectors::postgres::operators::operator_eq +CREATE OPERATOR = ( + PROCEDURE="operator_eq", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector, /* vectors::postgres::datatype::VectorInput */ + COMMUTATOR = =, + NEGATOR = <>, + RESTRICT = eqsel, + JOIN = eqjoinsel +); + +-- src/lib.rs:31 +-- finalize +CREATE CAST (real[] AS vector) + WITH FUNCTION cast_array_to_vector(real[], integer, boolean) AS IMPLICIT; + +CREATE CAST (vector AS real[]) + WITH FUNCTION cast_vector_to_array(vector, integer, boolean) AS IMPLICIT; + +CREATE OPERATOR CLASS l2_ops + FOR TYPE vector USING vectors AS + OPERATOR 1 <-> (vector, vector) FOR ORDER BY float_ops; + +CREATE OPERATOR CLASS dot_ops + FOR TYPE vector USING vectors AS + OPERATOR 1 <#> (vector, vector) FOR ORDER BY float_ops; + +CREATE OPERATOR CLASS cosine_ops + FOR TYPE vector USING vectors AS + OPERATOR 1 <=> (vector, vector) FOR ORDER BY float_ops; + diff --git a/sql/install/vectors--0.1.7.sql b/sql/install/vectors--0.1.7.sql new file mode 100644 index 000000000..eae328ee4 --- /dev/null +++ b/sql/install/vectors--0.1.7.sql @@ -0,0 +1,381 @@ +/* +This file is auto generated by pgrx. + +The ordering of items is not stable, it is driven by a dependency graph. +*/ + +-- src/lib.rs:30 +-- bootstrap +CREATE TYPE vector; + + +-- src/postgres/datatype.rs:452 +-- vectors::postgres::datatype::vector_typmod_out +CREATE FUNCTION "vector_typmod_out"( + "typmod" INT /* i32 */ +) RETURNS cstring /* alloc::ffi::c_str::CString */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'vector_typmod_out_wrapper'; + +-- src/postgres/datatype.rs:437 +-- vectors::postgres::datatype::vector_typmod_in +CREATE FUNCTION "vector_typmod_in"( + "list" cstring[] /* pgrx::datum::array::Array<&core::ffi::c_str::CStr> */ +) RETURNS INT /* i32 */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'vector_typmod_in_wrapper'; + +-- src/postgres/datatype.rs:423 +-- vectors::postgres::datatype::vector_out +CREATE FUNCTION "vector_out"( + "vector" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS cstring /* alloc::ffi::c_str::CString */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'vector_out_wrapper'; + +-- src/postgres/datatype.rs:350 +-- vectors::postgres::datatype::vector_in +CREATE FUNCTION "vector_in"( + "input" cstring, /* &core::ffi::c_str::CStr */ + "_oid" oid, /* pgrx_pg_sys::submodules::oids::Oid */ + "typmod" INT /* i32 */ +) RETURNS vector /* vectors::postgres::datatype::VectorOutput */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'vector_in_wrapper'; + +-- src/postgres/casts.rs:18 +-- vectors::postgres::casts::cast_vector_to_array +CREATE FUNCTION "cast_vector_to_array"( + "vector" vector, /* vectors::postgres::datatype::VectorInput */ + "_typmod" INT, /* i32 */ + "_explicit" bool /* bool */ +) RETURNS real[] /* alloc::vec::Vec */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'cast_vector_to_array_wrapper'; + +-- src/postgres/casts.rs:5 +-- vectors::postgres::casts::cast_array_to_vector +CREATE FUNCTION "cast_array_to_vector"( + "array" real[], /* pgrx::datum::array::Array */ + "typmod" INT, /* i32 */ + "_explicit" bool /* bool */ +) RETURNS vector /* vectors::postgres::datatype::VectorOutput */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'cast_array_to_vector_wrapper'; + +-- src/embedding/udf.rs:11 +-- vectors::embedding::udf::ai_embedding_vector +CREATE FUNCTION "ai_embedding_vector"( + "input" TEXT /* alloc::string::String */ +) RETURNS vector /* vectors::postgres::datatype::VectorOutput */ +STRICT +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'ai_embedding_vector_wrapper'; + +-- src/postgres/datatype.rs:74 +-- creates: +-- Type(vectors::postgres::datatype::Vector) + +-- requires: +-- vector_in +-- vector_out +-- vector_typmod_in +-- vector_typmod_out + + +CREATE TYPE vector ( + INPUT = vector_in, + OUTPUT = vector_out, + TYPMOD_IN = vector_typmod_in, + TYPMOD_OUT = vector_typmod_out, + STORAGE = EXTENDED, + INTERNALLENGTH = VARIABLE, + ALIGNMENT = double +); + + +-- src/postgres/operators.rs:115 +-- vectors::postgres::operators::operator_l2 +-- requires: +-- vector +CREATE FUNCTION "operator_l2"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS real /* vectors::prelude::scalar::Scalar */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_l2_wrapper'; + +-- src/postgres/operators.rs:115 +-- vectors::postgres::operators::operator_l2 +CREATE OPERATOR <-> ( + PROCEDURE="operator_l2", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector, /* vectors::postgres::datatype::VectorInput */ + COMMUTATOR = <-> +); + +-- src/postgres/operators.rs:107 +-- vectors::postgres::operators::operator_dot +-- requires: +-- vector +CREATE FUNCTION "operator_dot"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS real /* vectors::prelude::scalar::Scalar */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_dot_wrapper'; + +-- src/postgres/operators.rs:107 +-- vectors::postgres::operators::operator_dot +CREATE OPERATOR <#> ( + PROCEDURE="operator_dot", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector, /* vectors::postgres::datatype::VectorInput */ + COMMUTATOR = <#> +); + +-- src/postgres/operators.rs:91 +-- vectors::postgres::operators::operator_neq +-- requires: +-- vector +CREATE FUNCTION "operator_neq"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS bool /* bool */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_neq_wrapper'; + +-- src/postgres/operators.rs:91 +-- vectors::postgres::operators::operator_neq +CREATE OPERATOR <> ( + PROCEDURE="operator_neq", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector, /* vectors::postgres::datatype::VectorInput */ + COMMUTATOR = <>, + NEGATOR = =, + RESTRICT = eqsel, + JOIN = eqjoinsel +); + +-- src/postgres/operators.rs:47 +-- vectors::postgres::operators::operator_lte +-- requires: +-- vector +CREATE FUNCTION "operator_lte"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS bool /* bool */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_lte_wrapper'; + +-- src/postgres/operators.rs:47 +-- vectors::postgres::operators::operator_lte +CREATE OPERATOR <= ( + PROCEDURE="operator_lte", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector, /* vectors::postgres::datatype::VectorInput */ + COMMUTATOR = >=, + NEGATOR = >, + RESTRICT = scalarltsel, + JOIN = scalarltjoinsel +); + +-- src/postgres/operators.rs:36 +-- vectors::postgres::operators::operator_lt +-- requires: +-- vector +CREATE FUNCTION "operator_lt"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS bool /* bool */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_lt_wrapper'; + +-- src/postgres/operators.rs:36 +-- vectors::postgres::operators::operator_lt +CREATE OPERATOR < ( + PROCEDURE="operator_lt", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector, /* vectors::postgres::datatype::VectorInput */ + COMMUTATOR = >, + NEGATOR = >=, + RESTRICT = scalarltsel, + JOIN = scalarltjoinsel +); + +-- src/postgres/operators.rs:20 +-- vectors::postgres::operators::operator_minus +-- requires: +-- vector +CREATE FUNCTION "operator_minus"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS vector /* vectors::postgres::datatype::VectorOutput */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_minus_wrapper'; + +-- src/postgres/operators.rs:20 +-- vectors::postgres::operators::operator_minus +CREATE OPERATOR - ( + PROCEDURE="operator_minus", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector /* vectors::postgres::datatype::VectorInput */ +); + +-- src/postgres/operators.rs:69 +-- vectors::postgres::operators::operator_gte +-- requires: +-- vector +CREATE FUNCTION "operator_gte"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS bool /* bool */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_gte_wrapper'; + +-- src/postgres/operators.rs:69 +-- vectors::postgres::operators::operator_gte +CREATE OPERATOR >= ( + PROCEDURE="operator_gte", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector, /* vectors::postgres::datatype::VectorInput */ + COMMUTATOR = <=, + NEGATOR = <, + RESTRICT = scalargtsel, + JOIN = scalargtjoinsel +); + +-- src/postgres/operators.rs:58 +-- vectors::postgres::operators::operator_gt +-- requires: +-- vector +CREATE FUNCTION "operator_gt"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS bool /* bool */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_gt_wrapper'; + +-- src/postgres/operators.rs:58 +-- vectors::postgres::operators::operator_gt +CREATE OPERATOR > ( + PROCEDURE="operator_gt", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector, /* vectors::postgres::datatype::VectorInput */ + COMMUTATOR = <, + NEGATOR = <=, + RESTRICT = scalargtsel, + JOIN = scalargtjoinsel +); + +-- src/postgres/operators.rs:8 +-- vectors::postgres::operators::operator_add +-- requires: +-- vector +CREATE FUNCTION "operator_add"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS vector /* vectors::postgres::datatype::VectorOutput */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_add_wrapper'; + +-- src/postgres/operators.rs:8 +-- vectors::postgres::operators::operator_add +CREATE OPERATOR + ( + PROCEDURE="operator_add", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector, /* vectors::postgres::datatype::VectorInput */ + COMMUTATOR = + +); + +-- src/postgres/index.rs:35 +-- vectors::postgres::index::vectors_amhandler + + CREATE OR REPLACE FUNCTION vectors_amhandler(internal) RETURNS index_am_handler + PARALLEL SAFE IMMUTABLE STRICT LANGUAGE c AS 'MODULE_PATHNAME', 'vectors_amhandler_wrapper'; + CREATE ACCESS METHOD vectors TYPE INDEX HANDLER vectors_amhandler; + COMMENT ON ACCESS METHOD vectors IS 'pgvecto.rs index access method'; + + + + +-- src/postgres/operators.rs:80 +-- vectors::postgres::operators::operator_eq +-- requires: +-- vector +CREATE FUNCTION "operator_eq"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS bool /* bool */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_eq_wrapper'; + +-- src/postgres/operators.rs:80 +-- vectors::postgres::operators::operator_eq +CREATE OPERATOR = ( + PROCEDURE="operator_eq", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector, /* vectors::postgres::datatype::VectorInput */ + COMMUTATOR = =, + NEGATOR = <>, + RESTRICT = eqsel, + JOIN = eqjoinsel +); + +-- src/postgres/operators.rs:99 +-- vectors::postgres::operators::operator_cosine +-- requires: +-- vector +CREATE FUNCTION "operator_cosine"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS real /* vectors::prelude::scalar::Scalar */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_cosine_wrapper'; + +-- src/postgres/operators.rs:99 +-- vectors::postgres::operators::operator_cosine +CREATE OPERATOR <=> ( + PROCEDURE="operator_cosine", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector, /* vectors::postgres::datatype::VectorInput */ + COMMUTATOR = <=> +); + +-- src/lib.rs:31 +-- finalize +CREATE CAST (real[] AS vector) + WITH FUNCTION cast_array_to_vector(real[], integer, boolean) AS IMPLICIT; + +CREATE CAST (vector AS real[]) + WITH FUNCTION cast_vector_to_array(vector, integer, boolean) AS IMPLICIT; + +CREATE OPERATOR CLASS l2_ops + FOR TYPE vector USING vectors AS + OPERATOR 1 <-> (vector, vector) FOR ORDER BY float_ops; + +CREATE OPERATOR CLASS dot_ops + FOR TYPE vector USING vectors AS + OPERATOR 1 <#> (vector, vector) FOR ORDER BY float_ops; + +CREATE OPERATOR CLASS cosine_ops + FOR TYPE vector USING vectors AS + OPERATOR 1 <=> (vector, vector) FOR ORDER BY float_ops; + diff --git a/sql/install/vectors--0.1.8.sql b/sql/install/vectors--0.1.8.sql new file mode 100644 index 000000000..3c8c98e39 --- /dev/null +++ b/sql/install/vectors--0.1.8.sql @@ -0,0 +1,381 @@ +/* +This file is auto generated by pgrx. + +The ordering of items is not stable, it is driven by a dependency graph. +*/ + +-- src/lib.rs:20 +-- bootstrap +CREATE TYPE vector; + + +-- src/postgres/datatype.rs:452 +-- vectors::postgres::datatype::vector_typmod_out +CREATE FUNCTION "vector_typmod_out"( + "typmod" INT /* i32 */ +) RETURNS cstring /* alloc::ffi::c_str::CString */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'vector_typmod_out_wrapper'; + +-- src/postgres/datatype.rs:437 +-- vectors::postgres::datatype::vector_typmod_in +CREATE FUNCTION "vector_typmod_in"( + "list" cstring[] /* pgrx::datum::array::Array<&core::ffi::c_str::CStr> */ +) RETURNS INT /* i32 */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'vector_typmod_in_wrapper'; + +-- src/postgres/datatype.rs:423 +-- vectors::postgres::datatype::vector_out +CREATE FUNCTION "vector_out"( + "vector" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS cstring /* alloc::ffi::c_str::CString */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'vector_out_wrapper'; + +-- src/postgres/datatype.rs:350 +-- vectors::postgres::datatype::vector_in +CREATE FUNCTION "vector_in"( + "input" cstring, /* &core::ffi::c_str::CStr */ + "_oid" oid, /* pgrx_pg_sys::submodules::oids::Oid */ + "typmod" INT /* i32 */ +) RETURNS vector /* vectors::postgres::datatype::VectorOutput */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'vector_in_wrapper'; + +-- src/postgres/casts.rs:18 +-- vectors::postgres::casts::cast_vector_to_array +CREATE FUNCTION "cast_vector_to_array"( + "vector" vector, /* vectors::postgres::datatype::VectorInput */ + "_typmod" INT, /* i32 */ + "_explicit" bool /* bool */ +) RETURNS real[] /* alloc::vec::Vec */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'cast_vector_to_array_wrapper'; + +-- src/postgres/casts.rs:5 +-- vectors::postgres::casts::cast_array_to_vector +CREATE FUNCTION "cast_array_to_vector"( + "array" real[], /* pgrx::datum::array::Array */ + "typmod" INT, /* i32 */ + "_explicit" bool /* bool */ +) RETURNS vector /* vectors::postgres::datatype::VectorOutput */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'cast_array_to_vector_wrapper'; + +-- src/embedding/udf.rs:11 +-- vectors::embedding::udf::ai_embedding_vector +CREATE FUNCTION "ai_embedding_vector"( + "input" TEXT /* alloc::string::String */ +) RETURNS vector /* vectors::postgres::datatype::VectorOutput */ +STRICT +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'ai_embedding_vector_wrapper'; + +-- src/postgres/datatype.rs:74 +-- creates: +-- Type(vectors::postgres::datatype::Vector) + +-- requires: +-- vector_in +-- vector_out +-- vector_typmod_in +-- vector_typmod_out + + +CREATE TYPE vector ( + INPUT = vector_in, + OUTPUT = vector_out, + TYPMOD_IN = vector_typmod_in, + TYPMOD_OUT = vector_typmod_out, + STORAGE = EXTENDED, + INTERNALLENGTH = VARIABLE, + ALIGNMENT = double +); + + +-- src/postgres/operators.rs:82 +-- vectors::postgres::operators::operator_gt +-- requires: +-- vector +CREATE FUNCTION "operator_gt"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS bool /* bool */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_gt_wrapper'; + +-- src/postgres/operators.rs:82 +-- vectors::postgres::operators::operator_gt +CREATE OPERATOR > ( + PROCEDURE="operator_gt", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector, /* vectors::postgres::datatype::VectorInput */ + COMMUTATOR = <, + NEGATOR = <=, + RESTRICT = scalargtsel, + JOIN = scalargtjoinsel +); + +-- src/postgres/operators.rs:99 +-- vectors::postgres::operators::operator_gte +-- requires: +-- vector +CREATE FUNCTION "operator_gte"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS bool /* bool */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_gte_wrapper'; + +-- src/postgres/operators.rs:99 +-- vectors::postgres::operators::operator_gte +CREATE OPERATOR >= ( + PROCEDURE="operator_gte", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector, /* vectors::postgres::datatype::VectorInput */ + COMMUTATOR = <=, + NEGATOR = <, + RESTRICT = scalargtsel, + JOIN = scalargtjoinsel +); + +-- src/postgres/operators.rs:161 +-- vectors::postgres::operators::operator_dot +-- requires: +-- vector +CREATE FUNCTION "operator_dot"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS real /* vectors::prelude::scalar::Scalar */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_dot_wrapper'; + +-- src/postgres/operators.rs:161 +-- vectors::postgres::operators::operator_dot +CREATE OPERATOR <#> ( + PROCEDURE="operator_dot", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector, /* vectors::postgres::datatype::VectorInput */ + COMMUTATOR = <#> +); + +-- src/postgres/operators.rs:48 +-- vectors::postgres::operators::operator_lt +-- requires: +-- vector +CREATE FUNCTION "operator_lt"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS bool /* bool */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_lt_wrapper'; + +-- src/postgres/operators.rs:48 +-- vectors::postgres::operators::operator_lt +CREATE OPERATOR < ( + PROCEDURE="operator_lt", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector, /* vectors::postgres::datatype::VectorInput */ + COMMUTATOR = >, + NEGATOR = >=, + RESTRICT = scalarltsel, + JOIN = scalarltjoinsel +); + +-- src/postgres/operators.rs:116 +-- vectors::postgres::operators::operator_eq +-- requires: +-- vector +CREATE FUNCTION "operator_eq"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS bool /* bool */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_eq_wrapper'; + +-- src/postgres/operators.rs:116 +-- vectors::postgres::operators::operator_eq +CREATE OPERATOR = ( + PROCEDURE="operator_eq", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector, /* vectors::postgres::datatype::VectorInput */ + COMMUTATOR = =, + NEGATOR = <>, + RESTRICT = eqsel, + JOIN = eqjoinsel +); + +-- src/postgres/operators.rs:147 +-- vectors::postgres::operators::operator_cosine +-- requires: +-- vector +CREATE FUNCTION "operator_cosine"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS real /* vectors::prelude::scalar::Scalar */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_cosine_wrapper'; + +-- src/postgres/operators.rs:147 +-- vectors::postgres::operators::operator_cosine +CREATE OPERATOR <=> ( + PROCEDURE="operator_cosine", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector, /* vectors::postgres::datatype::VectorInput */ + COMMUTATOR = <=> +); + +-- src/postgres/operators.rs:175 +-- vectors::postgres::operators::operator_l2 +-- requires: +-- vector +CREATE FUNCTION "operator_l2"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS real /* vectors::prelude::scalar::Scalar */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_l2_wrapper'; + +-- src/postgres/operators.rs:175 +-- vectors::postgres::operators::operator_l2 +CREATE OPERATOR <-> ( + PROCEDURE="operator_l2", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector, /* vectors::postgres::datatype::VectorInput */ + COMMUTATOR = <-> +); + +-- src/postgres/index.rs:34 +-- vectors::postgres::index::vectors_amhandler + + CREATE OR REPLACE FUNCTION vectors_amhandler(internal) RETURNS index_am_handler + PARALLEL SAFE IMMUTABLE STRICT LANGUAGE c AS 'MODULE_PATHNAME', 'vectors_amhandler_wrapper'; + CREATE ACCESS METHOD vectors TYPE INDEX HANDLER vectors_amhandler; + COMMENT ON ACCESS METHOD vectors IS 'pgvecto.rs index access method'; + + + + +-- src/postgres/operators.rs:26 +-- vectors::postgres::operators::operator_minus +-- requires: +-- vector +CREATE FUNCTION "operator_minus"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS vector /* vectors::postgres::datatype::VectorOutput */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_minus_wrapper'; + +-- src/postgres/operators.rs:26 +-- vectors::postgres::operators::operator_minus +CREATE OPERATOR - ( + PROCEDURE="operator_minus", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector /* vectors::postgres::datatype::VectorInput */ +); + +-- src/postgres/operators.rs:133 +-- vectors::postgres::operators::operator_neq +-- requires: +-- vector +CREATE FUNCTION "operator_neq"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS bool /* bool */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_neq_wrapper'; + +-- src/postgres/operators.rs:133 +-- vectors::postgres::operators::operator_neq +CREATE OPERATOR <> ( + PROCEDURE="operator_neq", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector, /* vectors::postgres::datatype::VectorInput */ + COMMUTATOR = <>, + NEGATOR = =, + RESTRICT = eqsel, + JOIN = eqjoinsel +); + +-- src/postgres/operators.rs:8 +-- vectors::postgres::operators::operator_add +-- requires: +-- vector +CREATE FUNCTION "operator_add"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS vector /* vectors::postgres::datatype::VectorOutput */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_add_wrapper'; + +-- src/postgres/operators.rs:8 +-- vectors::postgres::operators::operator_add +CREATE OPERATOR + ( + PROCEDURE="operator_add", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector, /* vectors::postgres::datatype::VectorInput */ + COMMUTATOR = + +); + +-- src/postgres/operators.rs:65 +-- vectors::postgres::operators::operator_lte +-- requires: +-- vector +CREATE FUNCTION "operator_lte"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS bool /* bool */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_lte_wrapper'; + +-- src/postgres/operators.rs:65 +-- vectors::postgres::operators::operator_lte +CREATE OPERATOR <= ( + PROCEDURE="operator_lte", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector, /* vectors::postgres::datatype::VectorInput */ + COMMUTATOR = >=, + NEGATOR = >, + RESTRICT = scalarltsel, + JOIN = scalarltjoinsel +); + +-- src/lib.rs:21 +-- finalize +CREATE CAST (real[] AS vector) + WITH FUNCTION cast_array_to_vector(real[], integer, boolean) AS IMPLICIT; + +CREATE CAST (vector AS real[]) + WITH FUNCTION cast_vector_to_array(vector, integer, boolean) AS IMPLICIT; + +CREATE OPERATOR CLASS l2_ops + FOR TYPE vector USING vectors AS + OPERATOR 1 <-> (vector, vector) FOR ORDER BY float_ops; + +CREATE OPERATOR CLASS dot_ops + FOR TYPE vector USING vectors AS + OPERATOR 1 <#> (vector, vector) FOR ORDER BY float_ops; + +CREATE OPERATOR CLASS cosine_ops + FOR TYPE vector USING vectors AS + OPERATOR 1 <=> (vector, vector) FOR ORDER BY float_ops; + diff --git a/sql/install/vectors--0.1.9.sql b/sql/install/vectors--0.1.9.sql new file mode 100644 index 000000000..c6bf0bcaa --- /dev/null +++ b/sql/install/vectors--0.1.9.sql @@ -0,0 +1,413 @@ +/* +This file is auto generated by pgrx. + +The ordering of items is not stable, it is driven by a dependency graph. +*/ + +-- src/lib.rs:16 +-- bootstrap +CREATE TYPE vector; + + +-- src/postgres/datatype.rs:450 +-- vectors::postgres::datatype::vector_typmod_out +CREATE FUNCTION "vector_typmod_out"( + "typmod" INT /* i32 */ +) RETURNS cstring /* alloc::ffi::c_str::CString */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'vector_typmod_out_wrapper'; + +-- src/postgres/datatype.rs:435 +-- vectors::postgres::datatype::vector_typmod_in +CREATE FUNCTION "vector_typmod_in"( + "list" cstring[] /* pgrx::datum::array::Array<&core::ffi::c_str::CStr> */ +) RETURNS INT /* i32 */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'vector_typmod_in_wrapper'; + +-- src/postgres/functions.rs:5 +-- vectors::postgres::functions::vector_stat_tuples_done +CREATE FUNCTION "vector_stat_tuples_done"( + "oid" oid /* pgrx_pg_sys::submodules::oids::Oid */ +) RETURNS INT /* i32 */ +STRICT VOLATILE PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'vector_stat_tuples_done_wrapper'; + +-- src/postgres/functions.rs:16 +-- vectors::postgres::functions::vector_stat_config +CREATE FUNCTION "vector_stat_config"( + "oid" oid /* pgrx_pg_sys::submodules::oids::Oid */ +) RETURNS TEXT /* alloc::string::String */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'vector_stat_config_wrapper'; + +-- src/postgres/datatype.rs:421 +-- vectors::postgres::datatype::vector_out +CREATE FUNCTION "vector_out"( + "vector" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS cstring /* alloc::ffi::c_str::CString */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'vector_out_wrapper'; + +-- src/postgres/datatype.rs:348 +-- vectors::postgres::datatype::vector_in +CREATE FUNCTION "vector_in"( + "input" cstring, /* &core::ffi::c_str::CStr */ + "_oid" oid, /* pgrx_pg_sys::submodules::oids::Oid */ + "typmod" INT /* i32 */ +) RETURNS vector /* vectors::postgres::datatype::VectorOutput */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'vector_in_wrapper'; + +-- src/postgres/casts.rs:19 +-- vectors::postgres::casts::cast_vector_to_array +CREATE FUNCTION "cast_vector_to_array"( + "vector" vector, /* vectors::postgres::datatype::VectorInput */ + "_typmod" INT, /* i32 */ + "_explicit" bool /* bool */ +) RETURNS real[] /* alloc::vec::Vec */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'cast_vector_to_array_wrapper'; + +-- src/postgres/casts.rs:5 +-- vectors::postgres::casts::cast_array_to_vector +CREATE FUNCTION "cast_array_to_vector"( + "array" real[], /* pgrx::datum::array::Array */ + "typmod" INT, /* i32 */ + "_explicit" bool /* bool */ +) RETURNS vector /* vectors::postgres::datatype::VectorOutput */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'cast_array_to_vector_wrapper'; + +-- src/embedding/udf.rs:11 +-- vectors::embedding::udf::ai_embedding_vector +CREATE FUNCTION "ai_embedding_vector"( + "input" TEXT /* alloc::string::String */ +) RETURNS vector /* vectors::postgres::datatype::VectorOutput */ +STRICT +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'ai_embedding_vector_wrapper'; + +-- src/postgres/datatype.rs:72 +-- creates: +-- Type(vectors::postgres::datatype::Vector) + +-- requires: +-- vector_in +-- vector_out +-- vector_typmod_in +-- vector_typmod_out + + +CREATE TYPE vector ( + INPUT = vector_in, + OUTPUT = vector_out, + TYPMOD_IN = vector_typmod_in, + TYPMOD_OUT = vector_typmod_out, + STORAGE = EXTENDED, + INTERNALLENGTH = VARIABLE, + ALIGNMENT = double +); + + +-- src/postgres/operators.rs:147 +-- vectors::postgres::operators::operator_cosine +-- requires: +-- vector +CREATE FUNCTION "operator_cosine"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS real /* vectors::prelude::scalar::Scalar */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_cosine_wrapper'; + +-- src/postgres/operators.rs:147 +-- vectors::postgres::operators::operator_cosine +CREATE OPERATOR <=> ( + PROCEDURE="operator_cosine", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector, /* vectors::postgres::datatype::VectorInput */ + COMMUTATOR = <=> +); + +-- src/postgres/operators.rs:161 +-- vectors::postgres::operators::operator_dot +-- requires: +-- vector +CREATE FUNCTION "operator_dot"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS real /* vectors::prelude::scalar::Scalar */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_dot_wrapper'; + +-- src/postgres/operators.rs:161 +-- vectors::postgres::operators::operator_dot +CREATE OPERATOR <#> ( + PROCEDURE="operator_dot", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector, /* vectors::postgres::datatype::VectorInput */ + COMMUTATOR = <#> +); + +-- src/postgres/operators.rs:48 +-- vectors::postgres::operators::operator_lt +-- requires: +-- vector +CREATE FUNCTION "operator_lt"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS bool /* bool */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_lt_wrapper'; + +-- src/postgres/operators.rs:48 +-- vectors::postgres::operators::operator_lt +CREATE OPERATOR < ( + PROCEDURE="operator_lt", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector, /* vectors::postgres::datatype::VectorInput */ + COMMUTATOR = >, + NEGATOR = >=, + RESTRICT = scalarltsel, + JOIN = scalarltjoinsel +); + +-- src/postgres/operators.rs:175 +-- vectors::postgres::operators::operator_l2 +-- requires: +-- vector +CREATE FUNCTION "operator_l2"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS real /* vectors::prelude::scalar::Scalar */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_l2_wrapper'; + +-- src/postgres/operators.rs:175 +-- vectors::postgres::operators::operator_l2 +CREATE OPERATOR <-> ( + PROCEDURE="operator_l2", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector, /* vectors::postgres::datatype::VectorInput */ + COMMUTATOR = <-> +); + +-- src/postgres/operators.rs:26 +-- vectors::postgres::operators::operator_minus +-- requires: +-- vector +CREATE FUNCTION "operator_minus"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS vector /* vectors::postgres::datatype::VectorOutput */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_minus_wrapper'; + +-- src/postgres/operators.rs:26 +-- vectors::postgres::operators::operator_minus +CREATE OPERATOR - ( + PROCEDURE="operator_minus", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector /* vectors::postgres::datatype::VectorInput */ +); + +-- src/postgres/operators.rs:8 +-- vectors::postgres::operators::operator_add +-- requires: +-- vector +CREATE FUNCTION "operator_add"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS vector /* vectors::postgres::datatype::VectorOutput */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_add_wrapper'; + +-- src/postgres/operators.rs:8 +-- vectors::postgres::operators::operator_add +CREATE OPERATOR + ( + PROCEDURE="operator_add", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector, /* vectors::postgres::datatype::VectorInput */ + COMMUTATOR = + +); + +-- src/postgres/index.rs:34 +-- vectors::postgres::index::vectors_amhandler + + CREATE OR REPLACE FUNCTION vectors_amhandler(internal) RETURNS index_am_handler + PARALLEL SAFE IMMUTABLE STRICT LANGUAGE c AS 'MODULE_PATHNAME', 'vectors_amhandler_wrapper'; + CREATE ACCESS METHOD vectors TYPE INDEX HANDLER vectors_amhandler; + COMMENT ON ACCESS METHOD vectors IS 'pgvecto.rs index access method'; + + + + +-- src/postgres/operators.rs:82 +-- vectors::postgres::operators::operator_gt +-- requires: +-- vector +CREATE FUNCTION "operator_gt"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS bool /* bool */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_gt_wrapper'; + +-- src/postgres/operators.rs:82 +-- vectors::postgres::operators::operator_gt +CREATE OPERATOR > ( + PROCEDURE="operator_gt", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector, /* vectors::postgres::datatype::VectorInput */ + COMMUTATOR = <, + NEGATOR = <=, + RESTRICT = scalargtsel, + JOIN = scalargtjoinsel +); + +-- src/postgres/operators.rs:133 +-- vectors::postgres::operators::operator_neq +-- requires: +-- vector +CREATE FUNCTION "operator_neq"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS bool /* bool */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_neq_wrapper'; + +-- src/postgres/operators.rs:133 +-- vectors::postgres::operators::operator_neq +CREATE OPERATOR <> ( + PROCEDURE="operator_neq", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector, /* vectors::postgres::datatype::VectorInput */ + COMMUTATOR = <>, + NEGATOR = =, + RESTRICT = eqsel, + JOIN = eqjoinsel +); + +-- src/postgres/operators.rs:65 +-- vectors::postgres::operators::operator_lte +-- requires: +-- vector +CREATE FUNCTION "operator_lte"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS bool /* bool */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_lte_wrapper'; + +-- src/postgres/operators.rs:65 +-- vectors::postgres::operators::operator_lte +CREATE OPERATOR <= ( + PROCEDURE="operator_lte", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector, /* vectors::postgres::datatype::VectorInput */ + COMMUTATOR = >=, + NEGATOR = >, + RESTRICT = scalarltsel, + JOIN = scalarltjoinsel +); + +-- src/postgres/operators.rs:99 +-- vectors::postgres::operators::operator_gte +-- requires: +-- vector +CREATE FUNCTION "operator_gte"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS bool /* bool */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_gte_wrapper'; + +-- src/postgres/operators.rs:99 +-- vectors::postgres::operators::operator_gte +CREATE OPERATOR >= ( + PROCEDURE="operator_gte", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector, /* vectors::postgres::datatype::VectorInput */ + COMMUTATOR = <=, + NEGATOR = <, + RESTRICT = scalargtsel, + JOIN = scalargtjoinsel +); + +-- src/postgres/operators.rs:116 +-- vectors::postgres::operators::operator_eq +-- requires: +-- vector +CREATE FUNCTION "operator_eq"( + "lhs" vector, /* vectors::postgres::datatype::VectorInput */ + "rhs" vector /* vectors::postgres::datatype::VectorInput */ +) RETURNS bool /* bool */ +IMMUTABLE STRICT PARALLEL SAFE +LANGUAGE c /* Rust */ +AS 'MODULE_PATHNAME', 'operator_eq_wrapper'; + +-- src/postgres/operators.rs:116 +-- vectors::postgres::operators::operator_eq +CREATE OPERATOR = ( + PROCEDURE="operator_eq", + LEFTARG=vector, /* vectors::postgres::datatype::VectorInput */ + RIGHTARG=vector, /* vectors::postgres::datatype::VectorInput */ + COMMUTATOR = =, + NEGATOR = <>, + RESTRICT = eqsel, + JOIN = eqjoinsel +); + +-- src/lib.rs:17 +-- finalize +CREATE CAST (real[] AS vector) + WITH FUNCTION cast_array_to_vector(real[], integer, boolean) AS IMPLICIT; + +CREATE CAST (vector AS real[]) + WITH FUNCTION cast_vector_to_array(vector, integer, boolean) AS IMPLICIT; + +CREATE OPERATOR CLASS l2_ops + FOR TYPE vector USING vectors AS + OPERATOR 1 <-> (vector, vector) FOR ORDER BY float_ops; + +CREATE OPERATOR CLASS dot_ops + FOR TYPE vector USING vectors AS + OPERATOR 1 <#> (vector, vector) FOR ORDER BY float_ops; + +CREATE OPERATOR CLASS cosine_ops + FOR TYPE vector USING vectors AS + OPERATOR 1 <=> (vector, vector) FOR ORDER BY float_ops; + +CREATE VIEW pg_vector_index_info AS + SELECT + C.oid AS tablerelid, + I.oid AS indexrelid, + C.relname AS tablename, + I.relname AS indexname, + I.reltuples AS idx_tuples, + vector_stat_tuples_done(I.oid) AS idx_tuples_done, + vector_stat_config(I.oid) AS idx_config + FROM pg_class C JOIN + pg_index X ON C.oid = X.indrelid JOIN + pg_class I ON I.oid = X.indexrelid JOIN + pg_am A ON A.oid = I.relam + WHERE A.amname = 'vectors'; diff --git a/sql/upgrade/.gitkeep b/sql/upgrade/.gitkeep new file mode 100644 index 000000000..e69de29bb diff --git a/src/bgworker/mod.rs b/src/bgworker/mod.rs index 16b011680..5a8d84b52 100644 --- a/src/bgworker/mod.rs +++ b/src/bgworker/mod.rs @@ -1,8 +1,5 @@ -use crate::ipc::server::RpcHandler; -use crate::ipc::IpcError; -use service::worker::Worker; -use std::path::{Path, PathBuf}; -use std::sync::Arc; +pub mod normal; +pub mod upgrade; pub unsafe fn init() { use pgrx::bgworkers::BackgroundWorkerBuilder; @@ -47,125 +44,18 @@ pub fn main() { } log::error!("Panickied. Info: {:?}. Backtrace: {}.", info, backtrace); })); - let worker = if Path::new("pg_vectors").try_exists().unwrap() { - Worker::open(PathBuf::from("pg_vectors")) - } else { - Worker::create(PathBuf::from("pg_vectors")) - }; - std::thread::spawn({ - let worker = worker.clone(); - move || listen(crate::ipc::listen_unix(), worker) - }); - std::thread::spawn({ - let worker = worker.clone(); - move || listen(crate::ipc::listen_mmap(), worker) - }); - loop { - let mut sig: i32 = 0; - unsafe { - let mut set: libc::sigset_t = std::mem::zeroed(); - libc::sigemptyset(&mut set); - libc::sigaddset(&mut set, libc::SIGHUP); - libc::sigaddset(&mut set, libc::SIGTERM); - libc::sigwait(&set, &mut sig); - } - match sig { - libc::SIGHUP => { - std::process::exit(0); - } - libc::SIGTERM => { - std::process::exit(0); - } - _ => (), - } - } -} - -fn listen(listen: impl Iterator, worker: Arc) { - for rpc_handler in listen { - let worker = worker.clone(); - std::thread::spawn({ - move || { - log::trace!("Session established."); - let _ = session(worker, rpc_handler); - log::trace!("Session closed."); - } - }); - } -} - -fn session(worker: Arc, mut handler: RpcHandler) -> Result<(), IpcError> { - use crate::ipc::server::RpcHandle; - loop { - match handler.handle()? { - RpcHandle::Create { id, options, x } => { - worker.call_create(id, options); - handler = x.leave()?; - } - RpcHandle::Insert { id, insert, x } => { - let res = worker.call_insert(id, insert); - handler = x.leave(res)?; - } - RpcHandle::Delete { id, mut x } => { - let res = worker.call_delete(id, |p| x.next(p).unwrap()); - handler = x.leave(res)?; - } - RpcHandle::Search { - id, - search, - prefilter, - mut x, - } => { - if prefilter { - let res = worker.call_search(id, search, |p| x.check(p).unwrap()); - handler = x.leave(res)?; - } else { - let res = worker.call_search(id, search, |_| true); - handler = x.leave(res)?; - } - } - RpcHandle::Flush { id, x } => { - let result = worker.call_flush(id); - handler = x.leave(result)?; - } - RpcHandle::Destory { ids, x } => { - worker.call_destory(ids); - handler = x.leave()?; - } - RpcHandle::Stat { id, x } => { - let result = worker.call_stat(id); - handler = x.leave(result)?; - } - RpcHandle::Vbase { id, vbase, x } => { - use crate::ipc::server::VbaseHandle::*; - let instance = match worker.get_instance(id) { - Ok(x) => x, - Err(e) => { - x.error(Err(e))?; - break Ok(()); - } - }; - let view = instance.view(); - let mut it = match view.vbase(vbase.0, vbase.1) { - Ok(x) => x, - Err(e) => { - x.error(Err(e))?; - break Ok(()); - } - }; - let mut x = x.error(Ok(()))?; - loop { - match x.handle()? { - Next { x: y } => { - x = y.leave(it.next())?; - } - Leave { x } => { - handler = x; - break; - } - } - } - } + use service::worker::Worker; + use std::path::Path; + let path = Path::new("pg_vectors"); + if path.try_exists().unwrap() { + if Worker::check(path.to_owned()) { + let worker = Worker::open(path.to_owned()); + self::normal::normal(worker); + } else { + self::upgrade::upgrade(); } + } else { + let worker = Worker::create(path.to_owned()); + self::normal::normal(worker); } } diff --git a/src/bgworker/normal.rs b/src/bgworker/normal.rs new file mode 100644 index 000000000..8c4d2cc25 --- /dev/null +++ b/src/bgworker/normal.rs @@ -0,0 +1,132 @@ +use crate::ipc::{server::RpcHandler, IpcError}; +use service::worker::Worker; +use std::sync::Arc; + +pub fn normal(worker: Arc) { + std::thread::scope(|scope| { + scope.spawn({ + let worker = worker.clone(); + move || { + for rpc_handler in crate::ipc::listen_unix() { + let worker = worker.clone(); + std::thread::spawn({ + move || { + log::trace!("Session established."); + let _ = session(worker, rpc_handler); + log::trace!("Session closed."); + } + }); + } + } + }); + scope.spawn({ + let worker = worker.clone(); + move || { + for rpc_handler in crate::ipc::listen_mmap() { + let worker = worker.clone(); + std::thread::spawn({ + move || { + log::trace!("Session established."); + let _ = session(worker, rpc_handler); + log::trace!("Session closed."); + } + }); + } + } + }); + loop { + let mut sig: i32 = 0; + unsafe { + let mut set: libc::sigset_t = std::mem::zeroed(); + libc::sigemptyset(&mut set); + libc::sigaddset(&mut set, libc::SIGHUP); + libc::sigaddset(&mut set, libc::SIGTERM); + libc::sigwait(&set, &mut sig); + } + match sig { + libc::SIGHUP => { + std::process::exit(0); + } + libc::SIGTERM => { + std::process::exit(0); + } + _ => (), + } + } + }); +} + +fn session(worker: Arc, mut handler: RpcHandler) -> Result<(), IpcError> { + use crate::ipc::server::RpcHandle; + loop { + match handler.handle()? { + RpcHandle::Create { id, options, x } => { + worker.call_create(id, options); + handler = x.leave()?; + } + RpcHandle::Insert { id, insert, x } => match worker.call_insert(id, insert) { + Ok(()) => handler = x.leave()?, + Err(res) => x.reset(res)?, + }, + RpcHandle::Delete { id, mut x } => match worker.call_delete(id, |p| x.next(p).unwrap()) + { + Ok(()) => handler = x.leave()?, + Err(res) => x.reset(res)?, + }, + RpcHandle::Search { + id, + search, + prefilter: true, + mut x, + } => match worker.call_search(id, search, |p| x.check(p).unwrap()) { + Ok(res) => handler = x.leave(res)?, + Err(e) => x.reset(e)?, + }, + RpcHandle::Search { + id, + search, + prefilter: false, + x, + } => match worker.call_search(id, search, |_| true) { + Ok(res) => handler = x.leave(res)?, + Err(e) => x.reset(e)?, + }, + RpcHandle::Flush { id, x } => match worker.call_flush(id) { + Ok(()) => handler = x.leave()?, + Err(e) => x.reset(e)?, + }, + RpcHandle::Destory { ids, x } => { + worker.call_destory(ids); + handler = x.leave()?; + } + RpcHandle::Stat { id, x } => match worker.call_stat(id) { + Ok(res) => handler = x.leave(res)?, + Err(e) => x.reset(e)?, + }, + RpcHandle::Vbase { id, vbase, x } => { + use crate::ipc::server::VbaseHandle::*; + let instance = match worker.get_instance(id) { + Ok(x) => x, + Err(e) => x.reset(e)?, + }; + let view = instance.view(); + let mut it = match view.vbase(vbase.0, vbase.1) { + Ok(x) => x, + Err(e) => x.reset(e)?, + }; + let mut x = x.error()?; + loop { + match x.handle()? { + Next { x: y } => { + x = y.leave(it.next())?; + } + Leave { x } => { + handler = x; + break; + } + } + } + } + } + } +} diff --git a/src/bgworker/upgrade.rs b/src/bgworker/upgrade.rs new file mode 100644 index 000000000..b2086c87f --- /dev/null +++ b/src/bgworker/upgrade.rs @@ -0,0 +1,67 @@ +use crate::ipc::server::RpcHandler; +use crate::ipc::IpcError; +use service::prelude::*; + +pub fn upgrade() { + std::thread::scope(|scope| { + scope.spawn({ + move || { + for rpc_handler in crate::ipc::listen_unix() { + std::thread::spawn({ + move || { + log::trace!("Session established."); + let _ = session(rpc_handler); + log::trace!("Session closed."); + } + }); + } + } + }); + scope.spawn({ + move || { + for rpc_handler in crate::ipc::listen_mmap() { + std::thread::spawn({ + move || { + log::trace!("Session established."); + let _ = session(rpc_handler); + log::trace!("Session closed."); + } + }); + } + } + }); + loop { + let mut sig: i32 = 0; + unsafe { + let mut set: libc::sigset_t = std::mem::zeroed(); + libc::sigemptyset(&mut set); + libc::sigaddset(&mut set, libc::SIGHUP); + libc::sigaddset(&mut set, libc::SIGTERM); + libc::sigwait(&set, &mut sig); + } + match sig { + libc::SIGHUP => { + std::process::exit(0); + } + libc::SIGTERM => { + std::process::exit(0); + } + _ => (), + } + } + }); +} + +fn session(handler: RpcHandler) -> Result<(), IpcError> { + use crate::ipc::server::RpcHandle; + match handler.handle()? { + RpcHandle::Create { x, .. } => x.reset(FriendlyError::Upgrade)?, + RpcHandle::Search { x, .. } => x.reset(FriendlyError::Upgrade)?, + RpcHandle::Insert { x, .. } => x.reset(FriendlyError::Upgrade)?, + RpcHandle::Delete { x, .. } => x.reset(FriendlyError::Upgrade)?, + RpcHandle::Flush { x, .. } => x.reset(FriendlyError::Upgrade)?, + RpcHandle::Destory { x, .. } => x.reset(FriendlyError::Upgrade)?, + RpcHandle::Stat { x, .. } => x.reset(FriendlyError::Upgrade)?, + RpcHandle::Vbase { x, .. } => x.reset(FriendlyError::Upgrade)?, + } +} diff --git a/src/index/am.rs b/src/index/am.rs index 684b6ad88..519bfc3c5 100644 --- a/src/index/am.rs +++ b/src/index/am.rs @@ -27,9 +27,9 @@ pub unsafe fn init() { } #[pgrx::pg_extern(sql = " - CREATE OR REPLACE FUNCTION vectors_amhandler(internal) RETURNS index_am_handler + CREATE FUNCTION vectors_amhandler(internal) RETURNS index_am_handler PARALLEL SAFE IMMUTABLE STRICT LANGUAGE c AS 'MODULE_PATHNAME', '@FUNCTION_NAME@'; -", requires = ["vecf32"])] +")] fn vectors_amhandler( _fcinfo: pgrx::pg_sys::FunctionCallInfo, ) -> pgrx::PgBox { diff --git a/src/ipc/client/mod.rs b/src/ipc/client/mod.rs index 9d4633e75..145f4aaf3 100644 --- a/src/ipc/client/mod.rs +++ b/src/ipc/client/mod.rs @@ -1,5 +1,5 @@ use super::packet::*; -use super::transport::Socket; +use super::transport::ClientSocket; use crate::gucs::{Transport, TRANSPORT}; use crate::utils::cells::PgRefCell; use service::index::IndexOptions; @@ -12,8 +12,8 @@ use std::ops::DerefMut; pub trait ClientLike: 'static { const RESET: bool = false; - fn from_socket(socket: Socket) -> Self; - fn to_socket(self) -> Socket; + fn from_socket(socket: ClientSocket) -> Self; + fn to_socket(self) -> ClientSocket; } pub struct ClientGuard(pub ManuallyDrop); @@ -43,17 +43,17 @@ impl DerefMut for ClientGuard { } pub struct Rpc { - socket: Socket, + socket: ClientSocket, } impl Rpc { - pub fn new(socket: Socket) -> Self { + pub fn new(socket: ClientSocket) -> Self { Self { socket } } pub fn create(self: &mut ClientGuard, id: Id, options: IndexOptions) { let packet = RpcPacket::Create { id, options }; - self.socket.client_send(packet).friendly(); - let create::CreatePacket::Leave {} = self.socket.client_recv().friendly(); + self.socket.send(packet).friendly(); + let create::CreatePacket::Leave {} = self.socket.recv().friendly(); } pub fn search( self: &mut ClientGuard, @@ -67,58 +67,56 @@ impl Rpc { search, prefilter, }; - self.socket.client_send(packet).friendly(); + self.socket.send(packet).friendly(); loop { - match self.socket.client_recv().friendly() { + match self.socket.recv().friendly() { search::SearchPacket::Check { p } => { self.socket - .client_send(search::SearchCheckPacket { result: t.check(p) }) + .send(search::SearchCheckPacket { result: t.check(p) }) .friendly(); } search::SearchPacket::Leave { result } => { - return result.friendly(); + return result; } } } } pub fn delete(self: &mut ClientGuard, id: Id, mut t: impl Delete) { let packet = RpcPacket::Delete { id }; - self.socket.client_send(packet).friendly(); + self.socket.send(packet).friendly(); loop { - match self.socket.client_recv().friendly() { + match self.socket.recv().friendly() { delete::DeletePacket::Test { p } => { self.socket - .client_send(delete::DeleteTestPacket { delete: t.test(p) }) + .send(delete::DeleteTestPacket { delete: t.test(p) }) .friendly(); } - delete::DeletePacket::Leave { result } => { - return result.friendly(); + delete::DeletePacket::Leave {} => { + return; } } } } pub fn insert(self: &mut ClientGuard, id: Id, insert: (DynamicVector, Pointer)) { let packet = RpcPacket::Insert { id, insert }; - self.socket.client_send(packet).friendly(); - let insert::InsertPacket::Leave { result } = self.socket.client_recv().friendly(); - result.friendly() + self.socket.send(packet).friendly(); + let insert::InsertPacket::Leave {} = self.socket.recv().friendly(); } pub fn flush(self: &mut ClientGuard, id: Id) { let packet = RpcPacket::Flush { id }; - self.socket.client_send(packet).friendly(); - let flush::FlushPacket::Leave { result } = self.socket.client_recv().friendly(); - result.friendly() + self.socket.send(packet).friendly(); + let flush::FlushPacket::Leave {} = self.socket.recv().friendly(); } pub fn destory(self: &mut ClientGuard, ids: Vec) { let packet = RpcPacket::Destory { ids }; - self.socket.client_send(packet).friendly(); - let destory::DestoryPacket::Leave {} = self.socket.client_recv().friendly(); + self.socket.send(packet).friendly(); + let destory::DestoryPacket::Leave {} = self.socket.recv().friendly(); } pub fn stat(self: &mut ClientGuard, id: Id) -> IndexStat { let packet = RpcPacket::Stat { id }; - self.socket.client_send(packet).friendly(); - let stat::StatPacket::Leave { result } = self.socket.client_recv().friendly(); - result.friendly() + self.socket.send(packet).friendly(); + let stat::StatPacket::Leave { result } = self.socket.recv().friendly(); + result } pub fn vbase( mut self: ClientGuard, @@ -126,9 +124,8 @@ impl Rpc { vbase: (DynamicVector, usize), ) -> ClientGuard { let packet = RpcPacket::Vbase { id, vbase }; - self.socket.client_send(packet).friendly(); - let vbase::VbaseErrorPacket { result } = self.socket.client_recv().friendly(); - result.friendly(); + self.socket.send(packet).friendly(); + let vbase::VbaseErrorPacket {} = self.socket.recv().friendly(); ClientGuard::map(self) } } @@ -136,11 +133,11 @@ impl Rpc { impl ClientLike for Rpc { const RESET: bool = true; - fn from_socket(socket: Socket) -> Self { + fn from_socket(socket: ClientSocket) -> Self { Self { socket } } - fn to_socket(self) -> Socket { + fn to_socket(self) -> ClientSocket { self.socket } } @@ -154,30 +151,30 @@ pub trait Delete { } pub struct Vbase { - socket: Socket, + socket: ClientSocket, } impl Vbase { pub fn next(self: &mut ClientGuard) -> Option { let packet = vbase::VbasePacket::Next {}; - self.socket.client_send(packet).friendly(); - let vbase::VbaseNextPacket { p } = self.socket.client_recv().friendly(); + self.socket.send(packet).friendly(); + let vbase::VbaseNextPacket { p } = self.socket.recv().friendly(); p } pub fn leave(mut self: ClientGuard) -> ClientGuard { let packet = vbase::VbasePacket::Leave {}; - self.socket.client_send(packet).friendly(); - let vbase::VbaseLeavePacket {} = self.socket.client_recv().friendly(); + self.socket.send(packet).friendly(); + let vbase::VbaseLeavePacket {} = self.socket.recv().friendly(); ClientGuard::map(self) } } impl ClientLike for Vbase { - fn from_socket(socket: Socket) -> Self { + fn from_socket(socket: ClientSocket) -> Self { Self { socket } } - fn to_socket(self) -> Socket { + fn to_socket(self) -> ClientSocket { self.socket } } @@ -185,7 +182,7 @@ impl ClientLike for Vbase { enum Status { Borrowed, Lost, - Reset(Socket), + Reset(ClientSocket), } static CLIENT: PgRefCell = unsafe { PgRefCell::new(Status::Lost) }; @@ -224,10 +221,9 @@ impl Drop for ClientGuard { let mut x = CLIENT.borrow_mut(); match *x { Status::Borrowed => { - if T::RESET { - unsafe { - *x = Status::Reset(ManuallyDrop::take(&mut self.0).to_socket()); - } + let socket = unsafe { ManuallyDrop::take(&mut self.0).to_socket() }; + if T::RESET && socket.test() { + *x = Status::Reset(socket); } else { *x = Status::Lost; } diff --git a/src/ipc/mod.rs b/src/ipc/mod.rs index f93df1b41..5efd87a3b 100644 --- a/src/ipc/mod.rs +++ b/src/ipc/mod.rs @@ -8,42 +8,43 @@ use service::prelude::*; use thiserror::Error; #[derive(Debug, Clone, Error)] -#[rustfmt::skip] pub enum IpcError { - #[error("\ -pgvecto.rs: IPC connection is closed unexpected. -ADVICE: The error is raisen by background worker errors. \ -Please check the full Postgresql log to get more information.\ -")] + #[error("IPC connection is closed unexpected.")] Closed, } impl FriendlyErrorLike for IpcError { - fn friendly(self) -> ! { - panic!("pgvecto.rs: {}", self); + fn convert(self) -> FriendlyError { + FriendlyError::Ipc } } pub fn listen_unix() -> impl Iterator { std::iter::from_fn(move || { - let socket = self::transport::Socket::Unix(self::transport::unix::accept()); + let socket = self::transport::ServerSocket::Unix(self::transport::unix::accept()); Some(self::server::RpcHandler::new(socket)) }) } pub fn listen_mmap() -> impl Iterator { std::iter::from_fn(move || { - let socket = self::transport::Socket::Mmap(self::transport::mmap::accept()); + let socket = self::transport::ServerSocket::Mmap(self::transport::mmap::accept()); Some(self::server::RpcHandler::new(socket)) }) } -pub fn connect_unix() -> self::transport::Socket { - self::transport::Socket::Unix(self::transport::unix::connect()) +pub fn connect_unix() -> self::transport::ClientSocket { + self::transport::ClientSocket::Unix { + ok: true, + socket: self::transport::unix::connect(), + } } -pub fn connect_mmap() -> self::transport::Socket { - self::transport::Socket::Mmap(self::transport::mmap::connect()) +pub fn connect_mmap() -> self::transport::ClientSocket { + self::transport::ClientSocket::Mmap { + ok: true, + socket: self::transport::mmap::connect(), + } } pub fn init() { diff --git a/src/ipc/packet/delete.rs b/src/ipc/packet/delete.rs index f1280ec61..393354f13 100644 --- a/src/ipc/packet/delete.rs +++ b/src/ipc/packet/delete.rs @@ -4,7 +4,7 @@ use service::prelude::*; #[derive(Debug, Serialize, Deserialize)] pub enum DeletePacket { Test { p: Pointer }, - Leave { result: Result<(), FriendlyError> }, + Leave {}, } #[derive(Debug, Serialize, Deserialize)] diff --git a/src/ipc/packet/flush.rs b/src/ipc/packet/flush.rs index d111f6f73..f39543d0c 100644 --- a/src/ipc/packet/flush.rs +++ b/src/ipc/packet/flush.rs @@ -1,7 +1,6 @@ use serde::{Deserialize, Serialize}; -use service::prelude::*; #[derive(Debug, Serialize, Deserialize)] pub enum FlushPacket { - Leave { result: Result<(), FriendlyError> }, + Leave {}, } diff --git a/src/ipc/packet/insert.rs b/src/ipc/packet/insert.rs index 9ba2008d6..b056d6c27 100644 --- a/src/ipc/packet/insert.rs +++ b/src/ipc/packet/insert.rs @@ -1,7 +1,6 @@ use serde::{Deserialize, Serialize}; -use service::prelude::*; #[derive(Debug, Serialize, Deserialize)] pub enum InsertPacket { - Leave { result: Result<(), FriendlyError> }, + Leave {}, } diff --git a/src/ipc/packet/search.rs b/src/ipc/packet/search.rs index a95c96b4f..0c96c7b3b 100644 --- a/src/ipc/packet/search.rs +++ b/src/ipc/packet/search.rs @@ -3,12 +3,8 @@ use service::prelude::*; #[derive(Debug, Serialize, Deserialize)] pub enum SearchPacket { - Check { - p: Pointer, - }, - Leave { - result: Result, FriendlyError>, - }, + Check { p: Pointer }, + Leave { result: Vec }, } #[derive(Debug, Serialize, Deserialize)] diff --git a/src/ipc/packet/stat.rs b/src/ipc/packet/stat.rs index de388e032..236602192 100644 --- a/src/ipc/packet/stat.rs +++ b/src/ipc/packet/stat.rs @@ -1,10 +1,7 @@ use serde::{Deserialize, Serialize}; use service::index::IndexStat; -use service::prelude::*; #[derive(Debug, Serialize, Deserialize)] pub enum StatPacket { - Leave { - result: Result, - }, + Leave { result: IndexStat }, } diff --git a/src/ipc/packet/vbase.rs b/src/ipc/packet/vbase.rs index bce914b32..4663a9c8c 100644 --- a/src/ipc/packet/vbase.rs +++ b/src/ipc/packet/vbase.rs @@ -2,9 +2,7 @@ use serde::{Deserialize, Serialize}; use service::prelude::*; #[derive(Debug, Serialize, Deserialize)] -pub struct VbaseErrorPacket { - pub result: Result<(), FriendlyError>, -} +pub struct VbaseErrorPacket {} #[derive(Debug, Serialize, Deserialize)] pub enum VbasePacket { diff --git a/src/ipc/server/mod.rs b/src/ipc/server/mod.rs index 9a60fe37d..eaeeac982 100644 --- a/src/ipc/server/mod.rs +++ b/src/ipc/server/mod.rs @@ -1,20 +1,20 @@ use super::packet::*; -use super::transport::Socket; +use super::transport::ServerSocket; use super::IpcError; use service::index::IndexOptions; use service::index::IndexStat; use service::prelude::*; pub struct RpcHandler { - socket: Socket, + socket: ServerSocket, } impl RpcHandler { - pub(super) fn new(socket: Socket) -> Self { + pub(super) fn new(socket: ServerSocket) -> Self { Self { socket } } pub fn handle(mut self) -> Result { - Ok(match self.socket.server_recv::()? { + Ok(match self.socket.recv::()? { RpcPacket::Create { id, options } => RpcHandle::Create { id, options, @@ -117,151 +117,167 @@ pub enum RpcHandle { } pub struct Create { - socket: Socket, + socket: ServerSocket, } impl Create { pub fn leave(mut self) -> Result { let packet = create::CreatePacket::Leave {}; - self.socket.server_send(packet)?; + self.socket.ok(packet)?; Ok(RpcHandler { socket: self.socket, }) } + pub fn reset(mut self, err: FriendlyError) -> Result { + self.socket.err(err) + } } pub struct Insert { - socket: Socket, + socket: ServerSocket, } impl Insert { - pub fn leave(mut self, result: Result<(), FriendlyError>) -> Result { - let packet = insert::InsertPacket::Leave { result }; - self.socket.server_send(packet)?; + pub fn leave(mut self) -> Result { + let packet = insert::InsertPacket::Leave {}; + self.socket.ok(packet)?; Ok(RpcHandler { socket: self.socket, }) } + pub fn reset(mut self, err: FriendlyError) -> Result { + self.socket.err(err) + } } pub struct Delete { - socket: Socket, + socket: ServerSocket, } impl Delete { pub fn next(&mut self, p: Pointer) -> Result { let packet = delete::DeletePacket::Test { p }; - self.socket.server_send(packet)?; - let delete::DeleteTestPacket { delete } = - self.socket.server_recv::()?; + self.socket.ok(packet)?; + let delete::DeleteTestPacket { delete } = self.socket.recv::()?; Ok(delete) } - pub fn leave(mut self, result: Result<(), FriendlyError>) -> Result { - let packet = delete::DeletePacket::Leave { result }; - self.socket.server_send(packet)?; + pub fn leave(mut self) -> Result { + let packet = delete::DeletePacket::Leave {}; + self.socket.ok(packet)?; Ok(RpcHandler { socket: self.socket, }) } + pub fn reset(mut self, err: FriendlyError) -> Result { + self.socket.err(err) + } } pub struct Search { - socket: Socket, + socket: ServerSocket, } impl Search { pub fn check(&mut self, p: Pointer) -> Result { let packet = search::SearchPacket::Check { p }; - self.socket.server_send(packet)?; + self.socket.ok(packet)?; let search::SearchCheckPacket { result } = - self.socket.server_recv::()?; + self.socket.recv::()?; Ok(result) } - pub fn leave( - mut self, - result: Result, FriendlyError>, - ) -> Result { + pub fn leave(mut self, result: Vec) -> Result { let packet = search::SearchPacket::Leave { result }; - self.socket.server_send(packet)?; + self.socket.ok(packet)?; Ok(RpcHandler { socket: self.socket, }) } + pub fn reset(mut self, err: FriendlyError) -> Result { + self.socket.err(err) + } } pub struct Flush { - socket: Socket, + socket: ServerSocket, } impl Flush { - pub fn leave(mut self, result: Result<(), FriendlyError>) -> Result { - let packet = flush::FlushPacket::Leave { result }; - self.socket.server_send(packet)?; + pub fn leave(mut self) -> Result { + let packet = flush::FlushPacket::Leave {}; + self.socket.ok(packet)?; Ok(RpcHandler { socket: self.socket, }) } + pub fn reset(mut self, err: FriendlyError) -> Result { + self.socket.err(err) + } } pub struct Destory { - socket: Socket, + socket: ServerSocket, } impl Destory { pub fn leave(mut self) -> Result { let packet = destory::DestoryPacket::Leave {}; - self.socket.server_send(packet)?; + self.socket.ok(packet)?; Ok(RpcHandler { socket: self.socket, }) } + pub fn reset(mut self, err: FriendlyError) -> Result { + self.socket.err(err) + } } pub struct Stat { - socket: Socket, + socket: ServerSocket, } impl Stat { - pub fn leave( - mut self, - result: Result, - ) -> Result { + pub fn leave(mut self, result: IndexStat) -> Result { let packet = stat::StatPacket::Leave { result }; - self.socket.server_send(packet)?; + self.socket.ok(packet)?; Ok(RpcHandler { socket: self.socket, }) } + pub fn reset(mut self, err: FriendlyError) -> Result { + self.socket.err(err) + } } pub struct Vbase { - socket: Socket, + socket: ServerSocket, } impl Vbase { - pub fn error(mut self, result: Result<(), FriendlyError>) -> Result { - self.socket - .server_send(vbase::VbaseErrorPacket { result })?; + pub fn error(mut self) -> Result { + self.socket.ok(vbase::VbaseErrorPacket {})?; Ok(VbaseHandler { socket: self.socket, }) } + pub fn reset(mut self, err: FriendlyError) -> Result { + self.socket.err(err) + } } pub struct VbaseHandler { - socket: Socket, + socket: ServerSocket, } impl VbaseHandler { pub fn handle(mut self) -> Result { - Ok(match self.socket.server_recv::()? { + Ok(match self.socket.recv::()? { vbase::VbasePacket::Next {} => VbaseHandle::Next { x: VbaseNext { socket: self.socket, }, }, vbase::VbasePacket::Leave {} => { - self.socket.server_send(vbase::VbaseLeavePacket {})?; + self.socket.ok(vbase::VbaseLeavePacket {})?; VbaseHandle::Leave { x: RpcHandler { socket: self.socket, @@ -278,13 +294,13 @@ pub enum VbaseHandle { } pub struct VbaseNext { - socket: Socket, + socket: ServerSocket, } impl VbaseNext { pub fn leave(mut self, p: Option) -> Result { let packet = vbase::VbaseNextPacket { p }; - self.socket.server_send(packet)?; + self.socket.ok(packet)?; Ok(VbaseHandler { socket: self.socket, }) diff --git a/src/ipc/transport/mmap.rs b/src/ipc/transport/mmap.rs index a240dca11..8f3cadb2c 100644 --- a/src/ipc/transport/mmap.rs +++ b/src/ipc/transport/mmap.rs @@ -3,7 +3,6 @@ use crate::utils::file_socket::FileSocket; use crate::utils::os::{futex_wait, futex_wake, memfd_create, mmap_populate}; use rustix::fd::{AsFd, OwnedFd}; use rustix::fs::FlockOperation; -use serde::{Deserialize, Serialize}; use std::cell::UnsafeCell; use std::io::ErrorKind; use std::sync::atomic::{AtomicU32, Ordering}; @@ -65,27 +64,25 @@ impl Socket { Err(e) => panic!("{:?}", e), } } - pub fn send(&mut self, packet: T) -> Result<(), IpcError> { - let buffer = bincode::serialize(&packet).expect("Failed to serialize"); + pub fn send(&mut self, packet: &[u8]) -> Result<(), IpcError> { unsafe { if self.is_server { - (*self.addr).server_send(&buffer); + (*self.addr).server_send(packet); } else { - (*self.addr).client_send(&buffer); + (*self.addr).client_send(packet); } } Ok(()) } - pub fn recv Deserialize<'a>>(&mut self) -> Result { - let buffer = unsafe { + pub fn recv(&mut self) -> Result, IpcError> { + let packet = unsafe { if self.is_server { (*self.addr).server_recv(|| self.test())? } else { (*self.addr).client_recv(|| self.test())? } }; - let result = bincode::deserialize::(&buffer).expect("Failed to deserialize"); - Ok(result) + Ok(packet) } } diff --git a/src/ipc/transport/mod.rs b/src/ipc/transport/mod.rs index 1e559ca3e..5103ed626 100644 --- a/src/ipc/transport/mod.rs +++ b/src/ipc/transport/mod.rs @@ -3,35 +3,76 @@ pub mod unix; use super::IpcError; use serde::{Deserialize, Serialize}; +use service::prelude::FriendlyError; -pub enum Socket { +pub enum ServerSocket { Unix(unix::Socket), Mmap(mmap::Socket), } -impl Socket { - pub fn client_send(&mut self, packet: T) -> Result<(), IpcError> { +pub enum ClientSocket { + Unix { ok: bool, socket: unix::Socket }, + Mmap { ok: bool, socket: mmap::Socket }, +} + +impl ServerSocket { + pub fn ok(&mut self, packet: T) -> Result<(), IpcError> { + let mut buffer = Vec::new(); + buffer.push(0u8); + buffer.extend(bincode::serialize(&packet).expect("Failed to serialize")); match self { - Socket::Unix(x) => x.send(packet), - Socket::Mmap(x) => x.send(packet), + Self::Unix(x) => x.send(&buffer), + Self::Mmap(x) => x.send(&buffer), } } - pub fn client_recv Deserialize<'a>>(&mut self) -> Result { + pub fn err(&mut self, err: FriendlyError) -> Result { + let mut buffer = Vec::new(); + buffer.push(1u8); + buffer.extend(bincode::serialize(&err).expect("Failed to serialize")); match self { - Socket::Unix(x) => x.recv(), - Socket::Mmap(x) => x.recv(), + Self::Unix(x) => x.send(&buffer)?, + Self::Mmap(x) => x.send(&buffer)?, } + Err(IpcError::Closed) } - pub fn server_send(&mut self, packet: T) -> Result<(), IpcError> { + pub fn recv Deserialize<'a>>(&mut self) -> Result { + let buffer = match self { + Self::Unix(x) => x.recv()?, + Self::Mmap(x) => x.recv()?, + }; + Ok(bincode::deserialize(&buffer).expect("Failed to deserialize.")) + } +} + +impl ClientSocket { + pub fn send(&mut self, packet: T) -> Result<(), IpcError> { + let buffer = bincode::serialize(&packet).expect("Failed to serialize"); match self { - Socket::Unix(x) => x.send(packet), - Socket::Mmap(x) => x.send(packet), + Self::Unix { ok, socket } => socket.send(&buffer).inspect(|_| *ok = false), + Self::Mmap { ok, socket } => socket.send(&buffer).inspect(|_| *ok = false), + } + } + pub fn recv Deserialize<'a>>(&mut self) -> Result { + let buffer = match self { + Self::Unix { ok, socket } => socket + .recv() + .inspect(|_| *ok = false) + .map_err(|_| FriendlyError::Ipc)?, + Self::Mmap { ok, socket } => socket + .recv() + .inspect(|_| *ok = false) + .map_err(|_| FriendlyError::Ipc)?, + }; + match buffer[0] { + 0u8 => Ok(bincode::deserialize(&buffer[1..]).expect("Failed to deserialize.")), + 1u8 => Err(bincode::deserialize(&buffer[1..]).expect("Failed to deserialize.")), + _ => unreachable!(), } } - pub fn server_recv Deserialize<'a>>(&mut self) -> Result { + pub fn test(&self) -> bool { match self { - Socket::Unix(x) => x.recv(), - Socket::Mmap(x) => x.recv(), + ClientSocket::Unix { ok, .. } => *ok, + ClientSocket::Mmap { ok, .. } => *ok, } } } diff --git a/src/ipc/transport/unix.rs b/src/ipc/transport/unix.rs index 8ba654baf..0f9164d9c 100644 --- a/src/ipc/transport/unix.rs +++ b/src/ipc/transport/unix.rs @@ -2,7 +2,6 @@ use super::IpcError; use crate::utils::file_socket::FileSocket; use byteorder::{ReadBytesExt, WriteBytesExt}; use rustix::fd::AsFd; -use serde::{Deserialize, Serialize}; use std::io::{Read, Write}; use std::os::unix::net::UnixStream; use std::sync::OnceLock; @@ -40,20 +39,18 @@ macro_rules! resolve_closed { } impl Socket { - pub fn send(&mut self, packet: T) -> Result<(), IpcError> { + pub fn send(&mut self, packet: &[u8]) -> Result<(), IpcError> { use byteorder::NativeEndian as N; - let buffer = bincode::serialize(&packet).expect("Failed to serialize"); - let len = u32::try_from(buffer.len()).expect("Packet is too large."); + let len = u32::try_from(packet.len()).expect("Packet is too large."); resolve_closed!(self.stream.write_u32::(len)); - resolve_closed!(self.stream.write_all(&buffer)); + resolve_closed!(self.stream.write_all(packet)); Ok(()) } - pub fn recv Deserialize<'a>>(&mut self) -> Result { + pub fn recv(&mut self) -> Result, IpcError> { use byteorder::NativeEndian as N; let len = resolve_closed!(self.stream.read_u32::()); - let mut buffer = vec![0u8; len as usize]; - resolve_closed!(self.stream.read_exact(&mut buffer)); - let packet = bincode::deserialize(&buffer).expect("Failed to deserialize."); + let mut packet = vec![0u8; len as usize]; + resolve_closed!(self.stream.read_exact(&mut packet)); Ok(packet) } } diff --git a/src/lib.rs b/src/lib.rs index 0c44c38e2..b79c06f8e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,6 +4,7 @@ #![feature(offset_of)] #![feature(arbitrary_self_types)] #![feature(lazy_cell)] +#![feature(never_type)] mod bgworker; mod datatype; @@ -33,7 +34,7 @@ unsafe extern "C" fn _PG_init() { } } -#[cfg(not(any(target_os = "linux", target_os = "macos")))] +#[cfg(not(any(target_os = "linux", target_os = "macos", target_os = "freebsd")))] compile_error!("Target is not supported."); #[cfg(not(target_endian = "little"))] diff --git a/src/utils/os.rs b/src/utils/os.rs index 5332f8cf1..5fd9a890e 100644 --- a/src/utils/os.rs +++ b/src/utils/os.rs @@ -1,12 +1,11 @@ use rustix::fd::{AsFd, OwnedFd}; use rustix::mm::{MapFlags, ProtFlags}; -use std::io::ErrorKind; use std::sync::atomic::AtomicU32; -use std::sync::LazyLock; #[cfg(target_os = "linux")] -static SUPPORT_MEMFD: LazyLock = LazyLock::new(|| { +static SUPPORT_MEMFD: std::sync::LazyLock = std::sync::LazyLock::new(|| { use rustix::fs::MemfdFlags; + use std::io::ErrorKind; match rustix::fs::memfd_create(".memfd.VECTORS.SUPPORT", MemfdFlags::empty()) { Ok(_) => true, Err(e) if e.kind() == ErrorKind::Unsupported => false, @@ -139,3 +138,64 @@ pub unsafe fn mmap_populate(len: usize, fd: impl AsFd) -> std::io::Result<*mut l )?) } } + +#[cfg(target_os = "freebsd")] +pub unsafe fn futex_wait(futex: &AtomicU32, value: u32) { + let ptr: *const AtomicU32 = futex; + unsafe { + libc::_umtx_op( + ptr as *mut libc::c_void, + libc::UMTX_OP_WAIT_UINT, + value as libc::c_ulong, + core::ptr::null_mut(), + core::ptr::null_mut(), + ); + }; +} + +#[cfg(target_os = "freebsd")] +pub unsafe fn futex_wake(futex: &AtomicU32) { + let ptr: *const AtomicU32 = futex; + unsafe { + libc::_umtx_op( + ptr as *mut libc::c_void, + libc::UMTX_OP_WAKE, + i32::MAX as libc::c_ulong, + core::ptr::null_mut(), + core::ptr::null_mut(), + ); + }; +} + +#[cfg(target_os = "freebsd")] +pub fn memfd_create() -> std::io::Result { + use rustix::fs::Mode; + use rustix::fs::OFlags; + let name = format!( + ".shm.VECTORS.{:x}.{:x}", + std::process::id(), + rand::random::() + ); + let fd = rustix::fs::open( + &name, + OFlags::RDWR | OFlags::CREATE | OFlags::EXCL, + Mode::RUSR | Mode::WUSR, + )?; + rustix::fs::unlink(&name)?; + Ok(fd) +} + +#[cfg(target_os = "freebsd")] +pub unsafe fn mmap_populate(len: usize, fd: impl AsFd) -> std::io::Result<*mut libc::c_void> { + use std::ptr::null_mut; + unsafe { + Ok(rustix::mm::mmap( + null_mut(), + len, + ProtFlags::READ | ProtFlags::WRITE, + MapFlags::SHARED, + fd, + 0, + )?) + } +}