Skip to content

Commit 3b1e77a

Browse files
authored
Fix: shared KB embedding authorization for team members (#13809)
### What problem does this PR solve? fixes issue #13799 where team members get model not authorized when running RAG on an admin-shared knowledge base after the admin changes the KB embedding model (for example to bge-m3). ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue)
1 parent 8d4a3d0 commit 3b1e77a

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

api/db/services/dialog_service.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -257,8 +257,9 @@ def get_models(dialog):
257257
raise Exception("**ERROR**: Knowledge bases use different embedding models.")
258258

259259
if embedding_list:
260-
embd_model_config = get_model_config_by_type_and_name(dialog.tenant_id, LLMType.EMBEDDING, embedding_list[0])
261-
embd_mdl = LLMBundle(dialog.tenant_id, embd_model_config)
260+
embd_owner_tenant_id = kbs[0].tenant_id
261+
embd_model_config = get_model_config_by_type_and_name(embd_owner_tenant_id, LLMType.EMBEDDING, embedding_list[0])
262+
embd_mdl = LLMBundle(embd_owner_tenant_id, embd_model_config)
262263
if not embd_mdl:
263264
raise LookupError("Embedding model(%s) not found" % embedding_list[0])
264265

@@ -1367,8 +1368,9 @@ async def async_ask(question, kb_ids, tenant_id, chat_llm_name=None, search_conf
13671368

13681369
is_knowledge_graph = all([kb.parser_id == ParserType.KG for kb in kbs])
13691370
retriever = settings.retriever if not is_knowledge_graph else settings.kg_retriever
1370-
embd_model_config = get_model_config_by_type_and_name(tenant_id, LLMType.EMBEDDING, embedding_list[0])
1371-
embd_mdl = LLMBundle(tenant_id, embd_model_config)
1371+
embd_owner_tenant_id = kbs[0].tenant_id
1372+
embd_model_config = get_model_config_by_type_and_name(embd_owner_tenant_id, LLMType.EMBEDDING, embedding_list[0])
1373+
embd_mdl = LLMBundle(embd_owner_tenant_id, embd_model_config)
13721374
chat_model_config = get_model_config_by_type_and_name(tenant_id, LLMType.CHAT, chat_llm_name)
13731375
chat_mdl = LLMBundle(tenant_id, chat_model_config)
13741376
if rerank_id:
@@ -1449,9 +1451,11 @@ async def gen_mindmap(question, kb_ids, tenant_id, search_config={}):
14491451
tenant_ids = list(set([kb.tenant_id for kb in kbs]))
14501452
if tenant_embedding_list[0]:
14511453
embd_model_config = get_model_config_by_id(tenant_embedding_list[0])
1454+
embd_owner_tenant_id = kbs[0].tenant_id
14521455
else:
1453-
embd_model_config = get_model_config_by_type_and_name(tenant_id, LLMType.EMBEDDING, kbs[0].embd_id)
1454-
embd_mdl = LLMBundle(tenant_id, embd_model_config)
1456+
embd_owner_tenant_id = kbs[0].tenant_id
1457+
embd_model_config = get_model_config_by_type_and_name(embd_owner_tenant_id, LLMType.EMBEDDING, kbs[0].embd_id)
1458+
embd_mdl = LLMBundle(embd_owner_tenant_id, embd_model_config)
14551459
chat_id = search_config.get("chat_id", "")
14561460
if chat_id:
14571461
chat_model_config = get_model_config_by_type_and_name(tenant_id, LLMType.CHAT, chat_id)

0 commit comments

Comments
 (0)