Fix: Add pagerank validation for non-elasticsearch doc engines (#8215)

### What problem does this PR solve?

Validate that pagerank updates are only allowed when using elasticsearch
as the document engine. Return an error if pagerank is set while using a
different doc engine, preventing potential inconsistencies in document
scoring.

#8208

### Type of change

- [x] Bug Fix (non-breaking change which fixes an issue)
This commit is contained in:
Liu An 2025-06-12 15:47:22 +08:00 committed by GitHub
parent d5236b71f4
commit d0c5ff04a6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -124,6 +124,9 @@ def update():
return get_data_error_result()
if kb.pagerank != req.get("pagerank", 0):
if os.environ.get("DOC_ENGINE", "elasticsearch") != "elasticsearch":
return get_data_error_result(message="'pagerank' can only be set when doc_engine is elasticsearch")
if req.get("pagerank", 0) > 0:
settings.docStoreConn.update({"kb_id": kb.id}, {PAGERANK_FLD: req["pagerank"]},
search.index_name(kb.tenant_id), kb.id)