Wang Baoling
commited on
Commit
·
58e43fa
1
Parent(s):
9279c42
fix: using embd which user configured at knowledgebase (#1163)
Browse files### What problem does this PR solve?
as title
### Type of change
- [x] Bug Fix (non-breaking change which fixes an issue)
- api/apps/chunk_app.py +4 -1
- api/db/services/document_service.py +13 -0
api/apps/chunk_app.py
CHANGED
|
@@ -136,8 +136,11 @@ def set():
|
|
| 136 |
tenant_id = DocumentService.get_tenant_id(req["doc_id"])
|
| 137 |
if not tenant_id:
|
| 138 |
return get_data_error_result(retmsg="Tenant not found!")
|
|
|
|
|
|
|
| 139 |
embd_mdl = TenantLLMService.model_instance(
|
| 140 |
-
tenant_id, LLMType.EMBEDDING.value)
|
|
|
|
| 141 |
e, doc = DocumentService.get_by_id(req["doc_id"])
|
| 142 |
if not e:
|
| 143 |
return get_data_error_result(retmsg="Document not found!")
|
|
|
|
| 136 |
tenant_id = DocumentService.get_tenant_id(req["doc_id"])
|
| 137 |
if not tenant_id:
|
| 138 |
return get_data_error_result(retmsg="Tenant not found!")
|
| 139 |
+
|
| 140 |
+
embd_id = DocumentService.get_embd_id(req["doc_id"])
|
| 141 |
embd_mdl = TenantLLMService.model_instance(
|
| 142 |
+
tenant_id, LLMType.EMBEDDING.value, embd_id)
|
| 143 |
+
|
| 144 |
e, doc = DocumentService.get_by_id(req["doc_id"])
|
| 145 |
if not e:
|
| 146 |
return get_data_error_result(retmsg="Document not found!")
|
api/db/services/document_service.py
CHANGED
|
@@ -182,6 +182,19 @@ class DocumentService(CommonService):
|
|
| 182 |
return
|
| 183 |
return docs[0]["tenant_id"]
|
| 184 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 185 |
@classmethod
|
| 186 |
@DB.connection_context()
|
| 187 |
def get_doc_id_by_doc_name(cls, doc_name):
|
|
|
|
| 182 |
return
|
| 183 |
return docs[0]["tenant_id"]
|
| 184 |
|
| 185 |
+
@classmethod
|
| 186 |
+
@DB.connection_context()
|
| 187 |
+
def get_embd_id(cls, doc_id):
|
| 188 |
+
docs = cls.model.select(
|
| 189 |
+
Knowledgebase.embd_id).join(
|
| 190 |
+
Knowledgebase, on=(
|
| 191 |
+
Knowledgebase.id == cls.model.kb_id)).where(
|
| 192 |
+
cls.model.id == doc_id, Knowledgebase.status == StatusEnum.VALID.value)
|
| 193 |
+
docs = docs.dicts()
|
| 194 |
+
if not docs:
|
| 195 |
+
return
|
| 196 |
+
return docs[0]["embd_id"]
|
| 197 |
+
|
| 198 |
@classmethod
|
| 199 |
@DB.connection_context()
|
| 200 |
def get_doc_id_by_doc_name(cls, doc_name):
|