Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

如何通过代码获得检索的top3文档? #5167

Open
Go4miii opened this issue Dec 30, 2024 · 1 comment
Open

如何通过代码获得检索的top3文档? #5167

Go4miii opened this issue Dec 30, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@Go4miii
Copy link

Go4miii commented Dec 30, 2024

chatchat已经部署好了,请问如何实现我调知识库,通过几行代码传入“问题”,chatchat直接返回检索的top3文档?

请问如何实现这一过程,现在只有web界面,我想把chatchat返回的内容作为我另一个需求的输入。@dosu-bot

@Go4miii Go4miii added the bug Something isn't working label Dec 30, 2024
Copy link

dosubot bot commented Dec 30, 2024

要通过代码从 chatchat 检索并返回 top3 文档,可以使用 kb_chat 函数,并设置 top_k 参数为 3。以下是一个示例代码片段,展示如何实现这一过程:

from fastapi import Body

# 假设你已经设置了其他必要的参数
query = "你的查询内容"
kb_name = "你的知识库名称"

# 调用 kb_chat 函数,设置 top_k 为 3
response = await kb_chat(
    query=Body(query),
    mode=Body("local_kb"),
    kb_name=Body(kb_name),
    top_k=Body(3),  # 设置为3以返回top3文档
    score_threshold=Body(0.5),  # 可根据需要调整
    return_direct=Body(True)  # 直接返回检索结果
)

# 处理返回的文档
for doc in response:
    print(doc)

在这个代码片段中,top_k 参数被设置为 3,以确保返回的文档数量为 top3。return_direct 参数被设置为 True,以便直接返回检索结果而不经过 LLM 处理[1].

To continue talking to Dosu, mention @dosu.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Other

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant