Commit 656388d7 authored by 赵威's avatar 赵威

update device id

parent bc2780f3
...@@ -20,23 +20,25 @@ TAG_EMBEDDING_DICT = redis_client_db.hgetall("personas_tags_embedding") ...@@ -20,23 +20,25 @@ TAG_EMBEDDING_DICT = redis_client_db.hgetall("personas_tags_embedding")
@bind("strategy_embedding/personas_vector/match") @bind("strategy_embedding/personas_vector/match")
def match_tractate_by_device(device_id, n=10): def match_tractate_by_device(device_id, n=10):
try: try:
time_begin = time.time() if device_id not in ["0", "unknown"]:
business_tags = get_user_portrait_tag3_from_redis(device_id, tags_num=4).get("business_tags", []) time_begin = time.time()
# business_tags = ["假体下巴", "你好", "假体隆胸"] business_tags = get_user_portrait_tag3_from_redis(device_id, tags_num=4).get("business_tags", [])
res = [] # business_tags = ["假体下巴", "你好", "假体隆胸"]
vectors = [] res = []
for tag in business_tags: vectors = []
lst = json.loads(TAG_EMBEDDING_DICT.get(bytes(tag, "utf-8"), b"[]")) for tag in business_tags:
if lst: lst = json.loads(TAG_EMBEDDING_DICT.get(bytes(tag, "utf-8"), b"[]"))
vectors.append(np.array(lst).astype("float32")) if lst:
if vectors: vectors.append(np.array(lst).astype("float32"))
D, I = FAISS_TAGS_INDEX.search(np.array([np.average(vectors, axis=0)]).astype("float32"), n) if vectors:
res = I.tolist()[0] D, I = FAISS_TAGS_INDEX.search(np.array([np.average(vectors, axis=0)]).astype("float32"), n)
time_end = time.time() - time_begin res = I.tolist()[0]
if time_end > 0.04: time_end = time.time() - time_begin
send_performance_msg_to_dingtalk("match_tractate_by_device {} n={} cost {:.3f}ms".format( if time_end > 0.04:
device_id, n, time_end * 1000)) send_performance_msg_to_dingtalk("match_tractate_by_device {} n={} cost {:.3f}ms".format(
return res device_id, n, time_end * 1000))
return res
return []
except Exception as e: except Exception as e:
send_msg_to_dingtalk(str(traceback.format_exc())) send_msg_to_dingtalk(str(traceback.format_exc()))
return [] return []
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