refa: simplify RAPTOR tree clustering and configuration (#17614)

This commit is contained in:
buua436
2026-08-03 17:46:50 +08:00
committed by GitHub
parent e290a0d476
commit 3e7cfbe052
32 changed files with 318 additions and 1356 deletions

View File

@@ -419,12 +419,12 @@ class Compiler(ProcessBase, LLM):
for idx, (template_id, parser_cfg) in enumerate(templates):
raptor_cfg = (parser_cfg or {}).get("raptor") or {}
raptor_config = {
"prompt": raptor_cfg.get("prompt") or "Please write a concise summary of the following texts:\n{cluster_content}",
"prompt": raptor_cfg.get("prompt")
or "Summarize the paragraphs below without inventing facts or changing numbers.\nOutput exactly two parts in the same language as the source:\n1. First line: a concise title only.\n2. Following lines: a concise summary of the content.\nDo not output labels, Markdown headings, bullet points, or any other commentary.\n\nParagraphs:\n{cluster_content}",
"max_token": int(raptor_cfg.get("max_token") or 512),
"threshold": float(raptor_cfg.get("threshold") or 0.1),
"random_seed": int(raptor_cfg.get("random_seed") or 0),
"max_cluster": int(raptor_cfg.get("max_cluster") or 64),
"ext": raptor_cfg.get("ext") or {},
"clustering_threshold": float(0.3 if raptor_cfg.get("clustering_threshold") is None else raptor_cfg["clustering_threshold"]),
"clustering_ratio": float(0.5 if raptor_cfg.get("clustering_ratio") is None else raptor_cfg["clustering_ratio"]),
}
self._compile_progress(msg=f"tree-template ({idx + 1}/{len(templates)}): building tree for doc={doc_id}")
try:
@@ -433,8 +433,6 @@ class Compiler(ProcessBase, LLM):
raptor_config=raptor_config,
chat_mdl=chat_mdl_by_tid[template_id],
embd_mdl=embedding_model,
tree_builder="raptor",
clustering_method="ahc",
max_errors=3,
)
except Exception:
@@ -619,9 +617,9 @@ class Compiler(ProcessBase, LLM):
self.set_output("chunks", chunks)
return
for ck in chunks:
for idx, ck in enumerate(chunks):
ck["doc_id"] = doc_id
ck["id"] = xxhash.xxh64((ck["text"] + str(ck["doc_id"])).encode("utf-8")).hexdigest()
ck["id"] = xxhash.xxh64(f"{ck['text']}\x00{ck['doc_id']}\x00{idx}".encode("utf-8")).hexdigest()
if self._canvas._kb_id:
e, kb = KnowledgebaseService.get_by_id(self._canvas._kb_id)