Skip to content

Commit 60319f2

Browse files
authored
Merge pull request #51 from pinecone-io/delete-by-metadata-filter
Add delete by metadata filter support
2 parents 2c4b4c7 + 5bf47e1 commit 60319f2

File tree

11 files changed

+627
-51
lines changed

11 files changed

+627
-51
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# Changelog
22

33
## Unreleased Changes
4+
### Changed
5+
- 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.
6+
- Internally these requests are now sent as POST requests, though the previous DELETE api is still supported.
7+
48
## [2.0.9](https://github.com/pinecone-io/pinecone-python-client/compare/v2.0.8...v2.0.9)
59
### Changed
610
- Added [update](https://www.pinecone.io/docs/api/operation/update/) API. Allows updates to a vector and it's metadata.

pinecone/core/client/api/vector_operations_api.py

Lines changed: 126 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
none_type,
2727
validate_and_convert_types
2828
)
29+
from pinecone.core.client.model.delete_request import DeleteRequest
2930
from pinecone.core.client.model.describe_index_stats_response import DescribeIndexStatsResponse
3031
from pinecone.core.client.model.fetch_response import FetchResponse
3132
from pinecone.core.client.model.query_request import QueryRequest
@@ -50,6 +51,7 @@ def __init__(self, api_client=None):
5051

5152
def __delete(
5253
self,
54+
delete_request,
5355
**kwargs
5456
):
5557
"""Delete # noqa: E501
@@ -58,14 +60,13 @@ def __delete(
5860
This method makes a synchronous HTTP request by default. To make an
5961
asynchronous HTTP request, please pass async_req=True
6062
61-
>>> thread = api.delete(async_req=True)
63+
>>> thread = api.delete(delete_request, async_req=True)
6264
>>> result = thread.get()
6365
66+
Args:
67+
delete_request (DeleteRequest):
6468
6569
Keyword Args:
66-
ids ([str]): Vectors to delete.. [optional]
67-
delete_all (bool): This indicates that all vectors in the index namespace should be deleted.. [optional]
68-
namespace (str): The namespace to delete vectors from, if applicable.. [optional]
6970
_return_http_data_only (bool): response data without head status
7071
code and headers. Default is True.
7172
_preload_content (bool): if False, the urllib3.HTTPResponse object
@@ -110,6 +111,8 @@ def __delete(
110111
'_check_return_type', True
111112
)
112113
kwargs['_host_index'] = kwargs.get('_host_index')
114+
kwargs['delete_request'] = \
115+
delete_request
113116
return self.call_with_http_info(**kwargs)
114117

115118
self.delete = _Endpoint(
@@ -120,6 +123,124 @@ def __delete(
120123
],
121124
'endpoint_path': '/vectors/delete',
122125
'operation_id': 'delete',
126+
'http_method': 'POST',
127+
'servers': None,
128+
},
129+
params_map={
130+
'all': [
131+
'delete_request',
132+
],
133+
'required': [
134+
'delete_request',
135+
],
136+
'nullable': [
137+
],
138+
'enum': [
139+
],
140+
'validation': [
141+
]
142+
},
143+
root_map={
144+
'validations': {
145+
},
146+
'allowed_values': {
147+
},
148+
'openapi_types': {
149+
'delete_request':
150+
(DeleteRequest,),
151+
},
152+
'attribute_map': {
153+
},
154+
'location_map': {
155+
'delete_request': 'body',
156+
},
157+
'collection_format_map': {
158+
}
159+
},
160+
headers_map={
161+
'accept': [
162+
'application/json'
163+
],
164+
'content_type': [
165+
'application/json'
166+
]
167+
},
168+
api_client=api_client,
169+
callable=__delete
170+
)
171+
172+
def __delete1(
173+
self,
174+
**kwargs
175+
):
176+
"""Delete # noqa: E501
177+
178+
The `Delete` operation deletes vectors, by id, from a single namespace. You can delete items by their id, from a single namespace. # noqa: E501
179+
This method makes a synchronous HTTP request by default. To make an
180+
asynchronous HTTP request, please pass async_req=True
181+
182+
>>> thread = api.delete1(async_req=True)
183+
>>> result = thread.get()
184+
185+
186+
Keyword Args:
187+
ids ([str]): Vectors to delete.. [optional]
188+
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
189+
namespace (str): The namespace to delete vectors from, if applicable.. [optional]
190+
_return_http_data_only (bool): response data without head status
191+
code and headers. Default is True.
192+
_preload_content (bool): if False, the urllib3.HTTPResponse object
193+
will be returned without reading/decoding response data.
194+
Default is True.
195+
_request_timeout (int/float/tuple): timeout setting for this request. If
196+
one number provided, it will be total request timeout. It can also
197+
be a pair (tuple) of (connection, read) timeouts.
198+
Default is None.
199+
_check_input_type (bool): specifies if type checking
200+
should be done one the data sent to the server.
201+
Default is True.
202+
_check_return_type (bool): specifies if type checking
203+
should be done one the data received from the server.
204+
Default is True.
205+
_host_index (int/None): specifies the index of the server
206+
that we want to use.
207+
Default is read from the configuration.
208+
async_req (bool): execute request asynchronously
209+
210+
Returns:
211+
{str: (bool, date, datetime, dict, float, int, list, str, none_type)}
212+
If the method is called asynchronously, returns the request
213+
thread.
214+
"""
215+
kwargs['async_req'] = kwargs.get(
216+
'async_req', False
217+
)
218+
kwargs['_return_http_data_only'] = kwargs.get(
219+
'_return_http_data_only', True
220+
)
221+
kwargs['_preload_content'] = kwargs.get(
222+
'_preload_content', True
223+
)
224+
kwargs['_request_timeout'] = kwargs.get(
225+
'_request_timeout', None
226+
)
227+
kwargs['_check_input_type'] = kwargs.get(
228+
'_check_input_type', True
229+
)
230+
kwargs['_check_return_type'] = kwargs.get(
231+
'_check_return_type', True
232+
)
233+
kwargs['_host_index'] = kwargs.get('_host_index')
234+
return self.call_with_http_info(**kwargs)
235+
236+
self.delete1 = _Endpoint(
237+
settings={
238+
'response_type': ({str: (bool, date, datetime, dict, float, int, list, str, none_type)},),
239+
'auth': [
240+
'ApiKeyAuth'
241+
],
242+
'endpoint_path': '/vectors/delete',
243+
'operation_id': 'delete1',
123244
'http_method': 'DELETE',
124245
'servers': None,
125246
},
@@ -171,7 +292,7 @@ def __delete(
171292
'content_type': [],
172293
},
173294
api_client=api_client,
174-
callable=__delete
295+
callable=__delete1
175296
)
176297

177298
def __describe_index_stats(

0 commit comments

Comments
 (0)