mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-07-06 03:18:36 +08:00
feat(raptor): add Psi tree builder with original-space ranking and safe migration (#14679)
### What problem does this PR solve? Closes #14674. This PR improves RAPTOR configuration and tree construction while preserving the existing RAPTOR behavior as the default. RAPTOR currently builds summary layers with the original UMAP + GMM clustering path. This PR keeps that default path, and adds: - A hidden backend tree-builder option: - `tree_builder="raptor"`: default, existing RAPTOR behavior. - `tree_builder="psi"`: rank-aware Psi-style tree builder using original embedding-space cosine ranking. - A user-facing clustering method option for the default RAPTOR builder: - `clustering_method="gmm"`: existing default. - `clustering_method="ahc"`: agglomerative hierarchical clustering path. - A RAPTOR UI setting for `Clustering method` and `Max cluster`. ### What changed #### Backend - Added `tree_builder` support for RAPTOR/Psi. - Added `clustering_method` support for GMM/AHC. - Kept existing RAPTOR + GMM as the default. - Added Psi tree building from original-space cosine similarity. - Added bucketed Psi building controls for large inputs: - `raptor.ext.psi_exact_max_leaves` - `raptor.ext.psi_bucket_size` - Added method-aware RAPTOR summary metadata using existing `extra.raptor_method`. - Avoided adding a dedicated DB schema field for experimental method tracking. - Added cleanup/migration logic to avoid mixing stale RAPTOR summary trees. - Added defensive checks for Psi tree construction and summary failures. #### Frontend/UI - Added `Clustering method` in RAPTOR settings with `GMM` and `AHC`. - Added/kept `Max cluster` in RAPTOR settings. - Enlarged max cluster UI limit to `1024`, matching backend validation. - Kept AHC editable even when a RAPTOR task has already finished. - Fixed the UI save payload so `clustering_method` and `tree_builder` are serialized through `parser_config.raptor.ext`, avoiding backend validation errors for extra top-level RAPTOR fields. Example saved RAPTOR config: ```json { "raptor": { "max_cluster": 317, "ext": { "clustering_method": "ahc", "tree_builder": "raptor" } } } Co-authored-by: CaptainTimon <CaptainTimon@users.noreply.github.com>
This commit is contained in:
@@ -583,6 +583,10 @@ class TestDatasetUpdate:
|
||||
{"raptor": {"max_cluster": 512}},
|
||||
{"raptor": {"max_cluster": 1024}},
|
||||
{"raptor": {"random_seed": 0}},
|
||||
{"raptor": {"clustering_method": "gmm"}},
|
||||
{"raptor": {"clustering_method": "ahc"}},
|
||||
{"raptor": {"tree_builder": "raptor"}},
|
||||
{"raptor": {"tree_builder": "psi"}},
|
||||
],
|
||||
ids=[
|
||||
"auto_keywords_min",
|
||||
@@ -633,6 +637,10 @@ class TestDatasetUpdate:
|
||||
"raptor_max_cluster_mid",
|
||||
"raptor_max_cluster_max",
|
||||
"raptor_random_seed_min",
|
||||
"raptor_clustering_method_gmm",
|
||||
"raptor_clustering_method_ahc",
|
||||
"raptor_tree_builder_raptor",
|
||||
"raptor_tree_builder_psi",
|
||||
],
|
||||
)
|
||||
def test_parser_config(self, HttpApiAuth, add_dataset_func, parser_config):
|
||||
@@ -707,6 +715,10 @@ class TestDatasetUpdate:
|
||||
({"raptor": {"random_seed": -1}}, "Input should be greater than or equal to 0"),
|
||||
({"raptor": {"random_seed": 3.14}}, "Input should be a valid integer"),
|
||||
({"raptor": {"random_seed": "string"}}, "Input should be a valid integer"),
|
||||
({"raptor": {"clustering_method": "unknown"}}, "Input should be 'gmm' or 'ahc'"),
|
||||
({"raptor": {"clustering_method": None}}, "Input should be 'gmm' or 'ahc'"),
|
||||
({"raptor": {"tree_builder": "ahc"}}, "Input should be 'raptor' or 'psi'"),
|
||||
({"raptor": {"tree_builder": None}}, "Input should be 'raptor' or 'psi'"),
|
||||
({"delimiter": "a" * 65536}, "Parser config exceeds size limit (max 65,535 characters)"),
|
||||
],
|
||||
ids=[
|
||||
@@ -763,6 +775,10 @@ class TestDatasetUpdate:
|
||||
"raptor_random_seed_min_limit",
|
||||
"raptor_random_seed_float_not_allowed",
|
||||
"raptor_random_seed_type_invalid",
|
||||
"raptor_clustering_method_invalid",
|
||||
"raptor_clustering_method_none_invalid",
|
||||
"raptor_tree_builder_invalid",
|
||||
"raptor_tree_builder_none_invalid",
|
||||
"parser_config_type_invalid",
|
||||
],
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user