Repository navigation
feat: vectorchord - #18042
feat: vectorchord#18042
Conversation
|
Is there a migration path without having both extensions available at the same time? |
|
It should be possible to remove the references to the old extension manually with some queries before starting immich with the new extension. |
b024fbb to
878a80e
Compare
| @@ -1,13 +1,12 @@ | |||
| import { ConfigRepository } from 'src/repositories/config.repository'; | |||
| import { getVectorExtension } from 'src/repositories/database.repository'; | |||
There was a problem hiding this comment.
Why are you changing this? It's not great to keep needing to modify past migrations.
There was a problem hiding this comment.
Well, we're adding another extension so it's past the point of whether to modify the migration. The change is superficial, though, and won't change the actual behavior of the migration for existing extensions.
There is an option to instead remove TypeORM migrations as of 1.107 since we're setting that as a minimum, and it happens to include all the TypeORM vector migrations.
There was a problem hiding this comment.
Lol that's an option I guess. It would be nice to remove all of them at the same time. I guess it helps lessen the chance of bugs if that code path won't even be executed.
| config: DatabaseConnectionParams; | ||
| skipMigrations: boolean; | ||
| vectorExtension: VectorExtension; | ||
| vectorExtension?: VectorExtension; |
| import { vectorIndexQuery } from 'src/utils/database'; | ||
| import { isValidInteger } from 'src/validation'; | ||
| import { DataSource } from 'typeorm'; | ||
| import { DataSource, QueryRunner } from 'typeorm'; |
There was a problem hiding this comment.
Please stop adding in more typeorm imports...
ddbf125 to
6126ac7
Compare
There was a problem hiding this comment.
This repository is quite complex by now. Is that really necessary?
There was a problem hiding this comment.
It can't get much simpler without loss of functionality or robustness. The only optional parts are the auto-detection and correcting missing indices and embedding columns. The former is convenient, both for admins and for development, and the latter came up a lot during the 0.2.0 migration and resulted in people running their own SQL commands and making things worse. The more robust this code is, the less support burden we will have.
There was a problem hiding this comment.
I definitely wouldn't advocate for losing robustness. Wondering if we need to support this broad variety of extensions though.
334ed7d to
49beacc
Compare
update images for gha
Co-authored-by: Daniel Dietzler <36593685+danieldietzler@users.noreply.github.com>
7163b0c to
c1fa389
Compare
|
@mertalev Do extensions need to be dropped before "6. Remove the |
|
I didn't need to for the migration, but it's probably still a good idea to drop the old extension. I imagine it could cause issues with restoring from backups if it still exists. Maybe Immich should try to drop the extension too. |
|
I think we probably should consider doing that, if not with this release in the near future if we want to wait for safety. |
* 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>
| await sql`ALTER DATABASE ${dbName} SET vchordrq.prewarm_dim = '512,640,768,1024,1152,1536'`.execute(this.db); | ||
| await sql`SET vchordrq.prewarm_dim = '512,640,768,1024,1152,1536'`.execute(this.db); | ||
| await sql`ALTER DATABASE ${dbName} SET vchordrq.probes = 1`.execute(this.db); | ||
| await sql`SET vchordrq.probes = 1`.execute(this.db); |
There was a problem hiding this comment.
Isn't the version without ALTER DATABASE redundant? It also requires superuser privileges.
There was a problem hiding this comment.
It isn't because the parameters in alter database only take effect for new connections. You need to run the normal set version to make it apply to the current connection as well.
It shouldn't require superuser permission though - even the alter database command only requires db ownership, and the session-level version shouldn't require even that.
There was a problem hiding this comment.
You're right. I was erroneously assuming that SET means ALTER SYSTEM SET.
Description
This PR introduces support for VectorChord, the successor to pgvecto.rs. It's capable of higher QPS at the same recall, much faster indexing, lower RAM usage as well as better handling of inserts, updates and deletes. In addition, it is more integrated into Postgres using native indexing workers and memory management, and can coexist better with pgvector (which it comes bundled with).
The PR does not remove support for pgvecto.rs, meaning that the existing 0.2.0 image will continue to work, but will be deprecated in a future release. The correct extension to use (vchord, pgvecto.rs or pgvector) is autodetected at startup, and can be overridden with the
DB_VECTOR_EXTENSIONenvironmental variable. Switching between supported extensions is possible in this way as long as both extensions exist in the DB image. The intention is to make the migration as smooth as possible while giving both admins and build maintainers time to transition.However, upgrading directly from releases using TypeSense or pgvecto.rs 0.1.11 (i.e. releases before 1.95.0) is no longer supported as of this PR.However, upgrading directly from releases below 1.107.0 (released 10 months ago) is no longer supported as of this PR, as it assumes theface_searchrelation exists. Users on these old versions should upgrade to the release before this commit before upgrading to the latest.A quirk of VectorChord inherent to all IVF indices is that the optimal index parameters depend on the number of vectors. Since this is not something we know beforehand, there are checks in place to ensure roughly optimal settings at startup. This only takes place if the current settings are far from ideal so as to avoid frequent reindexing. The settings applied in this PR were tested for facial recognition with 15k vectors, 130k and 166k vectors to achieve very similar results to brute-force clustering. Smart search recall was tested at 1 million and 3.3 million vectors, but could benefit from similar testing with duplicate detection.
To do:
An informal facial recognition comparison with 166495 faces (min detection=0.2, min faces=8, max distance=0.4):
The selected VectorChord parameters are extremely biased in favor of quality and it still substantially outperforms pgvecto.rs in every metric.