oyvindberg / typo

Typed Postgresql integration for Scala. Hopes to avoid typos
https://oyvindberg.github.io/typo/
MIT License
101 stars 11 forks source link

Support for pgvector #58

Closed sbrunk closed 1 year ago

sbrunk commented 1 year ago

@oyvindberg I continue to stumble over super interesting new libraries from you. Just did a quick test applying typo to a schema and some queries and it looks quite nice.

In that project, I'm using as Postgres extension called https://github.com/pgvector/pgvector, that defines its own vector type meant for fast similarity computations.

typo obviously doesn't know the type, so it generates a

case class TypoUnknownVector(value: String)

pgvector already has a JDBC integration, It defines a PGvector type that let's you map from and to arrays, i.e.

val insertStmt = conn.prepareStatement("INSERT INTO items (embedding) VALUES (?)")
insertStmt.setObject(1, new PGvector(Array[Float](1, 1, 1)))
insertStmt.executeUpdate()

See https://github.com/pgvector/pgvector-java/#jdbc-scala for details.

Is it possible to support such a custom type within typo and if so, what would be the recommended way to integrate it?

It was nice meeting you in person in Madrid BTW :)

sbrunk commented 1 year ago

Skimming over the code this could be CustomType I guess, but it's an external extension, not a core Postgres type of course.

oyvindberg commented 1 year ago

Hey there!

It looks very doable with a custom type. If you can manage to pack the extension into the docker image I'm using I can give it a shot.

It was nice meeting you in person in Madrid BTW :)

Definitely likewise! :)

sbrunk commented 1 year ago

Wow that was fast! I'm just playing with it, pumping vectors into my test DB and it's working great so far. Thanks a lot @oyvindberg!

SQL driven development using the IntelliJ editor for prototyping your queries in conjunction with typo really feels next level to me :)

oyvindberg commented 1 year ago

SQL driven development using the IntelliJ editor for prototyping your queries in conjunction with typo really feels next level to me :)

Glad to hear it, I feel it's such a great step forward. Spread the word when you have the chance :)