Giter Club home page Giter Club logo

Comments (7)

bo0tzz avatar bo0tzz commented on June 14, 2024

That sounds correct, and would explain some issues we've seen. @mertalev thoughts?

from immich.

mertalev avatar mertalev commented on June 14, 2024

It does (or should I guess) check if it should update the smart search table at startup. Specifically, it checks if the dimensions of the current model match the dimensions in the table and updates the table if not. It's possible there's a bug somewhere in that logic, though.

from immich.

teamdest avatar teamdest commented on June 14, 2024

Apologies if I'm completely off on the wrong path, I don't know typescript at all or Javascript basically at all, but in the codebase I'm seeing the following control flow:

(inside the server section of the repo, and converting from the JS files on my drive to the TS files in the repo)

start.sh runs node on main -> src/main.js runs nestFactory.create() on apiModule -> src/app.module.ts constructor of ApiModule calls the init() of an ApiService -> src/services/api.service.ts calls init() on a databaseService -> src/services/database.service.ts

At this point, the following seems to occur:

  • if the postgres version is below the minimum major version, the code throws an error (14 is hardcoded as the minimum earlier in the file)
  • Attempts to lock the database with a lock of 'Databaselock.Migrations`
    • if this fails for some reason, nothing happens
  • If the lock succeeds:
    • Runs createVectorExtension() -> src/repositories/database.repository.ts runs a query of CREATE EXTENSION IF NOT EXISTS ${extension} where ${extension} is the preferred extension of vectors and vector. if this fails, an error is thrown
    • Runs updateVectorExtension() -> src/repositories/database.repository.ts
      • Compares the vector extension version to the expected one
      • If the version is outdated and the extension is vectors
        • Runs updateVectorSchema if the version is outdated
      • Runs a query setting the version of the extension to the expected one
      • if the version was not outdated, at this point it returns (note: it does not return an explicit value and I do not know what the default is in typescript?)
      • if the version WAS outdated
        • if the extension is vectors, run SELECT pgvectors_upgrade() and set "restartRequired" to TRUE
        • if the extension IS NOT vectors, run a reindex of FACE and CLIP indexes
          • At this point in the codepath, it seems to be updating the 'embeddings' column with a new dimSize
          • to get here, the extension would have to be "vector" (not "vectors") and an update had to happen
    • Runs assertVectorExtension() which just throws an error if the extension version is null, presumably as a final check that the above at least ~somewhat happened correctly.

Taking a brief break from bullet points to refocus: at this point we're at Line 36 of the database.service.ts file. At this point, the following happens:

  • shouldReindex is checked for each of FACE and CLIP -> src/repositories/database.repository.ts
    • if the extension isn't "vectors" it returns false immediately
    • if the extension IS "vectors", it runs SELECT idx_status FROM pg_vector_index_stat WHERE indexname for either FACE or CLIP
      • If the idx_status is "UPGRADE", it returns TRUE
      • if the idx_status is anything else, it returns FALSE
      • on error, if the response includes the words 'index is not existing', it returns TRUE
      • on error if the response includes the words 'relation "pg_vector_index_stat" does not exist', it returns FALSE
      • otherwise it throws the error
      • NOTE: this query returns NORMAL in my database for both items, so it would return FALSE

I am probably missing some sort of invalid state detail here. Maybe it's impossible to have it get to the end without it running this reindex at least once? But as I'm looking at it, it only gets to the point of running the reindex code (which is the code that does the dimSize column update) when an update to the vector extension was needed, which presumably never occurred here because this was a new install of an (idempotently-deployed) current version of the pgvecto.rs tensorchord container image.

from immich.

mertalev avatar mertalev commented on June 14, 2024

The check happens in the search repository's init, referenced in the smart info service.

from immich.

mertalev avatar mertalev commented on June 14, 2024

Oh, I guess the init in the smart info service isn't getting called anywhere haha.

from immich.

teamdest avatar teamdest commented on June 14, 2024

Ah, so it’s just not calling that unless you change the model while running?

from immich.

mertalev avatar mertalev commented on June 14, 2024

Yup, so it only updates on a config change event in practice. Making it run at startup should fix it.

from immich.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.