Commit 91c45347 authored by 赵威's avatar 赵威

add business_tags

parent cdb95f79
......@@ -23,24 +23,24 @@ def match_tractate_by_device(device_id, n=10):
if device_id not in ["0", "unknown", "87654"]:
time_begin = time.time()
business_tags = get_user_portrait_tag3_from_redis(device_id, tags_num=3).get("business_tags", [])
# business_tags = ["假体下巴", "你好", "假体隆胸"]
res = []
vectors = []
for tag in business_tags:
lst = json.loads(TAG_EMBEDDING_DICT.get(bytes(tag, "utf-8"), b"[]"))
if lst:
vectors.append(np.array(lst).astype("float32"))
if vectors:
D, I = FAISS_TAGS_INDEX.search(np.array([np.average(vectors, axis=0)]).astype("float32"), n)
distances = D.tolist()[0]
ids = I.tolist()[0]
for (index, i) in enumerate(distances):
if i <= 5.0:
res.append(ids[index])
time_end = time.time() - time_begin
if time_end > 0.04:
send_performance_msg_to_dingtalk("match_tractate_by_device {} n={} cost {:.3f}ms".format(
device_id, n, time_end * 1000))
if business_tags:
vectors = []
for tag in business_tags:
lst = json.loads(TAG_EMBEDDING_DICT.get(bytes(tag, "utf-8"), b"[]"))
if lst:
vectors.append(np.array(lst).astype("float32"))
if vectors:
D, I = FAISS_TAGS_INDEX.search(np.array([np.average(vectors, axis=0)]).astype("float32"), n)
distances = D.tolist()[0]
ids = I.tolist()[0]
for (index, i) in enumerate(distances):
if i <= 5.0:
res.append(ids[index])
time_end = time.time() - time_begin
if time_end > 0.04:
send_performance_msg_to_dingtalk("match_tractate_by_device {} n={} cost {:.3f}ms".format(
device_id, n, time_end * 1000))
return res
return []
except Exception as e:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment