Problem

Deletion of existing records in pgvector table fails due to a bug in SQL DELETE query. Both dev and alpha2 versions have this bug.

The bug is in the function PostgresPgvectorClient->deleteFromCollection(), line 239:

query: "DELETE FROM {$escaped_collection_name} WHERE drupal_entity_id IN {$prepared_ids};"

instead of 'drupal_entity_id' it should have 'id'.

Steps to reproduce

1. Use SELECT in PostgreSQL to see all records for a particular drupal_entity_id
2. Open that node for editing via Drupal UI
3. Hit Save button
4. Use SELECT again to see all records for the same drupal_entity_id
5. Verify that you have a duplicate set of records (number of records doubled) since none got deleted.

Proposed resolution

Replace the query on line 239 of PostgresPgvectorClient.php by this:

query: "DELETE FROM {$escaped_collection_name} WHERE id IN {$prepared_ids};"

User interface changes

None

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

calmforce created an issue. See original summary.

calmforce’s picture

StatusFileSize
new689 bytes

I made the change: replaced drupal_entity_id by id in the DELETE query.

Attached is the patch file.

To verify that the patch works:

1. Install the patch.
2. Use SELECT in PostgreSQL to see all records for a particular drupal_entity_id
3. Open that node for editing via Drupal UI
4. Hit Save button
5. Use SELECT again to see all records for the same drupal_entity_id
6. Verify that you DO NOT have a duplicate set of records, the number of records stay the same if no editing of the node was done.

This is the fix in GitLab:
https://git.drupalcode.org/issue/ai_vdb_provider_postgres-3553475/-/compare/1.0.x...3553475-deletion-of-chunks

calmforce’s picture

Status: Active » Needs review

calmforce’s picture

The patch tested locally, chunks properly deleted.
Created the Merge Request:
https://git.drupalcode.org/project/ai_vdb_provider_postgres/-/merge_requests/14

calmforce’s picture

StatusFileSize
new1.2 KB

The updated patch file with limit = 16384 is attached.