test_rag copy.py 1.0 KB

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