|
|
@@ -0,0 +1,25 @@
|
|
|
+import os
|
|
|
+import sys
|
|
|
+current_script_path = os.path.abspath(__file__)
|
|
|
+script_dir = os.path.dirname(current_script_path)
|
|
|
+project_root = os.path.abspath(os.path.join(script_dir, "../../"))
|
|
|
+if project_root not in sys.path:
|
|
|
+ sys.path.insert(0, project_root)
|
|
|
+from foundation.ai.rag.retrieval.retrieval import retrieval_manager
|
|
|
+
|
|
|
+query = "实体:通风孔;背景:在箱梁腹板上设置通风孔,用于结构内部空气流通,需保证与预应力钢筋保护层满足间距要求,并水平设置"
|
|
|
+collection = "first_bfp_collection" # 你的 Milvus 集合名
|
|
|
+
|
|
|
+# 二阶段:Milvus混合检索(向量+BM25) → BGE重排
|
|
|
+results = retrieval_manager.multi_stage_recall(
|
|
|
+ collection_name=collection,
|
|
|
+ query_text=query,
|
|
|
+ hybrid_top_k=50, # 第一阶段取多少候选
|
|
|
+ top_k=3, # 最终返回条数
|
|
|
+ ranker_type="weighted" # 或 "rrf"
|
|
|
+)
|
|
|
+
|
|
|
+print(results)
|
|
|
+for item in results:
|
|
|
+ print(item["rerank_score"], item["text_content"])
|
|
|
+ # 元数据在 item["metadata"](来自混合检索阶段)
|