Handle searching dataset without embedding model (#16742)

### Summary

Handle searching dataset without embedding model

In this PR, Searching datasets with different embedding models or
searching dataset with/without embedding models are not allowed. We will
improve the behavior later.
This commit is contained in:
qinling0210
2026-07-09 11:38:55 +08:00
committed by GitHub
parent 1430d0e431
commit ae96e636e9
14 changed files with 142 additions and 107 deletions

View File

@@ -29,6 +29,29 @@ from api.constants import DATASET_NAME_LIMIT
from api.utils.api_utils import get_parser_config, get_data_error_result
def _base_model_name(embd_id: str) -> str:
"""Return the base model name by stripping provider/instance suffix from an embd_id."""
parts = embd_id.rsplit("@", 2)
return parts[0]
def validate_dataset_embedding_models(kbs):
"""Validate that all given datasets use the same embedding model (or all use none).
Returns an error message string on failure, or ``None`` on success.
"""
# Either all datasets have an embedding model, or none do. Mixing is not allowed.
embd_ids = [kb.embd_id for kb in kbs if kb.embd_id]
has_embd = len(embd_ids) > 0
if has_embd and len(embd_ids) != len(kbs):
return "Cannot search across datasets where some have embedding models and others do not."
if has_embd:
embd_nms = list({_base_model_name(eid) for eid in embd_ids})
if len(embd_nms) > 1:
return f"Datasets use different embedding models: {[kb.embd_id for kb in kbs]}"
return None
class KnowledgebaseService(CommonService):
"""Service class for managing dataset operations.