# 1. Tạo embedding cho câu hỏi (Mặc định 1536 chiều như bro yêu cầu)
query_vector=awaitcreate_embedding_async(query)
ifnotquery_vector:
return"Xin lỗi, tôi gặp sự cố khi xử lý thông tin. Vui lòng thử lại sau."
v_str="["+",".join(str(v)forvinquery_vector)+"]"
# 2. Query StarRocks lấy Top 4 kết quả phù hợp nhất (Không check score)
sql=f"""
SELECT
content,
metadata
FROM shared_source.chatbot_rsa_knowledge
ORDER BY approx_cosine_similarity(embedding, {v_str}) DESC
LIMIT 4
"""
sr=get_db_connection()
results=awaitsr.execute_query_async(sql)
ifnotresults:
logger.warning(f"⚠️ No knowledge data found in DB for query: {query}")
return"Hiện tại tôi chưa tìm thấy thông tin chính xác về nội dung này trong hệ thống kiến thức của Canifa. Bạn có thể liên hệ hotline 1800 6061 để được hỗ trợ trực tiếp."
Hàm này tạo Prompt Module chuẩn để nhồi cho con Gemini.
Định nghĩa vai trò là Chuyên gia Fashion QC Agent.
"""
feedback_text=""
foridx,fbinenumerate(feedbacks):
feedback_text+=f"{idx+1}. User hỏi: '{fb['user_query']}' -> Bot trả lời: '{fb['bot_suggestion']}' -> User chửi: '{fb['feedback_note']}'\n"
prompt=f"""
You are an expert AI Fashion Quality Assurance (QA) Agent.
Your task is to fix logical flaws in the current 'fashion_rules.json' based on user bad-feedback.
=========== EXPLICIT INSTRUCTIONS ===========
1. Check what the users are angry about in the feedback.
2. Review the CURRENT RULES JSON.
3. Modify specific weight arrays or negative pairs to satisfy the user feedback. (For example, explicitly banning 'sweatshirt' for 'summer', or 'shorts' for 'formal_event').
4. Provide the FINAL COMPLETE JSON EXACTLY in the output format, properly structured.