langchain-ai / langchain-postgres

LangChain abstractions backed by Postgres Backend
MIT License
133 stars 48 forks source link

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

Open shamspias opened 1 month ago

shamspias commented 1 month ago

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

Additional Context