Skip to content

fix: Vector dimension changes now trigger column recreation in migrations - #4276

Merged
marcelomendoncasoares merged 6 commits into
mainfrom
copilot/fix-vector-dimension-migration
Nov 25, 2025
Merged

marcelomendoncasoares merged 6 commits into
mainfrom
copilot/fix-vector-dimension-migration

Conversation

Copilot AI commented Nov 21, 2025 •

Copy link
Copy Markdown
Contributor

Changing a vector column's dimension (e.g., vector(1536) → vector(768)) generated migrations that did not update the database, causing schema mismatch warnings on server startup.

Root cause: The canMigrateTo method only checked column type and name, ignoring dimension changes. This caused the migration generator to skip dimension changes entirely.

Changes:

  • Modified ColumnComparisons.canMigrateTo to return false when vectorDimension differs, triggering drop/recreate logic
  • Added 12 tests covering dimension increases, decreases, and SQL generation verification

Migration behavior:

-- Vector dimension changes now generate:
ALTER TABLE "rag_document" DROP COLUMN "embedding";
ALTER TABLE "rag_document" ADD COLUMN "embedding" vector(768);

This is necessary because PostgreSQL's pgvector does not support ALTER TYPE for dimension changes. Migration warnings correctly flag this as a destructive operation.

Fixes #2495

Pre-launch Checklist

  • I read the Contribute page and followed the process outlined there for submitting PRs.
  • This update contains only one single feature or bug fix and nothing else. (If you are submitting multiple fixes, please make multiple PRs.)
  • I read and followed the Dart Style Guide and formatted the code with dart format.
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///), and made sure that the documentation follows the same style as other Serverpod documentation. I checked spelling and grammar.
  • I added new tests to check the change I am making.
  • All existing and new tests are passing.
  • Any breaking changes are documented below.

If you need help, consider asking for advice on the discussion board.

Breaking changes

Vector dimension changes will now be treated as destructive changes requiring column drop/recreate, which will result in data loss for the affected column. Users should backup their data before applying migrations that change vector dimensions.

Original prompt

This section details on the original issue you should resolve

<issue_title>Changing vector size in model does not seem to update the database when doing a migration</issue_title>
<issue_description>### Describe the bug

After doing a migration and applying it, I still get this error message when starting the server.

WARNING: The database does not match the target database:
 - Table "rag_document" is not like the target database:
 - Column "embedding" mismatch: 
   - expected vector dimension "768", found "1536".

To reproduce

  1. Create a table with a vector field of dimension 1536. Create and apply migration.
  2. Change the dimension to 768, create and apply a (forced) migration.
  3. Start the server and the error message above is displayed.

Expected behavior

The vector dimension is expected to be correct (768 in the example above)

Library version

2.9

Platform information

MacOS

Additional context

No response

How experienced are you with this library?

Expert - Experienced and comfortable with using this library in complex projects

Are you interested in working on a PR for this?

  • I want to work on this</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@coderabbitai

coderabbitai Bot commented Nov 21, 2025 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Tip

📝 Customizable high-level summaries are now available in beta!

You can now customize how CodeRabbit generates the high-level summary in your pull requests — including its content, structure, tone, and formatting.

  • Provide your own instructions using the high_level_summary_instructions setting.
  • Format the summary however you like (bullet lists, tables, multi-section layouts, contributor stats, etc.).
  • Use high_level_summary_in_walkthrough to move the summary from the description to the walkthrough section.

Example instruction:

"Divide the high-level summary into five sections:

  1. 📝 Description — Summarize the main change in 50–60 words, explaining what was done.
  2. 📓 References — List relevant issues, discussions, documentation, or related PRs.
  3. 📦 Dependencies & Requirements — Mention any new/updated dependencies, environment variable changes, or configuration updates.
  4. 📊 Contributor Summary — Include a Markdown table showing contributions:
    | Contributor | Lines Added | Lines Removed | Files Changed |
  5. ✔️ Additional Notes — Add any extra reviewer context.
    Keep each section concise (under 200 words) and use bullet or numbered lists for clarity."

Note: This feature is currently in beta for Pro-tier users, and pricing will be announced later.


Comment @coderabbitai help to get the list of available commands and usage tips.

Copilot AI and others added 3 commits November 21, 2025 19:44
- Fix canMigrateTo to detect vector dimension changes
- Add comprehensive tests for vector dimension migrations
- Vector dimension changes now properly trigger column drop/recreate

Co-authored-by: marcelomendoncasoares <[email protected]>
- Verify DROP COLUMN SQL is generated
- Verify ADD COLUMN with new dimension SQL is generated

Co-authored-by: marcelomendoncasoares <[email protected]>
Copilot AI changed the title [WIP] Fix vector size issue in database migration fix: Vector dimension changes now trigger column recreation in migrations Nov 21, 2025
@marcelomendoncasoares
marcelomendoncasoares marked this pull request as ready for review November 21, 2025 21:23

@marcelomendoncasoares marcelomendoncasoares left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

🤖

@marcelomendoncasoares
marcelomendoncasoares requested a review from a team November 21, 2025 21:24

@SandPod SandPod left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM!

One suggestion for improvements.

… setup duplication

Co-authored-by: marcelomendoncasoares <[email protected]>
@marcelomendoncasoares
marcelomendoncasoares merged commit 7f66a87 into main Nov 25, 2025
@marcelomendoncasoares
marcelomendoncasoares deleted the copilot/fix-vector-dimension-migration branch November 25, 2025 17:44
@github-actions github-actions Bot locked and limited conversation to collaborators Nov 25, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Changing vector size in model does not seem to update the database when doing a migration Add abstraction of requests and responses in Relic

3 participants