Skip to content

Commit

Permalink
add support for deletion and updation
Browse files Browse the repository at this point in the history
Signed-off-by: Jiffin Tony Thottan <[email protected]>
  • Loading branch information
jiffin committed Dec 6, 2024
1 parent 65f0f36 commit 72194d2
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions pythonvectordbceph.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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":
Expand Down Expand Up @@ -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 ''

Expand Down

0 comments on commit 72194d2

Please sign in to comment.