Skip to content

Commit 219ea75

Browse files
authored
feat: Knowledge base search based on authorized users (#3438)
1 parent 71a5de4 commit 219ea75

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

apps/application/chat_pipeline/step/search_dataset_step/impl/base_search_dataset_step.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
from application.chat_pipeline.I_base_chat_pipeline import ParagraphPipelineModel
1717
from application.chat_pipeline.step.search_dataset_step.i_search_dataset_step import ISearchDatasetStep
1818
from common.config.embedding_config import VectorStore, ModelManage
19+
from common.constants.permission_constants import RoleConstants
20+
from common.database_model_manage.database_model_manage import DatabaseModelManage
1921
from common.db.search import native_search
2022
from common.utils.common import get_file_content
2123
from knowledge.models import Paragraph, Knowledge
@@ -52,6 +54,11 @@ def execute(self, problem_text: str, knowledge_id_list: list[str], exclude_docum
5254
search_mode: str = None,
5355
workspace_id=None,
5456
**kwargs) -> List[ParagraphPipelineModel]:
57+
get_knowledge_list_of_authorized = DatabaseModelManage.get_model('get_knowledge_list_of_authorized')
58+
chat_user_type = self.context.get('chat_user_type')
59+
if get_knowledge_list_of_authorized is not None and RoleConstants.CHAT_USER.value.name == chat_user_type:
60+
knowledge_id_list = get_knowledge_list_of_authorized(self.context.get('chat_user_id'),
61+
knowledge_id_list)
5562
if len(knowledge_id_list) == 0:
5663
return []
5764
exec_problem_text = padding_problem_text if padding_problem_text is not None else problem_text

apps/application/flow/step_node/search_knowledge_node/impl/base_search_knowledge_node.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
from application.flow.i_step_node import NodeResult
1616
from application.flow.step_node.search_knowledge_node.i_search_knowledge_node import ISearchKnowledgeStepNode
1717
from common.config.embedding_config import VectorStore
18+
from common.constants.permission_constants import RoleConstants
19+
from common.database_model_manage.database_model_manage import DatabaseModelManage
1820
from common.db.search import native_search
1921
from common.utils.common import get_file_content
2022
from knowledge.models import Document, Paragraph, Knowledge, SearchMode
@@ -64,6 +66,11 @@ def execute(self, knowledge_id_list, knowledge_setting, question,
6466
exclude_paragraph_id_list=None,
6567
**kwargs) -> NodeResult:
6668
self.context['question'] = question
69+
get_knowledge_list_of_authorized = DatabaseModelManage.get_model('get_knowledge_list_of_authorized')
70+
chat_user_type = self.workflow_manage.get_body().get('chat_user_type')
71+
if get_knowledge_list_of_authorized is not None and RoleConstants.CHAT_USER.value.name == chat_user_type:
72+
knowledge_id_list = get_knowledge_list_of_authorized(self.workflow_manage.get_body().get('chat_user_id'),
73+
knowledge_id_list)
6774
if len(knowledge_id_list) == 0:
6875
return get_none_result(question)
6976
model_id = get_embedding_id(knowledge_id_list)

0 commit comments

Comments
 (0)