Skip to content

[AI-180] Enable pgvector extension if available - #26210

Merged
machisuji merged 33 commits into
release/18.0from
implementation/ai-180-enable-pgvector-extension-if-available
Nov 11, 2026
Merged

machisuji merged 33 commits into
release/18.0from
implementation/ai-180-enable-pgvector-extension-if-available

Conversation

@joelpaulkoch

@joelpaulkoch joelpaulkoch commented Oct 21, 2026 •

Copy link
Copy Markdown
Collaborator

Ticket

https://community.openproject.org/projects/AI/work_packages/AI-180/

What are you trying to accomplish?

  1. Enable the pgvector extension because we need it for semantic search
  2. As pgvector might not be available (third party extension) keep the migration optional
  3. If pgvector is not available, disable features that depend on it (which is only semantic search for now)
  4. If pgvector is not available, show information after migration and in admin area
  5. Update CI, dev env, installation scripts, etc.
  6. Update documentation

Screenshots

Information displayed to Admins:

Screenshot 2026-10-21 at 16 52 29 Screenshot 2026-10-28 at 10 32 35 Image

What approach did you choose and why?

To enable pgvector, I added a migration that uses Extensions::Base as we do for the other extensions.
I've included updates to CI, dev environements, installation scripts, etc. so that we include pgvector everywhere.

As far as I can tell, we don't have any "optional" migrations yet. I am expecting that we will make pgvector mandatory in a future release too. For this reason I tried to keep everything as close to the existing patterns as possible.

The approach to make pgvector optional is therefore as follows:

  • migrations that depend on pgvector live in a separate directory (../migrate_requires_pgvector) which is not on the migrations_path used by Rails to run migrations
  • before running db:migrate we use a rake task to try to enable pgvector, as a check to find out if we actually can
  • only if this check succeeds we append the directory of the migrations that require pgvector to the migrations_path
  • we also remember the result of the check to disable features that depend on pgvector

Benefits:

  • it's very close to the existing patterns, to make pgvector mandatory we simply move the migrations to the usual path that is on Rails migration_path
  • as we are actually trying to enable pgvector, we catch all error cases (extension not available, not enough permissions, ..)

Downsides:

  • the migration to enable pgvector is strictly speaking obsolete at the moment, as our check will already enable it
  • as we are simply storing the result of the check in memory, we must restart the application after installing pgvector to check again and get access to features that depend on it

Alternatives considered:

  • make pgvector mandatory -> could cause issues during upgrade
  • allow admins to enable pgvector from admin area at runtime -> I wanted to avoid that and stick as much as possible to existing patterns

AI involvement

Collaborative – AI generated a substantial part of the code; I reviewed and understand every line.

Merge checklist

  • Added/updated tests
  • Added/updated documentation in Lookbook (patterns, previews, etc)
  • Tested major browsers (Chrome, Firefox, Edge, ...)

@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@github-actions github-actions Bot added the ai: Collaborative 💻 AI generated a substantial part of the code; A human reviewed and understands every line. label Oct 21, 2026
@github-actions

Copy link
Copy Markdown

Caution

The provided work package version does not match the core version

Details:

Please make sure that:

  • The work package version OR your pull request target branch is correct

@joelpaulkoch

Copy link
Copy Markdown
Collaborator Author

I have read the CLA Document and I hereby sign the CLA

@github-actions

Copy link
Copy Markdown

Warning

Flaky specs

  • rspec ./spec/features/components/lookbook_accessibility_spec.rb[1:14:1]
  • rspec ./spec/features/work_packages/table/delete_work_packages_with_descendants_spec.rb[1:1:1]
  • rspec ./spec/features/work_packages/table/queries/id_filter_spec.rb[1:1]
🤖 Ask Copilot to investigate

Copy the prompt below into a new comment on this PR to delegate the investigation to GitHub Copilot. It will look into the flakiness and open a separate pull request with you as reviewer.

@copilot The following spec(s) are flaky in CI (first seen on PR #26210, linked for reference only):

- `rspec ./spec/features/components/lookbook_accessibility_spec.rb[1:14:1]`
- `rspec ./spec/features/work_packages/table/delete_work_packages_with_descendants_spec.rb[1:1:1]`
- `rspec ./spec/features/work_packages/table/queries/id_filter_spec.rb[1:1]`

Treat this as a standalone task, unrelated to PR #26210. Create a new branch from origin/dev and open a new pull request targeting dev — do not stack it on PR #26210 or reuse that branch.

Follow the playbook in docs/development/testing/handling-flaky-tests/README.md to find the root cause and fix the underlying race — do not skip, delete, or weaken the spec to make it pass; disabling is a last resort per the playbook, and only with a bug ticket. Verify the fix by running the spec(s) repeatedly (e.g. `script/bulk_run_rspec --run-count 10`).

If you cannot reproduce the flake or are not confident in a fix after reasonable investigation, do not fabricate a change or skip the spec to force CI green. Instead, leave the pull request in draft and document what you tried, the suspected cause, and any leads in its description, then assign @joelpaulkoch to take over.

Once the fix is verified, title the PR after the spec(s) it fixes, and use the PR description to explain the root cause, how the change resolves it, and the before/after results. Label the PR `flaky-spec`, assign @joelpaulkoch, and request a review from @joelpaulkoch.
On every commit, set @joelpaulkoch as the sole co-author with a `Co-authored-by:` trailer (use their GitHub no-reply email so it links to their account), so it is traceable who dispatched the fix.

@github-actions

Copy link
Copy Markdown

Warning

Flaky specs

  • rspec ./modules/wikis/spec/features/admin/internal_provider_spec.rb[1:1]
  • rspec ./spec/features/admin/departments_spec.rb[1:2:3]
🤖 Ask Copilot to investigate

Copy the prompt below into a new comment on this PR to delegate the investigation to GitHub Copilot. It will look into the flakiness and open a separate pull request with you as reviewer.

@copilot The following spec(s) are flaky in CI (first seen on PR #26210, linked for reference only):

- `rspec ./modules/wikis/spec/features/admin/internal_provider_spec.rb[1:1]`
- `rspec ./spec/features/admin/departments_spec.rb[1:2:3]`

Treat this as a standalone task, unrelated to PR #26210. Create a new branch from origin/dev and open a new pull request targeting dev — do not stack it on PR #26210 or reuse that branch.

Follow the playbook in docs/development/testing/handling-flaky-tests/README.md to find the root cause and fix the underlying race — do not skip, delete, or weaken the spec to make it pass; disabling is a last resort per the playbook, and only with a bug ticket. Verify the fix by running the spec(s) repeatedly (e.g. `script/bulk_run_rspec --run-count 10`).

If you cannot reproduce the flake or are not confident in a fix after reasonable investigation, do not fabricate a change or skip the spec to force CI green. Instead, leave the pull request in draft and document what you tried, the suspected cause, and any leads in its description, then assign @joelpaulkoch to take over.

Once the fix is verified, title the PR after the spec(s) it fixes, and use the PR description to explain the root cause, how the change resolves it, and the before/after results. Label the PR `flaky-spec`, assign @joelpaulkoch, and request a review from @joelpaulkoch.
On every commit, set @joelpaulkoch as the sole co-author with a `Co-authored-by:` trailer (use their GitHub no-reply email so it links to their account), so it is traceable who dispatched the fix.

@joelpaulkoch
joelpaulkoch force-pushed the implementation/ai-180-enable-pgvector-extension-if-available branch from 45b00bb to 84b3696 Compare October 22, 2026 14:41
@joelpaulkoch
joelpaulkoch added this pull request to stack #26283 October 23, 2026 15:29

@oliverguenther oliverguenther left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A first preliminary pass:

  • I've tested that the application works fine without pgvector

  • pgvector also needs to be added to our docker-compose and helm-charts, if we want to roll this out as a default

  • pgvector docker image is not a docker official image, so there are no guarantees on when updates will be available. This is an important caveat for production systems

  • The image is pushed only on a pgvector release. I have not found individual releases. This means this image would not get postgres security updates unless manually built by the maintainer.

If you take a look at the current known vulnerabilities in the image, this becomes apparent:

postgres:17 (trixie): 88 high (2 critical) CVEs
This PR suggests to change to pgvector:pg17, which is Debian bookworkm:
pgvector/pgvector:pg17 (bookworm!): 129 high (16 critical)

If nothing else, this image should at least be changed to pgvector/pgvector:pg17-trixie , which has 89 high (2 critical).

If we want to ship this for production-ready systems, it would be easier to have an image built on our systems using the same logic on a schedule, to make sure we have an updated postgres ready and are not waiting for a maintainer to build theirs. This adds extra complexity however.

  • I'm not sure if the migration rake task extension works fine on saas, please double-check

Comment thread modules/llm/lib/tasks/pgvector.rake Resolved
@joelpaulkoch

Copy link
Copy Markdown
Collaborator Author

Thanks for the review, I've updated the image references to use debian trixie based images.

And I created a work package to track that we use a custom image instead: https://community.openproject.org/projects/AI/work_packages/AI-200/activity

FYI, they are planning to drop support for postgres 13 and 14 with the 0.9.0 release of pgvector: pgvector/pgvector#1042

Regarding

I'm not sure if the migration rake task extension works fine on saas, please double-check

in case of a fresh installation the task would not run as we would load the schema directly.
As we want to keep pgvector optional, it can't be included in the schema dump.
With 84c9b27 we always run the db:migrate task.

As far as I am aware, that was the only issue with the approach on saas.

Comment thread .github/workflows/packager.yml Resolved
Comment thread modules/llm/lib/tasks/pgvector.rake Resolved
@joelpaulkoch
joelpaulkoch force-pushed the implementation/ai-180-enable-pgvector-extension-if-available branch from ea9da11 to 7a85490 Compare October 28, 2026 10:02
@github-actions

Copy link
Copy Markdown

Warning

Flaky specs

  • rspec ./modules/documents/spec/features/documents/project/show_edit_document_spec.rb[1:1]
🤖 Ask Copilot to investigate

Copy the prompt below into a new comment on this PR to delegate the investigation to GitHub Copilot. It will look into the flakiness and open a separate pull request with you as reviewer.

@copilot The following spec(s) are flaky in CI (first seen on PR #26210, linked for reference only):

- `rspec ./modules/documents/spec/features/documents/project/show_edit_document_spec.rb[1:1]`

Treat this as a standalone task, unrelated to PR #26210. Create a new branch from origin/dev and open a new pull request targeting dev — do not stack it on PR #26210 or reuse that branch.

Follow the playbook in docs/development/testing/handling-flaky-tests/README.md to find the root cause and fix the underlying race — do not skip, delete, or weaken the spec to make it pass; disabling is a last resort per the playbook, and only with a bug ticket. Verify the fix by running the spec(s) repeatedly (e.g. `script/bulk_run_rspec --run-count 10`).

If you cannot reproduce the flake or are not confident in a fix after reasonable investigation, do not fabricate a change or skip the spec to force CI green. Instead, leave the pull request in draft and document what you tried, the suspected cause, and any leads in its description, then assign @joelpaulkoch to take over.

Once the fix is verified, title the PR after the spec(s) it fixes, and use the PR description to explain the root cause, how the change resolves it, and the before/after results. Label the PR `flaky-spec`, assign @joelpaulkoch, and request a review from @joelpaulkoch.
On every commit, set @joelpaulkoch as the sole co-author with a `Co-authored-by:` trailer (use their GitHub no-reply email so it links to their account), so it is traceable who dispatched the fix.

@joelpaulkoch
joelpaulkoch force-pushed the implementation/ai-180-enable-pgvector-extension-if-available branch from 7a85490 to 8cf949c Compare October 29, 2026 08:43
Comment thread modules/llm/lib/tasks/pgvector.rake Resolved
@joelpaulkoch
joelpaulkoch force-pushed the implementation/ai-180-enable-pgvector-extension-if-available branch from 8cf949c to dfc469f Compare October 29, 2026 15:26
@joelpaulkoch
joelpaulkoch removed this pull request from stack #26283 November 4, 2026 13:44
@joelpaulkoch
joelpaulkoch changed the base branch from dev to release/18.0 November 4, 2026 13:45
@joelpaulkoch
joelpaulkoch force-pushed the implementation/ai-180-enable-pgvector-extension-if-available branch from dfc469f to 5eee7af Compare November 4, 2026 13:47
@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown
1 Warning
⚠️ This PR has migration-related changes on a release branch. Ping @opf/operations

Generated by 🚫 Danger

@joelpaulkoch
joelpaulkoch added this pull request to stack #26642 November 4, 2026 13:50
@joelpaulkoch
joelpaulkoch removed this pull request from stack #26642 November 4, 2026 13:53
@joelpaulkoch
joelpaulkoch added this pull request to stack #26643 November 4, 2026 13:54
@joelpaulkoch
joelpaulkoch force-pushed the implementation/ai-180-enable-pgvector-extension-if-available branch 2 times, most recently from 10953c0 to f4c8eca Compare November 6, 2026 15:54
@joelpaulkoch
joelpaulkoch force-pushed the implementation/ai-180-enable-pgvector-extension-if-available branch from dd4ff6c to 145cc16 Compare November 11, 2026 16:47
@machisuji
machisuji merged commit 5c4f24c into release/18.0 Nov 11, 2026
22 checks passed
@machisuji
machisuji deleted the implementation/ai-180-enable-pgvector-extension-if-available branch November 11, 2026 17:04
@github-actions github-actions Bot locked and limited conversation to collaborators Nov 11, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

ai: Collaborative 💻 AI generated a substantial part of the code; A human reviewed and understands every line.

Development

Successfully merging this pull request may close these issues.

4 participants