From 243ed4bc351cfa56666aa4f47e0bd22a19394843 Mon Sep 17 00:00:00 2001 From: sinopec Date: Wed, 28 May 2025 19:16:16 +0800 Subject: [PATCH] =?UTF-8?q?Feat:=20Surpport=20dynamically=20add=20knowledg?= =?UTF-8?q?e=20basees=20for=20retrieval=20while=20u=E2=80=A6=20(#7915)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit …sing the SDK chat API ### What problem does this PR solve? When using the SDK for chat, you can include the IDs of additional knowledge bases you want to use in the request. This way, you don’t need to repeatedly create new assistants to support various combinations of knowledge bases. This is especially useful when there are many knowledge bases with different content. If users clearly know which knowledge base contains the information they need and select accordingly, the recall accuracy will be greatly improved. Users only need to add an extra field, a kb_ids array, in the HTTP request. The content of this field can be determined by the client fetching the list of knowledge bases and letting the user select from it. ### Type of change - [x] New Feature (non-breaking change which adds functionality) Co-authored-by: Li Ye --- api/db/services/conversation_service.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/api/db/services/conversation_service.py b/api/db/services/conversation_service.py index 575eea695..c37812937 100644 --- a/api/db/services/conversation_service.py +++ b/api/db/services/conversation_service.py @@ -123,6 +123,8 @@ def completion(tenant_id, chat_id, question, name="New session", session_id=None message_id = msg[-1].get("id") e, dia = DialogService.get_by_id(conv.dialog_id) + kb_ids = kwargs.get("kb_ids",[]) + dia.kb_ids = list(set(dia.kb_ids + kb_ids)) if not conv.reference: conv.reference = [] conv.message.append({"role": "assistant", "content": "", "id": message_id})