Skip to content

Commit

Permalink
Merge pull request #51 from pinecone-io/delete-by-metadata-filter
Browse files Browse the repository at this point in the history
Add delete by metadata filter support
  • Loading branch information
benjaminran authored Apr 19, 2022
2 parents 2c4b4c7 + 5bf47e1 commit 60319f2
Show file tree
Hide file tree
Showing 11 changed files with 627 additions and 51 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Changelog

## Unreleased Changes
### Changed
- Added support for deleting vectors by metadata filter. The pinecone.Index.delete() api now accepts an additional filter= parameter which takes metadata filter expression equivalent to what query() supports.
- Internally these requests are now sent as POST requests, though the previous DELETE api is still supported.

## [2.0.9](https://github.com/pinecone-io/pinecone-python-client/compare/v2.0.8...v2.0.9)
### Changed
- Added [update](https://www.pinecone.io/docs/api/operation/update/) API. Allows updates to a vector and it's metadata.
Expand Down
131 changes: 126 additions & 5 deletions pinecone/core/client/api/vector_operations_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
none_type,
validate_and_convert_types
)
from pinecone.core.client.model.delete_request import DeleteRequest
from pinecone.core.client.model.describe_index_stats_response import DescribeIndexStatsResponse
from pinecone.core.client.model.fetch_response import FetchResponse
from pinecone.core.client.model.query_request import QueryRequest
Expand All @@ -50,6 +51,7 @@ def __init__(self, api_client=None):

def __delete(
self,
delete_request,
**kwargs
):
"""Delete # noqa: E501
Expand All @@ -58,14 +60,13 @@ def __delete(
This method makes a synchronous HTTP request by default. To make an
asynchronous HTTP request, please pass async_req=True
>>> thread = api.delete(async_req=True)
>>> thread = api.delete(delete_request, async_req=True)
>>> result = thread.get()
Args:
delete_request (DeleteRequest):
Keyword Args:
ids ([str]): Vectors to delete.. [optional]
delete_all (bool): This indicates that all vectors in the index namespace should be deleted.. [optional]
namespace (str): The namespace to delete vectors from, if applicable.. [optional]
_return_http_data_only (bool): response data without head status
code and headers. Default is True.
_preload_content (bool): if False, the urllib3.HTTPResponse object
Expand Down Expand Up @@ -110,6 +111,8 @@ def __delete(
'_check_return_type', True
)
kwargs['_host_index'] = kwargs.get('_host_index')
kwargs['delete_request'] = \
delete_request
return self.call_with_http_info(**kwargs)

self.delete = _Endpoint(
Expand All @@ -120,6 +123,124 @@ def __delete(
],
'endpoint_path': '/vectors/delete',
'operation_id': 'delete',
'http_method': 'POST',
'servers': None,
},
params_map={
'all': [
'delete_request',
],
'required': [
'delete_request',
],
'nullable': [
],
'enum': [
],
'validation': [
]
},
root_map={
'validations': {
},
'allowed_values': {
},
'openapi_types': {
'delete_request':
(DeleteRequest,),
},
'attribute_map': {
},
'location_map': {
'delete_request': 'body',
},
'collection_format_map': {
}
},
headers_map={
'accept': [
'application/json'
],
'content_type': [
'application/json'
]
},
api_client=api_client,
callable=__delete
)

def __delete1(
self,
**kwargs
):
"""Delete # noqa: E501
The `Delete` operation deletes vectors, by id, from a single namespace. You can delete items by their id, from a single namespace. # noqa: E501
This method makes a synchronous HTTP request by default. To make an
asynchronous HTTP request, please pass async_req=True
>>> thread = api.delete1(async_req=True)
>>> result = thread.get()
Keyword Args:
ids ([str]): Vectors to delete.. [optional]
delete_all (bool): This indicates that all vectors in the index namespace should be deleted.. [optional] if omitted the server will use the default value of False
namespace (str): The namespace to delete vectors from, if applicable.. [optional]
_return_http_data_only (bool): response data without head status
code and headers. Default is True.
_preload_content (bool): if False, the urllib3.HTTPResponse object
will be returned without reading/decoding response data.
Default is True.
_request_timeout (int/float/tuple): timeout setting for this request. If
one number provided, it will be total request timeout. It can also
be a pair (tuple) of (connection, read) timeouts.
Default is None.
_check_input_type (bool): specifies if type checking
should be done one the data sent to the server.
Default is True.
_check_return_type (bool): specifies if type checking
should be done one the data received from the server.
Default is True.
_host_index (int/None): specifies the index of the server
that we want to use.
Default is read from the configuration.
async_req (bool): execute request asynchronously
Returns:
{str: (bool, date, datetime, dict, float, int, list, str, none_type)}
If the method is called asynchronously, returns the request
thread.
"""
kwargs['async_req'] = kwargs.get(
'async_req', False
)
kwargs['_return_http_data_only'] = kwargs.get(
'_return_http_data_only', True
)
kwargs['_preload_content'] = kwargs.get(
'_preload_content', True
)
kwargs['_request_timeout'] = kwargs.get(
'_request_timeout', None
)
kwargs['_check_input_type'] = kwargs.get(
'_check_input_type', True
)
kwargs['_check_return_type'] = kwargs.get(
'_check_return_type', True
)
kwargs['_host_index'] = kwargs.get('_host_index')
return self.call_with_http_info(**kwargs)

self.delete1 = _Endpoint(
settings={
'response_type': ({str: (bool, date, datetime, dict, float, int, list, str, none_type)},),
'auth': [
'ApiKeyAuth'
],
'endpoint_path': '/vectors/delete',
'operation_id': 'delete1',
'http_method': 'DELETE',
'servers': None,
},
Expand Down Expand Up @@ -171,7 +292,7 @@ def __delete(
'content_type': [],
},
api_client=api_client,
callable=__delete
callable=__delete1
)

def __describe_index_stats(
Expand Down
Loading

0 comments on commit 60319f2

Please sign in to comment.