Unable to delete a record in Milvus collection

419 views Asked by At

The below code I have executed to delete a record from Milvus collection. There is no error but the respective record also not deleted.

Please recommend solution for this

from pymilvus import connections,Collection,db,utility,FieldSchema, CollectionSchema

def connectVectorDB(**conStrings):
    try:
        milvusDB = connections.connect(
            #db_name=conStrings['dbName'],
            host=conStrings['hostname'],
            port=conStrings['port']
            )
        db.using_database(conStrings['dbName'])
        return milvusDB
    except Exception as err:
        raise err

dbConnections = connectVectorDB(dbName='default',hostname="localhost",port='19530')
myCol = Collection('DocStrings')

expression = "docID == 445341931317291845"
myCol.delete(expr=expression)
myCol.flush()
1

There are 1 answers

0
grey On

A couple of questions first:

  • What Milvus and PyMilvus verion are you using?
  • Is docId defined as a primary key in the collection?

Also in the example above you're using == which is not allowed before 2.3.2.

Before version 2.3.2:

Milvus only supports deleting entities with clearly specified primary keys, which can be achieved merely with the term expression in.

I.e. One may use boolean expressions like expr = "book_id in [0,1]" where book_id is defined as primary key.

Since 2.3.2 it is possible to delete entities not only by primary key, but also using complex boolean expressions:

Milvus supports deleting entities by primary key or complex boolean expressions. Deleting entities by primary key is much faster and lighter than deleting them by complex boolean expressions. This is because Milvus executes queries first when deleting data by complex boolean expressions.

It worth to mention that:

  • Deleted entities can still be retrieved immediately after the deletion if the consistency level is set lower than Strong.
  • Entities deleted beyond the pre-specified span of time for Time Travel cannot be retrieved again.
  • Frequent deletion operations will impact the system performance. Before deleting entities by comlpex boolean expressions, make sure the collection has been loaded.
  • Deleting entities by complex boolean expressions is not an atomic operation. Therefore, if it fails halfway through, some data may still be deleted.
  • Deleting entities by complex boolean expressions is supported only when the consistency is set to Bounded.

See: https://milvus.io/docs/delete_data.md