diff --git a/api/apps/sdk/chat.py b/api/apps/sdk/chat.py index 6f3a70ab..cd67b10c 100644 --- a/api/apps/sdk/chat.py +++ b/api/apps/sdk/chat.py @@ -65,7 +65,7 @@ def create(tenant_id): "system": "prompt", "rerank_id": "rerank_model", "vector_similarity_weight": "keywords_similarity_weight"} - key_list = ["similarity_threshold", "vector_similarity_weight", "top_n", "rerank_id"] + key_list = ["similarity_threshold", "vector_similarity_weight", "top_n", "rerank_id","top_k"] if prompt: for new_key, old_key in key_mapping.items(): if old_key in prompt: @@ -200,7 +200,7 @@ def update(tenant_id, chat_id): "system": "prompt", "rerank_id": "rerank_model", "vector_similarity_weight": "keywords_similarity_weight"} - key_list = ["similarity_threshold", "vector_similarity_weight", "top_n", "rerank_id"] + key_list = ["similarity_threshold", "vector_similarity_weight", "top_n", "rerank_id","top_k"] if prompt: for new_key, old_key in key_mapping.items(): if old_key in prompt: diff --git a/docs/references/http_api_reference.md b/docs/references/http_api_reference.md index 09beb726..c806fae7 100644 --- a/docs/references/http_api_reference.md +++ b/docs/references/http_api_reference.md @@ -1389,6 +1389,7 @@ curl --request POST \ - All the variables in 'System' should be curly bracketed. - The default value is `[{"key": "knowledge", "optional": true}]`. - `"rerank_model"`: `string` If it is not specified, vector cosine similarity will be used; otherwise, reranking score will be used. + - `top_k`: `int` Refers to the process of reordering or selecting the top-k items from a list or set based on a specific ranking criterion. Default to 1024. - `"empty_response"`: `string` If nothing is retrieved in the dataset for the user's question, this will be used as the response. To allow the LLM to improvise when nothing is found, leave this blank. - `"opener"`: `string` The opening greeting for the user. Defaults to `"Hi! I am your assistant, can I help you?"`. - `"show_quote`: `boolean` Indicates whether the source of text should be displayed. Defaults to `true`. diff --git a/docs/references/python_api_reference.md b/docs/references/python_api_reference.md index d94ec444..a1154b02 100644 --- a/docs/references/python_api_reference.md +++ b/docs/references/python_api_reference.md @@ -965,6 +965,7 @@ Instructions for the LLM to follow. A `Prompt` object contains the following at - All the variables in 'System' should be curly bracketed. - The default value is `[{"key": "knowledge", "optional": True}]`. - `rerank_model`: `str` If it is not specified, vector cosine similarity will be used; otherwise, reranking score will be used. Defaults to `""`. +- `top_k`: `int` Refers to the process of reordering or selecting the top-k items from a list or set based on a specific ranking criterion. Default to 1024. - `empty_response`: `str` If nothing is retrieved in the dataset for the user's question, this will be used as the response. To allow the LLM to improvise when nothing is found, leave this blank. Defaults to `None`. - `opener`: `str` The opening greeting for the user. Defaults to `"Hi! I am your assistant, can I help you?"`. - `show_quote`: `bool` Indicates whether the source of text should be displayed. Defaults to `True`. diff --git a/sdk/python/ragflow_sdk/modules/chat.py b/sdk/python/ragflow_sdk/modules/chat.py index 7663dfdc..013bddd7 100644 --- a/sdk/python/ragflow_sdk/modules/chat.py +++ b/sdk/python/ragflow_sdk/modules/chat.py @@ -28,6 +28,7 @@ class Chat(Base): self.similarity_threshold = 0.2 self.keywords_similarity_weight = 0.7 self.top_n = 8 + self.top_k = 1024 self.variables = [{"key": "knowledge", "optional": True}] self.rerank_model = None self.empty_response = None diff --git a/sdk/python/ragflow_sdk/ragflow.py b/sdk/python/ragflow_sdk/ragflow.py index 05158f6f..c0da192c 100644 --- a/sdk/python/ragflow_sdk/ragflow.py +++ b/sdk/python/ragflow_sdk/ragflow.py @@ -108,6 +108,7 @@ class RAGFlow: prompt = Chat.Prompt(self, {"similarity_threshold": 0.2, "keywords_similarity_weight": 0.7, "top_n": 8, + "top_k": 1024, "variables": [{ "key": "knowledge", "optional": True