typeorm icon indicating copy to clipboard operation
typeorm copied to clipboard

feat: Add vector as column type to postgres

Open strongpauly opened this issue 1 year ago • 19 comments

Description of change

Added vector as column type to postgres

Fixes #10056

Pull-Request Checklist

  • [x] Code is up-to-date with the master branch
  • [x] npm run format to apply prettier formatting
  • [x] npm run test passes with this change: N/A
  • [x] This pull request links relevant issues as Fixes #10056
  • [x] There are new or updated unit tests validating the change: N/A
  • [x] Documentation has been updated to reflect this change
  • [x] The new commits follow conventions explained in CONTRIBUTING.md

strongpauly avatar Jun 16 '23 16:06 strongpauly

Since vector seems a special use-case and requires the existence of the according extension in the db. I would recommend adding the vector type in a note below the regular types, stating that this needs pgvector to be present in order to work.

hinogi avatar Jul 09 '23 20:07 hinogi

Added a note in the English docs

strongpauly avatar Jul 22 '23 11:07 strongpauly

Hello @hinogi, it would be great to have such a feature in a new release, when can we expect it?

andreymyssak avatar Jul 29 '23 14:07 andreymyssak

This feature is needed but this PR is incomplete. It doesn't support passing dimensions, using indexes for approximate search, installing the extension automatically or have any tests. Pleases see #2423 as a reference.

Thore1954 avatar Jul 29 '23 15:07 Thore1954

Hello @hinogi, it would be great to have such a feature in a new release, when can we expect it?

I am not a maintainer, I just try to help out with additional code reviews and stuff.

hinogi avatar Jul 30 '23 09:07 hinogi

please merge this PR, I need the feature and forking isn't working!

GuilleAntico avatar Aug 15 '23 15:08 GuilleAntico

@strongpauly please update Postgres column types test with the new type to make sure synchronization works as expected

AlexMesser avatar Aug 19 '23 15:08 AlexMesser

Would be nice if you also update Postgres driver to install the extention automatically.

Thore1954 avatar Aug 19 '23 16:08 Thore1954

any news on this?

GuilleAntico avatar Sep 22 '23 16:09 GuilleAntico

Sorry, I can do nothing.

hinogi avatar Sep 23 '23 06:09 hinogi

I created this PR because it was a simple change that I was already hacking in in my codebase. However, the requested additions require more time than I can devote at the moment. Apologies. Feel free to take what I've started and expand upon it.

strongpauly avatar Sep 24 '23 19:09 strongpauly

@strongpauly how did you hack it?

I'm getting this error:

"DataTypeNotSupportedError: Data type \\\"vector\\\" in \\\"Entity.embedding\\\" is not supported by \\\"postgres\\\" database.

nrathi avatar Oct 06 '23 15:10 nrathi

import { ColumnType, DataSource, DataSourceOptions } from 'typeorm';
export const dataSourceFactory = (options?: DataSourceOptions): DataSource => {
    const dataSource = new DataSource(options);
    dataSource.driver.supportedDataTypes.push('vector' as ColumnType);
    dataSource.driver.withLengthColumnTypes.push('vector' as ColumnType);
    return dataSource;
};

strongpauly avatar Oct 06 '23 17:10 strongpauly

Comments in this PR must be addressed before it can be merged.

pleerock avatar Jan 02 '24 08:01 pleerock

Created https://github.com/typeorm/typeorm/pull/10789 to address the issues FYI @pleerock - can you please take a look?

firtoz avatar Mar 24 '24 17:03 firtoz

what's the status of this one would love to see this in typeorm! ❤️

lukasholzer avatar Apr 22 '24 20:04 lukasholzer

what's the status of this one would love to see this in typeorm! ❤️

@lukasholzer I have been using a build from my branch via https://github.com/typeorm/typeorm/pull/10789 which works quite well for my usecases.

I won't be able to update my code any more since I have moved on from typeorm to another ORM because of various issues, but anyone's free to spin off from it if they like.

firtoz avatar Apr 22 '24 21:04 firtoz

@firtoz thanks so much!

Out of curiosity which ORM did you choose and why? MikroORM?

lukasholzer avatar Apr 22 '24 21:04 lukasholzer

@lukasholzer trying out drizzle for now, the community and the repo feels active, may consider prisma if it doesn't work out

firtoz avatar Apr 22 '24 21:04 firtoz