Fix index not found for new user. (#4597)

### What problem does this PR solve?

### Type of change

- [x] Bug Fix (non-breaking change which fixes an issue)
This commit is contained in:
Kevin Hu 2025-01-23 11:45:22 +08:00 committed by GitHub
parent 15f9406e7b
commit c4b9e903c8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -14,6 +14,7 @@
# limitations under the License.
#
import json
import logging
from flask import request
from flask_login import login_required, current_user
@ -286,13 +287,18 @@ def knowledge_graph(kb_id):
message='No authorization.',
code=settings.RetCode.AUTHENTICATION_ERROR
)
e, kb = KnowledgebaseService.get_by_id(kb_id)
_, kb = KnowledgebaseService.get_by_id(kb_id)
req = {
"kb_id": [kb_id],
"knowledge_graph_kwd": ["graph"]
}
sres = settings.retrievaler.search(req, search.index_name(kb.tenant_id), [kb_id])
obj = {"graph": {}, "mind_map": {}}
try:
sres = settings.retrievaler.search(req, search.index_name(kb.tenant_id), [kb_id])
except Exception as e:
logging.exception(e)
return get_json_result(data=obj)
for id in sres.ids[:1]:
ty = sres.field[id]["knowledge_graph_kwd"]
try: