Feature Request: Support Deleting Vectors by Metadata in PGVector Class #49

Open
opened 2026-02-16 05:16:18 -05:00 by yindo · 0 comments
Owner

Originally created by @shamspias on GitHub (Oct 15, 2024).

Currently, the PGVector class only allows deleting vectors by specifying their IDs through the delete and adelete methods. There is no built-in functionality to delete vectors based on metadata filters.

Proposed Solution

Modify the delete and adelete methods to accept an optional filter parameter. This parameter would allow users to specify conditions based on metadata fields, enabling the deletion of vectors that match these conditions. Utilize the existing _create_filter_clause method to generate the appropriate SQLAlchemy where clauses.

Example Usage

# Delete vectors where the 'category' metadata field equals 'news'
vector_store.delete(filter={"category": {"$eq": "news"}})

Benefits

  • Enhanced Functionality: Allows deletion of vectors based on metadata, improving data management capabilities.
  • Flexibility: Supports complex queries using existing filter mechanisms.
  • Backward Compatibility: The existing functionality of deleting by IDs remains unaffected.

Additional Context

  • Ensure that the _create_filter_clause method correctly handles all supported operators and edge cases.
  • Maintain consistency with the rest of the class's API design.
Originally created by @shamspias on GitHub (Oct 15, 2024). Currently, the `PGVector` class only allows deleting vectors by specifying their IDs through the `delete` and `adelete` methods. There is no built-in functionality to delete vectors based on metadata filters. ### **Proposed Solution** Modify the `delete` and `adelete` methods to accept an optional `filter` parameter. This parameter would allow users to specify conditions based on metadata fields, enabling the deletion of vectors that match these conditions. Utilize the existing `_create_filter_clause` method to generate the appropriate SQLAlchemy where clauses. ### **Example Usage** ```python # Delete vectors where the 'category' metadata field equals 'news' vector_store.delete(filter={"category": {"$eq": "news"}}) ``` ### **Benefits** - **Enhanced Functionality:** Allows deletion of vectors based on metadata, improving data management capabilities. - **Flexibility:** Supports complex queries using existing filter mechanisms. - **Backward Compatibility:** The existing functionality of deleting by IDs remains unaffected. ### **Additional Context** - Ensure that the `_create_filter_clause` method correctly handles all supported operators and edge cases. - Maintain consistency with the rest of the class's API design.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/langchain-postgres#49