mirror of
https://github.com/immich-app/immich.git
synced 2026-03-01 18:19:10 +03:00
feat: vectorchord (#18042)
* wip auto-detect available extensions auto-recovery, fix reindexing check use original image for ml * set probes * update image for sql checker update images for gha * cascade * fix new instance * accurate dummy vector * simplify dummy * preexisiting pg docs * handle different db name * maybe fix sql generation * revert refreshfaces sql change * redundant switch * outdated message * update docker compose files * Update docs/docs/administration/postgres-standalone.md Co-authored-by: Daniel Dietzler <36593685+danieldietzler@users.noreply.github.com> * tighten range * avoid always printing "vector reindexing complete" * remove nesting * use new images * add vchord to unit tests * debug e2e image * mention 1.107.2 in startup error * support new vchord versions --------- Co-authored-by: Daniel Dietzler <36593685+danieldietzler@users.noreply.github.com>
This commit is contained in:
@@ -6,7 +6,7 @@ import { BootstrapEventPriority, DatabaseExtension, DatabaseLock, VectorIndex }
|
||||
import { BaseService } from 'src/services/base.service';
|
||||
import { VectorExtension } from 'src/types';
|
||||
|
||||
type CreateFailedArgs = { name: string; extension: string; otherName: string };
|
||||
type CreateFailedArgs = { name: string; extension: string; otherExtensions: string[] };
|
||||
type UpdateFailedArgs = { name: string; extension: string; availableVersion: string };
|
||||
type RestartRequiredArgs = { name: string; availableVersion: string };
|
||||
type NightlyVersionArgs = { name: string; extension: string; version: string };
|
||||
@@ -25,18 +25,15 @@ const messages = {
|
||||
outOfRange: ({ name, version, range }: OutOfRangeArgs) =>
|
||||
`The ${name} extension version is ${version}, but Immich only supports ${range}.
|
||||
Please change ${name} to a compatible version in the Postgres instance.`,
|
||||
createFailed: ({ name, extension, otherName }: CreateFailedArgs) =>
|
||||
createFailed: ({ name, extension, otherExtensions }: CreateFailedArgs) =>
|
||||
`Failed to activate ${name} extension.
|
||||
Please ensure the Postgres instance has ${name} installed.
|
||||
|
||||
If the Postgres instance already has ${name} installed, Immich may not have the necessary permissions to activate it.
|
||||
In this case, please run 'CREATE EXTENSION IF NOT EXISTS ${extension}' manually as a superuser.
|
||||
In this case, please run 'CREATE EXTENSION IF NOT EXISTS ${extension} CASCADE' manually as a superuser.
|
||||
See https://immich.app/docs/guides/database-queries for how to query the database.
|
||||
|
||||
Alternatively, if your Postgres instance has ${otherName}, you may use this instead by setting the environment variable 'DB_VECTOR_EXTENSION=${otherName}'.
|
||||
Note that switching between the two extensions after a successful startup is not supported.
|
||||
The exception is if your version of Immich prior to upgrading was 1.90.2 or earlier.
|
||||
In this case, you may set either extension now, but you will not be able to switch to the other extension following a successful startup.`,
|
||||
Alternatively, if your Postgres instance has any of ${otherExtensions.join(', ')}, you may use one of them instead by setting the environment variable 'DB_VECTOR_EXTENSION=<extension name>'.`,
|
||||
updateFailed: ({ name, extension, availableVersion }: UpdateFailedArgs) =>
|
||||
`The ${name} extension can be updated to ${availableVersion}.
|
||||
Immich attempted to update the extension, but failed to do so.
|
||||
@@ -67,8 +64,7 @@ export class DatabaseService extends BaseService {
|
||||
}
|
||||
|
||||
await this.databaseRepository.withLock(DatabaseLock.Migrations, async () => {
|
||||
const envData = this.configRepository.getEnv();
|
||||
const extension = envData.database.vectorExtension;
|
||||
const extension = await this.databaseRepository.getVectorExtension();
|
||||
const name = EXTENSION_NAMES[extension];
|
||||
const extensionRange = this.databaseRepository.getExtensionVersionRange(extension);
|
||||
|
||||
@@ -97,12 +93,23 @@ export class DatabaseService extends BaseService {
|
||||
throw new Error(messages.invalidDowngrade({ name, extension, availableVersion, installedVersion }));
|
||||
}
|
||||
|
||||
await this.checkReindexing();
|
||||
try {
|
||||
await this.databaseRepository.reindexVectorsIfNeeded([VectorIndex.CLIP, VectorIndex.FACE]);
|
||||
} catch (error) {
|
||||
this.logger.warn(
|
||||
'Could not run vector reindexing checks. If the extension was updated, please restart the Postgres instance. If you are upgrading directly from a version below 1.107.2, please upgrade to 1.107.2 first.',
|
||||
);
|
||||
throw error;
|
||||
}
|
||||
|
||||
const { database } = this.configRepository.getEnv();
|
||||
if (!database.skipMigrations) {
|
||||
await this.databaseRepository.runMigrations();
|
||||
}
|
||||
await Promise.all([
|
||||
this.databaseRepository.prewarm(VectorIndex.CLIP),
|
||||
this.databaseRepository.prewarm(VectorIndex.FACE),
|
||||
]);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -110,10 +117,13 @@ export class DatabaseService extends BaseService {
|
||||
try {
|
||||
await this.databaseRepository.createExtension(extension);
|
||||
} catch (error) {
|
||||
const otherExtension =
|
||||
extension === DatabaseExtension.VECTORS ? DatabaseExtension.VECTOR : DatabaseExtension.VECTORS;
|
||||
const otherExtensions = [
|
||||
DatabaseExtension.VECTOR,
|
||||
DatabaseExtension.VECTORS,
|
||||
DatabaseExtension.VECTORCHORD,
|
||||
].filter((ext) => ext !== extension);
|
||||
const name = EXTENSION_NAMES[extension];
|
||||
this.logger.fatal(messages.createFailed({ name, extension, otherName: EXTENSION_NAMES[otherExtension] }));
|
||||
this.logger.fatal(messages.createFailed({ name, extension, otherExtensions }));
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
@@ -130,21 +140,4 @@ export class DatabaseService extends BaseService {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
private async checkReindexing() {
|
||||
try {
|
||||
if (await this.databaseRepository.shouldReindex(VectorIndex.CLIP)) {
|
||||
await this.databaseRepository.reindex(VectorIndex.CLIP);
|
||||
}
|
||||
|
||||
if (await this.databaseRepository.shouldReindex(VectorIndex.FACE)) {
|
||||
await this.databaseRepository.reindex(VectorIndex.FACE);
|
||||
}
|
||||
} catch (error) {
|
||||
this.logger.warn(
|
||||
'Could not run vector reindexing checks. If the extension was updated, please restart the Postgres instance.',
|
||||
);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user