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.
This commit is contained in:
2026-09-09 20:00:06 +08:00
parent b841f68295
commit 2945108f66
26 changed files with 514 additions and 142 deletions
+25 -26
View File
@@ -1,6 +1,11 @@
"""快速测试 Milvus 检索是否正常工作。"""
"""快速测试 fin_* Milvus 检索(需先 build_collections 灌库)。"""
from __future__ import annotations
import sys
sys.path.insert(0, "d:/金融系统")
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
@@ -8,29 +13,23 @@ from app.tool.milvus_tool import get_milvus_client
e = get_embedder()
m = get_milvus_client()
# 测试产品检索
v = e.embed("R3中风险产品有哪些")
hits = m.search("fin_product", v, top_k=3)
print("=== 产品检索 ===")
for h in hits:
score = h.get("score", 0)
text = h.get("chunk_text", "")[:100]
print(f"score={score:.4f} | {text}")
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]}")
# 测试 FAQ 检索
v2 = e.embed("开户需要什么材料")
hits2 = m.search("fin_faq", v2, top_k=3)
print("\n=== FAQ 检索 ===")
for h in hits2:
score = h.get("score", 0)
text = h.get("chunk_text", "")[:100]
print(f"score={score:.4f} | {text}")
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:
score = h.get("score", 0)
text = h.get("chunk_text", "")[:100]
print(f"score={score:.4f} | {text}")
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()