Files
group_xinghuo_jinrong/scripts/kb/test_search.py
T
zhanghongyu_0626 2945108f66 feat(kb): Enhance knowledge base with new collections and search functionality
- Added new configuration for knowledge base root directory in `.env.example` and `settings.py`.
- Implemented `find_products` method in `CoreReadOnlyRepository` for fuzzy product search based on user queries.
- Introduced `search_cs_knowledge` function in `rag_service.py` to facilitate semantic search across new `fin_*` collections.
- Updated document parsing to support Markdown and YAML front-matter for knowledge base entries.
- Created multiple new FAQ and policy documents in the `data/kb_collections` directory to enrich the knowledge base.

This update significantly improves the knowledge retrieval capabilities for customer service interactions, ensuring more relevant and accurate responses.
2026-09-09 20:00:06 +08:00

36 lines
1.1 KiB
Python

"""快速测试 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()