fix: normalize legacy parser configuration (#17761)

This commit is contained in:
buua436
2026-08-04 13:49:44 +08:00
committed by GitHub
parent 539eb470e3
commit 3e11914144
9 changed files with 102 additions and 23 deletions

View File

@@ -371,6 +371,35 @@ class RaptorConfig(Base):
scope: Annotated[Literal["file", "dataset"], Field(default="file")]
auto_disable_for_structured_data: Annotated[bool, Field(default=True)]
@model_validator(mode="before")
@classmethod
def normalize_legacy_fields(cls, value: Any) -> Any:
"""Accept old RAPTOR fields but do not retain them in the config."""
if not isinstance(value, dict):
return value
normalized = dict(value)
changed_fields = []
legacy_ext = normalized.pop("ext", None)
if legacy_ext is not None:
changed_fields.append("ext")
if isinstance(legacy_ext, dict) and normalized.get("clustering_threshold") is None:
if "clustering_threshold" in legacy_ext:
normalized["clustering_threshold"] = legacy_ext["clustering_threshold"]
changed_fields.append("ext.clustering_threshold")
for field in ("threshold", "clustering_method", "tree_builder"):
if field in normalized:
normalized.pop(field)
changed_fields.append(field)
max_token = normalized.get("max_token")
if isinstance(max_token, (int, float)) and not isinstance(max_token, bool) and max_token < 512:
normalized["max_token"] = 512
changed_fields.append("max_token")
if changed_fields:
logging.debug("RaptorConfig normalized legacy fields: %s", sorted(changed_fields))
return normalized
class GraphragConfig(Base):
"""Dataset parser configuration for GraphRAG generation."""