fix 代码整理

This commit is contained in:
zhouchengrong
2024-04-10 10:47:20 +08:00
parent 3960a19014
commit 49f5e0a4b5
2 changed files with 28 additions and 29 deletions

View File

@@ -29,16 +29,15 @@ def outfit_matcher(request_item: OutfitMatcher):
service = OutfitMaterTypeAware() service = OutfitMaterTypeAware()
all_items = request_item["query"] + request_item["database"] all_items = request_item["query"] + request_item["database"]
prepared_feature = {} prepared_feature = {}
have_features_data = []
no_have_features_data = []
temp_data = deepcopy(all_items)
# 连接milvus # 连接milvus
client = MilvusClient(uri=MILVUS_URL, token="root:Milvus", db_name="mixi") client = MilvusClient(uri=MILVUS_URL, token="root:Milvus", db_name="mixi")
try:
search_data = client.get(collection_name='mixi_outfit', ids=[item['item_name'] for item in all_items]) search_data = client.get(collection_name='mixi_outfit', ids=[item['item_name'] for item in all_items])
# 查询数据库,分成两批 需要过模型推理的和不需要的 # 查询数据库,分成两批 需要过模型推理的和不需要的
have_features_data = []
no_have_features_data = []
temp_data = deepcopy(all_items)
for td in temp_data: for td in temp_data:
for sd in search_data: for sd in search_data:
if td['item_name'] == sd['item_name']: if td['item_name'] == sd['item_name']:
@@ -61,9 +60,10 @@ def outfit_matcher(request_item: OutfitMatcher):
# 存入数据 # 存入数据
res = client.insert(collection_name="mixi_outfit", data=data) res = client.insert(collection_name="mixi_outfit", data=data)
# 断开连接 # 断开连接
client.close()
for d in data: for d in data:
prepared_feature[d['item_name']] = d['features'] prepared_feature[d['item_name']] = d['features']
finally:
client.close()
for hfd in have_features_data: for hfd in have_features_data:
prepared_feature[hfd['item_name']] = hfd['features'] prepared_feature[hfd['item_name']] = hfd['features']

View File

@@ -86,7 +86,6 @@ class SimilarMatch:
@RunTime @RunTime
def match_features(self): def match_features(self):
# 连接milvus
# 连接milvus # 连接milvus
client = MilvusClient(uri=MILVUS_URL, db_name="mixi") client = MilvusClient(uri=MILVUS_URL, db_name="mixi")
try: try: