Files
group_xinghuo_jinrong/scripts/kb/test_search.py
T

36 lines
1.1 KiB
Python
Raw Normal View History

"""快速测试 fin_* Milvus 检索(需先 build_collections 灌库)。"""
from __future__ import annotations
import sys
from pathlib import Path
ROOT = Path(__file__).resolve().parents[2]
sys.path.insert(0, str(ROOT))
from app.tool.embedding_tool import get_embedder
from app.tool.milvus_tool import get_milvus_client
e = get_embedder()
m = get_milvus_client()
try:
v = e.embed("R3中风险产品有哪些")
hits = m.search("fin_product", v, top_k=3)
print("=== 产品检索 ===")
for h in hits:
print(f"score={h.get('score', 0):.4f} | {(h.get('chunk_text') or '')[:100]}")
v2 = e.embed("开户需要什么材料")
hits2 = m.search("fin_faq", v2, top_k=3)
print("\n=== FAQ 检索 ===")
for h in hits2:
print(f"score={h.get('score', 0):.4f} | {(h.get('chunk_text') or '')[:100]}")
v3 = e.embed("投资者适当性匹配规则")
hits3 = m.search("fin_policy", v3, top_k=3)
print("\n=== 政策检索 ===")
for h in hits3:
print(f"score={h.get('score', 0):.4f} | {(h.get('chunk_text') or '')[:100]}")
finally:
m.close()