Migration
outline: [2,3]
PGVecto.rs Migration Overview
From pgvector
Prerequisites
When migrating from pgvector to PGVecto.rs, it is possible that you may have a table with a column of vector type. An example of this would be:
In addition, some rows will be inserted into the table, as follows:
In most cases, there will also be one or more vector indexes:
This is a typical scenario when pgvector is used. If the following requirements are met, the migration can be initiated.
- Please note that your
pgvectorextension is not installed in thevectorsschema. This means that you can installpgvectorandPGVecto.rsat the same time.
Steps to Migration
1. Install PGVecto.rs
Please follow the instructions provided to install PGVecto.rs and ensure that the extension is loaded by PostgreSQL.
The two extensions, pgvector and PGVecto.rs, are now installed at the PostgreSQL.
To validate the install, please run \dx in psql. You will see that there is an extension called vector for pgvector and another called vectors for PGVecto.rs.
Please note that there are some symbols with the same name in both extensions. This may cause confusion when doing the migration. To differentiate between the two, please verify that the search_path does not include the PGVecto.rs schema vectors.
2. Check existing indexes
For indexes created at vector columns, please retrieve the definition and record it in a convenient location. This information is necessary for the recovery of the indexes at a later stage.
3. Migrate vector columns
To migrate from a pgvector vector column, the first step is to create a PGVecto.rs vector column of the corresponding type. The subsequent step is to replicate the vector data from the original column to the new one.
Here provides the conversion path for each vector type of pgvector:
vector(pgvector) -> real[] -> vector(PGVecto.rs)halfvec -> vector(pgvector) -> real[] -> vector(PGVecto.rs) -> vecf16bit -> text[] -> real[] -> vector(PGVecto.rs) -> bvector
This vector type is not supported for migration yet:
sparsevec
Method 1: Conversion after validation
With this method, you can check the correctness of the vector data during the migration process, and you do not need to worry about the indexes that have been created on the vector columns, as they will be automatically deleted. However, it requires additional memory to store the vectors before and after the migration.
This step will cause some downtime, due to:
- a short
ACCESS EXCLUSIVElock byALTER TABLE ADD COLUMN - a much longer
ROW EXCLUSIVElock byUPDATE - a short
ACCESS EXCLUSIVElock byALTER TABLE DROP COLUMN
Once the data has been copied, you can check the data by SELECT and replace the existing column with the new one.
Method 2: Conversion without additional memory
With this method, the migration will be completed in one command and no additional memory is required. However, you need to delete the index on the vector column in advance.
This step will cause some downtime, due to:
- a long
ACCESS EXCLUSIVElock byALTER TABLE ALTER COLUMN
4. Recreate index
To recreate index on vector columns for PGVecto.rs , please enable the compatibility mode and create it like before.
For other vector types, such as halfvec, sparsevec, and bit, please refer to the indexing. Currently, pgvector_compatibility mode is not supported for these types.
5. Clean the environment
You may now safely remove the pgvector extension if it is no longer required.
In the event that the pgvector extension is removed, it is advisable to reset the search_path in order to ensure that symbols in PGVecto.rs are accessible globally.
Verify the result
Once the migration task is executed, you can verify the new columns by SELECT SQL.