import time from loguru import logger from app.services.milvus import Milvus from app.services.milvus_helpers import my_milvus from app.services.my_redis import MyRedis @logger.catch() async def build_recommendations(company_id: str, user_id: str) -> list[str]: MILVUS_CLI = my_milvus.get("cli") myredis = MyRedis() r = myredis.get_client() user_pk = r.hget(f"meeting_user_id_to_embedding_id_map:{company_id}", user_id) user_id_list = [] if user_pk: user_emb = await MILVUS_CLI.query_vector_by_pk( f"meeting_attendee_rec_{company_id}", int(user_pk) ) pk_list = await MILVUS_CLI.search_vectors( f"meeting_attendee_rec_{company_id}", [user_emb], 10 ) pk_list = [str(item) for item in pk_list] user_id_list = r.hmget( f"embedding_id_to_meeting_user_id_map:{company_id}", pk_list ) return user_id_list @logger.catch() async def build_recommendations_v2(company_id: str, user_id: str) -> list[str]: old_milvus = Milvus() myredis = MyRedis() r = myredis.get_client() user_pk = r.hget(f"meeting_user_id_to_embedding_id_map:{company_id}", user_id) user_id_list = [] if user_pk: start = time.perf_counter() user_emb = await old_milvus.query_embedding_by_pk( f"meeting_attendee_rec_{company_id}", "pk", int(user_pk) ) logger.debug(time.perf_counter() - start) start = time.perf_counter() pk_list = await old_milvus.search( [user_emb], f"meeting_attendee_rec_{company_id}", "embeddings", 10 ) logger.debug(time.perf_counter() - start) pk_list = [str(item) for item in pk_list] user_id_list = r.hmget( f"embedding_id_to_meeting_user_id_map:{company_id}", pk_list ) return user_id_list