Skip to content

Modify driver.supportedDataTypes to support installed Postgres extension data type. Bypass validation for a column. #10056

@w1am

Description

@w1am

Feature Description

I'm using the pgvector extension in my database, which allows me to store data in a vector datatype and perform vector operations such as nearest neighbors with SELECT * FROM items WHERE embedding <-> '[3,1,2]' < 5;. However, TypeORM seems to have an entity validator method that verifies whether the datatype defined in my entity exists.

For instance, the following won't work because the vector datatype doesn't natively exist.

@Entity('items')
export class Item extends BaseEntity {
  @PrimaryGeneratedColumn("increment")
  name: number;

  @Column("vector")
  embedding: number[];
}

In raw SQL, this is how I would achieve it:

CREATE TABLE items (id bigserial PRIMARY KEY, embedding vector(3));
INSERT INTO items (embedding) VALUES ('[1,2,3]'), ('[4,5,6]');
SELECT * FROM items ORDER BY embedding <-> '[3,1,2]' LIMIT 5;

Is there a way to modify or bypass the validation for a column? I could create this column using raw SQL, but that defeats the purpose of using an ORM. Of course, bypassing seems like a terrible idea. Is there a way to do this?

The Solution

I would like to bypass the entity validation for a specific column, as I'm using a custom extension, pgvector, in my database. Defining the type in the TypeORM entity results in a validation error, since the vector datatype isn't natively supported by PostgreSQL.

As a side note, I've installed the extension manually using the command CREATE EXTENSION vector.

Considered Alternatives

I could create this column using raw SQL, but that defeats the purpose of using an ORM.

Additional Context

You may refer to the pgvector documentation https://github.com/pgvector/pgvector

Relevant Database Driver(s)

  • aurora-mysql
  • aurora-postgres
  • better-sqlite3
  • cockroachdb
  • cordova
  • expo
  • mongodb
  • mysql
  • nativescript
  • oracle
  • postgres
  • react-native
  • sap
  • spanner
  • sqlite
  • sqlite-abstract
  • sqljs
  • sqlserver

Are you willing to resolve this issue by submitting a Pull Request?

Yes, I have the time, but I don't know how to start. I would need guidance.

I no longer have the time as I'm not actively working on projects that use TypeORM.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions