Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tracking issue for schema #255

Open
4 of 14 tasks
usamoi opened this issue Jan 11, 2024 · 10 comments
Open
4 of 14 tasks

Tracking issue for schema #255

usamoi opened this issue Jan 11, 2024 · 10 comments

Comments

@usamoi
Copy link
Collaborator

usamoi commented Jan 11, 2024

View https://docs.pgvecto.rs/reference/schema.html to see schema provided by pgvecto.rs.

Functions

pgvecto.rs are lack of helper functions, and we need to provide more helper functions.

Types

  • text representation of vector types, not documented
  • memory representation of vector types, not documented
  • binary representation of vector types, not documented
  • subscript behaviors of vector types, not documented

Schema

CI

  • check that you write a CREATE FUNCTION export_name SQL using the name _vectors_*_wrapper and the SQL is inconsistent with the signture defined in the code
  • check if a correct install script is located in ./src/install for a release

Contributing

If you want to export a user function to PostgreSQL:

  1. use pgrx::pg_extern and name the function _vectors_*
  2. write CREATE FUNCTION export_name in finalize.sql, you can use the name _vectors_*_wrapper here.

If you want to export a cast, operator or something else to PostgreSQL:

  1. use pgrx::pg_extern and name the function _vectors_*
  2. finish SQL in finalize.sql
@usamoi usamoi changed the title feat: helper functions Tracking issue for helper functions Jan 11, 2024
@usamoi usamoi changed the title Tracking issue for helper functions Tracking issue for schema Jan 11, 2024
@usamoi usamoi added the tracking-issue Tracking issue of a topic label Jan 11, 2024
@VoVAllen
Copy link
Member

Test logical replication between different extension version

@JoePassanante
Copy link
Contributor

JoePassanante commented Jan 13, 2024

Can you elaborate on

casts between vecf16 and half precision; PostgreSQL do not support half precision, we may make some decisions here

Is this an issue with postgres itself? or that it hasn't been implemented in pgvecto?

@usamoi
Copy link
Collaborator Author

usamoi commented Jan 13, 2024

Is this an issue with postgres itself?

Yes. PostgreSQL supports floating-type real (IEEE 754 binary 32) and floating type double precision (IEEE 754 binary 64), but there is not such a type named half precision (IEEE 754 binary 16). We probably cannot provide a cast between a vecf16 and an array. Another choice is providing a cast between vef16 and real[], which is "make some decisions here" refered.

@JoePassanante
Copy link
Contributor

JoePassanante commented Jan 13, 2024

Is this an issue with postgres itself?

Yes. PostgreSQL supports floating-type real (IEEE 754 binary 32) and floating type double precision (IEEE 754 binary 64), but there is not such a type named half precision (IEEE 754 binary 16). We probably cannot provide a cast between a vecf16 and an array. Another choice is providing a cast between vef16 and real[], which is "make some decisions here" refered.

Messaged over in the discord for some help getting the environment setup. But isn't this as simple as:

#[pgrx::pg_extern(immutable, parallel_safe, strict)]
fn _vectors_cast_vecf32_to_vecf16(
    vector: Vecf32Input<'_>,
    _typmod: i32,
    _explicit: bool,
) -> Vecf16Output {
    let data = vector
        .data()
        .iter()
        .map(|x| x.to_f32())
        .map(|x| f16::from_f32(x))
        .collect();

    Vecf16::new_in_postgres(data)
}

CREATE CAST (vector AS vecf16)
    WITH FUNCTION _vectors_cast_vecf32_to_vecf16(vector, integer, boolean) AS IMPLICIT;

@usamoi
Copy link
Collaborator Author

usamoi commented Jan 13, 2024

Is this an issue with postgres itself?

Yes. PostgreSQL supports floating-type real (IEEE 754 binary 32) and floating type double precision (IEEE 754 binary 64), but there is not such a type named half precision (IEEE 754 binary 16). We probably cannot provide a cast between a vecf16 and an array. Another choice is providing a cast between vef16 and real[], which is "make some decisions here" refered.

Messaged over in the discord for some help getting the environment setup. But isn't this as simple as:

#[pgrx::pg_extern(immutable, parallel_safe, strict)]
fn _vectors_cast_vecf32_to_vecf16(
    vector: Vecf32Input<'_>,
    _typmod: i32,
    _explicit: bool,
) -> Vecf16Output {
    let data = vector
        .data()
        .iter()
        .map(|x| x.to_f32())
        .map(|x| f16::from_f32(x))
        .collect();

    Vecf16::new_in_postgres(data)
}

CREATE CAST (vector AS vecf16)
    WITH FUNCTION _vectors_cast_vecf32_to_vecf16(vector, integer, boolean) AS IMPLICIT;

Yes.

  • casts between vector and vecf16
  • casts between vecf16 and half precision[]

It's two issues. You can talk only about the first one since you only need the first one.

@VoVAllen
Copy link
Member

I think float(2) is the same as fp16?

@usamoi
Copy link
Collaborator Author

usamoi commented Jan 13, 2024

I think float(2) is the same as fp16?

https://www.postgresql.org/docs/current/datatype-numeric.html#DATATYPE-FLOAT

I don't think so.

@my-vegetable-has-exploded
Copy link
Contributor

Is there more specific definition of absolute-value norm?

@usamoi
Copy link
Collaborator Author

usamoi commented Apr 11, 2024

Is there more specific definition of absolute-value norm?

https://en.wikipedia.org/wiki/Norm_(mathematics)

@my-vegetable-has-exploded
Copy link
Contributor

Is there more specific definition of absolute-value norm?

https://en.wikipedia.org/wiki/Norm_(mathematics)

I did not grasp the definition. How should we calculate it for a one-dimensional vector?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants