-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathask.py
More file actions
36 lines (25 loc) · 998 Bytes
/
Copy pathask.py
File metadata and controls
36 lines (25 loc) · 998 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
"""交互式问答(框架版):加载 Chroma 索引,回答用户问题,并打印检索到的资料和相似度分数
运行前请先执行 python build_index.py
运行方式:
python ask.py
"""
from src.ingest import load_store
from src.qa import answer
def main():
store = load_store()
print("输入问题开始提问(输入 exit 退出)。\n")
while True:
question = input("你:").strip()
if question.lower() in ("exit", "quit", "q"):
break
if not question:
continue
reply, hits = answer(question, store, top_k=3)
print("\n--- 检索到的资料(按相似度排序)---")
for i, (text, score) in enumerate(hits):
preview = text.replace("\n", " ")[:50]
score_str = f"{score:.4f}" if score is not None else "?"
print(f" [{i+1}] 相似度={score_str} {preview}...")
print(f"\n助手:{reply}\n")
if __name__ == "__main__":
main()