diff --git a/pythonvectordbceph.py b/pythonvectordbceph.py index 1331616..789f748 100644 --- a/pythonvectordbceph.py +++ b/pythonvectordbceph.py @@ -84,6 +84,7 @@ def pythonvectordbappceph(): # TODO: parse other metadatas and add to the collection event_data = json.loads(request.data) object_key = event_data['Records'][0]['s3']['object']['key'] + event_type = event_data['Records'][0]['eventName'] app.logger.debug(object_key) # Create collection which includes the id, object url, and embedded vector @@ -100,7 +101,14 @@ def pythonvectordbappceph(): client.create_index(collection_name=collection_name, index_params=index_params) app.logger.debug("collection " + collection_name + "created") + object_url = endpoint_url+ "/" + bucket_name + "/"+ object_key + client.load_collection(collection_name=collection_name) # define different functions below code snippet + if event_type == "ObjectRemoved:Delete": + exp = "url = " + object_url + res = client.delete(collection_name=collection_name, filter=exp) + app.logger.debug(res) + return "delete success" # delete success object_data = s3.get_object(Bucket=bucket_name, Key=object_key) match object_type: case "TEXT": @@ -134,13 +142,11 @@ def pythonvectordbappceph(): case _: app.logger.error("Unknown object format") - client.load_collection(collection_name=collection_name) - app.logger.debug(vector) object_url = endpoint_url+ "/" + bucket_name + "/"+ object_key data = [ {"embedded_vector": vector, "url": object_url} ] - res = client.insert(collection_name=collection_name, data=data) + res = client.upsert(collection_name=collection_name, data=data) app.logger.debug(res) return ''