Example #1
0
 def del_milvus_collection(name):
     try:
         milvus = Milvus(host=MILVUS_ADDR, port=MILVUS_PORT)
         res = milvus.drop_collection(collection_name=name)
         if not res.OK():
             raise MilvusError(
                 "There was some error when drop milvus collection", res)
     except Exception as e:
         err_msg = "There was some error when delete milvus collection"
         logger.error(f"{err_msg} : {str(e)}", exc_info=True)
         raise MilvusError(err_msg, e)
Example #2
0
 def del_milvus_collection(name):
     milvus = Milvus()
     try:
         milvus.connect(MILVUS_ADDR, MILVUS_PORT)
         res = milvus.drop_collection(collection_name=name)
         if not res.OK():
             raise MilvusError(
                 "There has some error when drop milvus collection", res)
     except Exception as e:
         raise MilvusError(
             "There has some error when delete milvus collection", e)
Example #3
0
 def search_vectors(name, vector, topk, nprobe):
     search_param = {'nprobe': nprobe}
     try:
         milvus = Milvus(host=MILVUS_ADDR, port=MILVUS_PORT)
         res, ids = milvus.search(collection_name=name, query_records=vector, top_k=topk, params=search_param)
         if not res.OK():
             raise MilvusError("There was some error when search vectors", res)
         return ids
     except Exception as e:
         err_msg = "There was some error when search vectors"
         logger.error(f"{err_msg} : {str(e)}", exc_info=True)
         raise MilvusError(err_msg, e)
Example #4
0
 def insert_vectors(name, vectors):
     try:
         milvus = Milvus(host=MILVUS_ADDR, port=MILVUS_PORT)
         res, ids = milvus.insert(collection_name=name, records=vectors)
         if not res.OK():
             err_msg = "There was some error when insert vectors"
             logger.error(f"{err_msg} : {str(res)}", exc_info=True)
             raise MilvusError(err_msg, res)
         return ids
     except Exception as e:
         err_msg = "There was some error when insert vectors"
         logger.error(f"{err_msg} : {str(e)}", exc_info=True)
         raise MilvusError(err_msg, e)
Example #5
0
 def insert_vectors(name, vectors):
     milvus = Milvus()
     try:
         milvus.connect(MILVUS_ADDR, MILVUS_PORT)
         res, ids = milvus.insert(collection_name=name, records=vectors)
         if not res.OK():
             raise MilvusError("There has some error when insert vectors",
                               res)
         return ids
     except Exception as e:
         logger.error("There has some error when insert vectors",
                      exc_info=True)
         raise MilvusError("There has some error when insert vectors", e)
Example #6
0
 def search_vectors(name, vector, topk, nprobe):
     milvus = Milvus()
     search_param = {'nprobe': nprobe}
     try:
         milvus.connect(MILVUS_ADDR, MILVUS_PORT)
         res, ids = milvus.search(collection_name=name,
                                  query_records=vector,
                                  top_k=topk,
                                  params=search_param)
         if not res.OK():
             raise MilvusError("There has some error when search vectors",
                               res)
         return ids
     except Exception as e:
         raise MilvusError("There has some error when search vectors", e)
Example #7
0
 def new_milvus_collection(name, dimension, index_file_size, metric_type):
     metric_type = type_mapping.get(metric_type, MetricType.L2)
     try:
         milvus = Milvus(host=MILVUS_ADDR, port=MILVUS_PORT)
         parma = {
             "collection_name": name,
             "dimension": dimension,
             "index_file_size": index_file_size,
             "metric_type": metric_type
         }
         res = milvus.create_collection(parma)
         if not res.OK():
             raise MilvusError("There was some error when create milvus collection", res)
     except Exception as e:
         raise MilvusError("There was some error when create milvus collection", e)
Example #8
0
 def del_vectors(collection_name, ids):
     milvus = Milvus()
     try:
         milvus.connect(MILVUS_ADDR, MILVUS_PORT)
         milvus.delete_by_id(collection_name=collection_name, id_array=ids)
     except Exception as e:
         raise MilvusError("There has some error when delete vectors", e)
Example #9
0
 def del_vectors(collection_name, ids):
     try:
         milvus = Milvus(host=MILVUS_ADDR, port=MILVUS_PORT)
         milvus.delete_entity_by_id(collection_name=collection_name, id_array=ids)
     except Exception as e:
         err_msg = "There was some error when delete vectors"
         logger.error(f"{err_msg} : {str(e)}", exc_info=True)
         raise MilvusError(err_msg, e)