Skip to content

Commit 1846793

Browse files
committed
style: polish code
1 parent c26ed3e commit 1846793

File tree

2 files changed

+14
-18
lines changed

2 files changed

+14
-18
lines changed

api/configs/feature/__init__.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -619,13 +619,10 @@ class DataSetConfig(BaseSettings):
619619
PLAN_SANDBOX_CLEAN_MESSAGE_DAY_SETTING: PositiveInt = Field(
620620
description="Interval in days for message cleanup operations - plan: sandbox",
621621
default=30,
622-
)
623-
624-
RETRIEVAL_TOP_N: Optional[PositiveInt] = Field(
625-
description="number of retrieval top_n",
626-
default=None
627622
)
628623

624+
RETRIEVAL_TOP_N: Optional[PositiveInt] = Field(description="number of retrieval top_n", default=None)
625+
629626

630627
class WorkspaceConfig(BaseSettings):
631628
"""

api/core/rag/datasource/retrieval_service.py

+12-13
Original file line numberDiff line numberDiff line change
@@ -106,16 +106,15 @@ def retrieve(
106106
exception_message = ";\n".join(exceptions)
107107
raise Exception(exception_message)
108108

109-
110109
if retrieval_method == RetrievalMethod.HYBRID_SEARCH.value:
111110
data_post_processor = DataPostProcessor(
112111
str(dataset.tenant_id), reranking_mode, reranking_model, weights, False
113112
)
114113
all_documents = data_post_processor.invoke(
115-
query=query,
116-
documents=all_documents,
117-
score_threshold=score_threshold,
118-
top_n=DifyConfig.RETRIEVAL_TOP_N if DifyConfig.RETRIEVAL_TOP_N else top_k
114+
query=query,
115+
documents=all_documents,
116+
score_threshold=score_threshold,
117+
top_n=DifyConfig.RETRIEVAL_TOP_N or top_k,
119118
)
120119

121120
return all_documents
@@ -184,10 +183,10 @@ def embedding_search(
184183
)
185184
all_documents.extend(
186185
data_post_processor.invoke(
187-
query=query,
188-
documents=documents,
189-
score_threshold=score_threshold,
190-
top_n=DifyConfig.RETRIEVAL_TOP_N if DifyConfig.RETRIEVAL_TOP_N else len(documents)
186+
query=query,
187+
documents=documents,
188+
score_threshold=score_threshold,
189+
top_n=DifyConfig.RETRIEVAL_TOP_N or len(documents),
191190
)
192191
)
193192
else:
@@ -229,10 +228,10 @@ def full_text_index_search(
229228
)
230229
all_documents.extend(
231230
data_post_processor.invoke(
232-
query=query,
233-
documents=documents,
234-
score_threshold=score_threshold,
235-
top_n=DifyConfig.RETRIEVAL_TOP_N if DifyConfig.RETRIEVAL_TOP_N else len(documents)
231+
query=query,
232+
documents=documents,
233+
score_threshold=score_threshold,
234+
top_n=DifyConfig.RETRIEVAL_TOP_N or len(documents),
236235
)
237236
)
238237
else:

0 commit comments

Comments
 (0)