2025-02-11 14:08:13 -05:00
|
|
|
import { DatabaseExtension } from 'src/enum';
|
2024-10-03 17:48:40 -04:00
|
|
|
import { ConfigRepository } from 'src/repositories/config.repository';
|
2023-12-08 11:15:46 -05:00
|
|
|
import { MigrationInterface, QueryRunner } from 'typeorm';
|
|
|
|
|
|
2024-10-03 17:48:40 -04:00
|
|
|
const vectorExtension = new ConfigRepository().getEnv().database.vectorExtension;
|
|
|
|
|
|
2023-12-08 11:15:46 -05:00
|
|
|
export class AddFaceEmbeddingIndex1700714033632 implements MigrationInterface {
|
|
|
|
|
name = 'AddFaceEmbeddingIndex1700714033632';
|
|
|
|
|
|
|
|
|
|
public async up(queryRunner: QueryRunner): Promise<void> {
|
2024-10-03 17:48:40 -04:00
|
|
|
if (vectorExtension === DatabaseExtension.VECTORS) {
|
2024-02-06 21:46:38 -05:00
|
|
|
await queryRunner.query(`SET vectors.pgvector_compatibility=on`);
|
|
|
|
|
}
|
|
|
|
|
await queryRunner.query(`SET search_path TO "$user", public, vectors`);
|
|
|
|
|
|
2023-12-08 11:15:46 -05:00
|
|
|
await queryRunner.query(`
|
|
|
|
|
CREATE INDEX IF NOT EXISTS face_index ON asset_faces
|
2024-02-06 21:46:38 -05:00
|
|
|
USING hnsw (embedding vector_cosine_ops)
|
|
|
|
|
WITH (ef_construction = 300, m = 16)`);
|
2023-12-08 11:15:46 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async down(queryRunner: QueryRunner): Promise<void> {
|
|
|
|
|
await queryRunner.query(`DROP INDEX IF EXISTS face_index`);
|
|
|
|
|
}
|
|
|
|
|
}
|