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

Vector not deriving serde::Serialize & serde::Deserialize #6

Closed
turulix opened this issue Aug 24, 2023 · 7 comments
Closed

Vector not deriving serde::Serialize & serde::Deserialize #6

turulix opened this issue Aug 24, 2023 · 7 comments

Comments

@turulix
Copy link

turulix commented Aug 24, 2023

As the title says, would it be possible to derive Serialize & Deserialize for the Vector, so you can simply Serialize it into a json string using serde?

@ankane
Copy link
Member

ankane commented Sep 2, 2023

Hi @turulix, thanks for the suggestion. I'd like to keep Vector simple (and focused on DB interactions), so think it's better to convert to/from Vec<32> for serialization.

@ankane ankane closed this as completed Sep 2, 2023
@turulix
Copy link
Author

turulix commented Sep 2, 2023

Yes, but this requires a lot of work as a user since you have to manually convert between the Vector type and the Vec. This is a problem when using serde since there is no really clean way of doing this as far as im aware of. And deriving the two traits, this would be done automatically by serde. If you want to keep this simplistic, maybe put this feature behind a feature flag that isn't enabled by default but available as a quality or life feature

@appcypher
Copy link

As mentioned above, since pgvector::Vector wraps a Vec<f32>, it is trivial to implement a Serialize/Deserialize behind a serde feature flag.

I mean, this is a datatype fgs. It is not weird to expect that people will want to serialize it.

@turulix
Copy link
Author

turulix commented Oct 14, 2023

Made a fork which implements the Serialize & Deserialize in case you need it https://github.com/turulix/pgvector-rust

@appcypher
Copy link

appcypher commented Oct 14, 2023

Made a fork which implements the Serialize & Deserialize in case you need it https://github.com/turulix/pgvector-rust

Damn! Saw this a little late. I just did the same. Published as pgvec.
I will try to keep as up-to-date as possible but I'm sure these features will be added upstream in the future.

@turulix
Copy link
Author

turulix commented Oct 16, 2023

Oh sweet, i'm just gonna use yours then, since I didn't publish mine :)

ankane added a commit that referenced this issue Oct 17, 2023
@ankane
Copy link
Member

ankane commented Oct 17, 2023

Added a serde feature in the commit above (will go out with the next release)

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

No branches or pull requests

3 participants