From c58d2fce89c0f8d198b4d8fe8b558bd1b93874af Mon Sep 17 00:00:00 2001 From: Jyong <76649700+JohnJyong@users.noreply.github.com> Date: Tue, 3 Dec 2024 17:34:56 +0800 Subject: [PATCH] roll back rerank topn setting (#11297) --- api/.env.example | 1 - api/configs/feature/__init__.py | 2 -- api/core/rag/datasource/retrieval_service.py | 7 +++---- 3 files changed, 3 insertions(+), 7 deletions(-) diff --git a/api/.env.example b/api/.env.example index 00b6c28a919abe..52cdd9ecb28dc3 100644 --- a/api/.env.example +++ b/api/.env.example @@ -413,4 +413,3 @@ RESET_PASSWORD_TOKEN_EXPIRY_MINUTES=5 CREATE_TIDB_SERVICE_JOB_ENABLED=false -RETRIEVAL_TOP_N=0 diff --git a/api/configs/feature/__init__.py b/api/configs/feature/__init__.py index e88eb980577121..f1cb3efda7b3e3 100644 --- a/api/configs/feature/__init__.py +++ b/api/configs/feature/__init__.py @@ -626,8 +626,6 @@ class DataSetConfig(BaseSettings): default=30, ) - RETRIEVAL_TOP_N: int = Field(description="number of retrieval top_n", default=0) - class WorkspaceConfig(BaseSettings): """ diff --git a/api/core/rag/datasource/retrieval_service.py b/api/core/rag/datasource/retrieval_service.py index 759166da4c4be8..b2141396d6dcc4 100644 --- a/api/core/rag/datasource/retrieval_service.py +++ b/api/core/rag/datasource/retrieval_service.py @@ -3,7 +3,6 @@ from flask import Flask, current_app -from configs import DifyConfig from core.rag.data_post_processor.data_post_processor import DataPostProcessor from core.rag.datasource.keyword.keyword_factory import Keyword from core.rag.datasource.vdb.vector_factory import Vector @@ -114,7 +113,7 @@ def retrieve( query=query, documents=all_documents, score_threshold=score_threshold, - top_n=DifyConfig.RETRIEVAL_TOP_N or top_k, + top_n=top_k, ) return all_documents @@ -186,7 +185,7 @@ def embedding_search( query=query, documents=documents, score_threshold=score_threshold, - top_n=DifyConfig.RETRIEVAL_TOP_N or len(documents), + top_n=len(documents), ) ) else: @@ -231,7 +230,7 @@ def full_text_index_search( query=query, documents=documents, score_threshold=score_threshold, - top_n=DifyConfig.RETRIEVAL_TOP_N or len(documents), + top_n=len(documents), ) ) else: