RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.
Go agent-harnessagent-native-databaseagentic-aiagentic-retrievalagentic-searchaiai-agentscontext-enginecontext-engineeringcontext-managementharness-engineeringknowledge-compilationragretrieval-augmented-generationretrieval-harnesssearch-harness
fix: improve knowledge compiler LLM handling (#19701)
buua436130902a39768
diff --git a/internal/ingestion/component/knowledge_compiler/pool_wiring.go b/internal/ingestion/component/knowledge_compiler/pool_wiring.goindex 3d4a92b7f8..13edf9cf90 100644--- a/internal/ingestion/component/knowledge_compiler/pool_wiring.go+++ b/internal/ingestion/component/knowledge_compiler/pool_wiring.go@@ -20,6 +20,7 @@ import ("ragflow/internal/ingestion/component/knowledge_compiler/mindmap""ragflow/internal/ingestion/component/knowledge_compiler/structure"+ "ragflow/internal/ingestion/component/knowledge_compiler/tree""ragflow/internal/ingestion/component/knowledge_compiler/wiki""ragflow/internal/ingestion/knowledge_compile")@@ -36,5 +37,6 @@ func init() {}structure.SetBatchSubmitter(submit)mindmap.SetBatchSubmitter(submit)+ tree.SetBatchSubmitter(submit)wiki.SetBatchSubmitter(submit)}diff --git a/internal/ingestion/component/knowledge_compiler/tree/claims.go b/internal/ingestion/component/knowledge_compiler/tree/claims.goindex 91082adee3..15bdb3d05c 100644--- a/internal/ingestion/component/knowledge_compiler/tree/claims.go+++ b/internal/ingestion/component/knowledge_compiler/tree/claims.go@@ -5,43 +5,20 @@ import ("encoding/json""fmt""log"- "os""sort"- "strconv""strings""sync"- "time""unicode/utf8""ragflow/internal/agent/runtime""ragflow/internal/ingestion/component/knowledge_compiler/common")-// claimExtractionWorkers bounds how many claim-extraction LLM calls run at once.-// Batches are independent, so a large document would otherwise open one-// round-trip per batch and trip the provider's rate limit; this keeps the-// fan-out predictable. Mirrors Python _claim_limiter (raptor.py): the default is-// 4 and MAX_CONCURRENT_CLAIM_CHATS overrides it.-func claimExtractionWorkers() int {- if n, err := strconv.Atoi(os.Getenv("MAX_CONCURRENT_CLAIM_CHATS")); err == nil && n > 0 {- return n- }- return 4-}-// claimBatchSize is how many chunks one extraction call covers, mirroring Python// _CLAIM_BATCH_SIZE (raptor.py). Every chunk in the batch is a TARGET and the// model attributes each claim by chunk id.const claimBatchSize = 4-// Retry budget for a transient LLM failure (rate limit, 5xx, timeout), mirroring-// Python raptor._extract_claim_for_chunk: 3 attempts, 2s then 4s of back-off.-const claimMaxAttempts = 3--// claimRetryBaseDelay is a var (not a const) purely so tests can shorten the-// wait; production always uses the 2s base.-var claimRetryBaseDelay = 2 * time.Second-// EvidenceGateMode decides what happens to a claim whose evidence all failed to// locate. Mirrors Python _EVIDENCE_GATE_MODES.type EvidenceGateMode string@@ -174,11 +151,10 @@ type EvidenceRef struct {// through source_chunk_ids; the validation gate then checks each quote against// that chunk's text.//-// The calls are independent, so a bounded worker pool runs several at once —-// mirroring the Python side, which fans every batch out under _claim_limiter-// (default 4, MAX_CONCURRENT_CLAIM_CHATS override) instead of extracting-// serially. The worker cap keeps a large document from opening hundreds of-// concurrent round-trips against the provider's rate limit.+// The calls are independent, so the batches are submitted to the shared+// knowledge-compilation pool. This keeps Tree's LLM fan-out bounded together+// with the other compiler variants instead of maintaining a second,+// document-local semaphore.//// claimPrompt is the template-declared extraction contract (Python passes// raptor_config["claim_prompt"] from tree.yaml's raptor section into@@ -210,43 +186,26 @@ func ExtractClaimsForChunks(ctx context.Context, deps common.Deps, llmID string,}batches := packClaimBatches(entries)- claimsByChunk := make(map[string][]Claim)total := len(entries)- workers := claimExtractionWorkers()- if workers > len(batches) {- workers = len(batches)- }// Announce the fan-out shape before the first LLM call: the batches take// model latency, so without this line the log would sit silent on// "building tree" for tens of seconds (mirrors Python's start message).runtime.ReportProgressMessage(ctx, "Compiler", fmt.Sprintf("tree-template: claim extraction start: %d chunk(s) -> %d batch(es)", total, len(batches)))+ results := make([]map[string][]Claim, len(batches))+ jobs := make([]func() error, 0, len(batches))var (- // mu guards claimsByChunk and serialises the progress callback, which- // is supplied by the caller and is not required to be goroutine-safe.+ // mu serialises the progress callback, which is supplied by the caller+ // and is not required to be goroutine-safe.mu sync.Mutex- wg sync.WaitGroupcompleted int)- sem := make(chan struct{}, workers)for i := range batches {- wg.Add(1)- go func(i int) {- defer wg.Done()- // Take a slot before doing any work; if the context is already- // done, drop out instead of queueing a call that would be- // cancelled mid-flight.- select {- case sem <- struct{}{}:- case <-ctx.Done():- return- }- defer func() { <-sem }()-+ i := i+ jobs = append(jobs, func() error {batch := batches[i]-- batchClaims := extractClaimsForBatch(ctx, deps, llmID, prompt, batch, mode)+ results[i] = extractClaimsForBatch(ctx, deps, llmID, prompt, batch, mode)mu.Lock()// Report progress *after* the batch completes, counting the chunks@@ -255,15 +214,20 @@ func ExtractClaimsForChunks(ctx context.Context, deps common.Deps, llmID string,// finish out of order, so the figure jumps by batch size).completed += len(batch)runtime.ReportProgressMessage(ctx, "Compiler", fmt.Sprintf("tree-template: extracting claims for chunk %d/%d", completed, total))- if len(batchClaims) > 0 {- for id, claims := range batchClaims {- claimsByChunk[id] = append(claimsByChunk[id], claims...)- }- }mu.Unlock()- }(i)+ return nil+ })+ }+ if err := runBatches(ctx, jobs); err != nil {+ return nil+ }++ claimsByChunk := make(map[string][]Claim)+ for _, batchClaims := range results {+ for id, claims := range batchClaims {+ claimsByChunk[id] = append(claimsByChunk[id], claims...)+ }}- wg.Wait()if len(claimsByChunk) == 0 {return nil}@@ -285,13 +249,24 @@ func extractClaimsForBatch(ctx context.Context, deps common.Deps, llmID, claimPrtextByID[t.id] = t.text}- raw, err := chatWithClaimRetry(ctx, deps, llmID, claimPrompt, renderClaimSource(batch), batch)+ req := common.ChatRequest{+ LLMID: llmID,+ SystemPrompt: claimPrompt,+ UserPrompt: renderClaimSource(batch),+ JSONMode: true,+ DisableThinking: true,+ }+ raw, err := common.GenJSON(ctx, deps.Chat, req)if err != nil {log.Printf("tree: claim extraction skipped for batch %s: %v", claimBatchLabel(batch), err)return nil}- items := parseClaimItems(raw)+ items, err := parseClaimItemsMap(raw)+ if err != nil {+ log.Printf("tree: claim extraction skipped for batch %s: %v", claimBatchLabel(batch), err)+ return nil+ }if len(items) == 0 {return nil}@@ -384,61 +359,6 @@ func claimBatchLabel(batch []claimEntry) string {return strings.Join(ids, ",")}-// chatWithClaimRetry issues one claim-extraction call, retrying transient-// provider failures (rate limits, 5xx, timeouts) with exponential back-off,-// mirroring Python raptor._extract_claim_for_chunk. A cancelled context is never-// retried.-func chatWithClaimRetry(ctx context.Context, deps common.Deps, llmID, claimPrompt, prompt string, batch []claimEntry) (string, error) {- var lastErr error- for attempt := 1; attempt <= claimMaxAttempts; attempt++ {- if ctx.Err() != nil {- return "", ctx.Err()- }- resp, err := deps.Chat.Chat(ctx, common.ChatRequest{- LLMID: llmID,- SystemPrompt: claimPrompt,- UserPrompt: prompt,- JSONMode: true,- DisableThinking: true,- })- if err == nil {- if resp == nil {- return "", nil- }- return resp.Content, nil- }- lastErr = err- if !isRetryableClaimErr(err) || attempt == claimMaxAttempts {- break- }- delay := claimRetryBaseDelay * time.Duration(1<<(attempt-1))- log.Printf("tree: claim extraction retry %d/%d after %s for batch %s: %v",- attempt, claimMaxAttempts, delay, claimBatchLabel(batch), err)- select {- case <-time.After(delay):- case <-ctx.Done():- return "", ctx.Err()- }- }- return "", lastErr-}--// isRetryableClaimErr mirrors Python _RETRYABLE_LLM_ERR: capacity and transport-// failures that back-off can clear, as opposed to a malformed request that no-// amount of waiting would fix.-func isRetryableClaimErr(err error) bool {- msg := strings.ToLower(err.Error())- for _, s := range []string{- "rate limit", "429", "tpm limit", "too many requests", "requests per minute",- "server", "503", "502", "504", "500", "unavailable", "timeout", "timed out",- } {- if strings.Contains(msg, s) {- return true- }- }- return false-}-// parseClaimItems tolerates the model wrapping JSON in prose or fences.func parseClaimItems(raw string) []Claim {s, err := common.RepairJSONText(raw)@@ -446,20 +366,38 @@ func parseClaimItems(raw string) []Claim {return nil}- var out struct {- Items []Claim `json:"items"`+ var payload map[string]any+ if err := json.Unmarshal([]byte(s), &payload); err != nil {+ return nil}- if err := json.Unmarshal([]byte(s), &out); err != nil {+ items, err := parseClaimItemsMap(payload)+ if err != nil {return nil}- items := make([]Claim, 0, len(out.Items))- for _, it := range out.Items {+ return items+}++func parseClaimItemsMap(raw map[string]any) ([]Claim, error) {+ itemsRaw, ok := raw["items"]+ if !ok {+ return nil, fmt.Errorf(`claim response is missing "items"`)+ }+ b, err := json.Marshal(itemsRaw)+ if err != nil {+ return nil, fmt.Errorf("claim items cannot be encoded: %w", err)+ }+ var items []Claim+ if err := json.Unmarshal(b, &items); err != nil {+ return nil, fmt.Errorf("claim items are invalid: %w", err)+ }+ filtered := make([]Claim, 0, len(items))+ for _, it := range items {if strings.TrimSpace(it.Name) == "" {continue}- items = append(items, it)+ filtered = append(filtered, it)}- return items+ return filtered, nil}// ValidateClaims locates every quote in the chunk it cites and drops the onesdiff --git a/internal/ingestion/component/knowledge_compiler/tree/claims_test.go b/internal/ingestion/component/knowledge_compiler/tree/claims_test.goindex 73502ee204..29adaa2c3d 100644--- a/internal/ingestion/component/knowledge_compiler/tree/claims_test.go+++ b/internal/ingestion/component/knowledge_compiler/tree/claims_test.go@@ -6,7 +6,6 @@ import ("fmt""strings""testing"- "time""ragflow/internal/ingestion/component/knowledge_compiler/common")@@ -55,6 +54,20 @@ func (f *flakyChatForClaims) Chat(ctx context.Context, req common.ChatRequest) (return &common.ChatResponse{Content: f.reply}, nil}+type sequencedChatForClaims struct {+ replies []string+ calls int+}++func (s *sequencedChatForClaims) Chat(_ context.Context, _ common.ChatRequest) (*common.ChatResponse, error) {+ index := s.calls+ s.calls+++ if index >= len(s.replies) {+ index = len(s.replies) - 1+ }+ return &common.ChatResponse{Content: s.replies[index]}, nil+}+func TestLocateEvidenceExactAndReflowed(t *testing.T) {text := "Post-war immigration added 2.1 million residents to the city."if _, _, ok := LocateEvidence(text, text); !ok {@@ -297,6 +310,19 @@ func TestExtractClaimsForChunksAttribution(t *testing.T) {func TestExtractClaimsForChunksBatchesChunksPerCall(t *testing.T) {// Mirrors Python _CLAIM_BATCH_SIZE: one call harvests a whole batch, so the// call count stays flat instead of growing one-per-chunk.+ previous := batchSubmitter+ defer SetBatchSubmitter(previous)+ submitted := 0+ SetBatchSubmitter(func(ctx context.Context, jobs []func() error) error {+ submitted = len(jobs)+ for _, job := range jobs {+ if err := job(); err != nil {+ return err+ }+ }+ return nil+ })+reply, _ := json.Marshal(map[string]any{"items": []any{map[string]any{"name": "a claim",@@ -316,15 +342,14 @@ func TestExtractClaimsForChunksBatchesChunksPerCall(t *testing.T) {if chat.calls != 1 {t.Fatalf("expected 1 call for %d chunks, got %d", len(chunks), chat.calls)}+ if submitted != 1 {+ t.Fatalf("expected one batch submitted to the shared pool, got %d", submitted)+ }}func TestExtractClaimsForChunksRetriesTransientErrors(t *testing.T) {// Mirrors Python _RETRYABLE_LLM_ERR: a rate-limit failure is worth waiting// out instead of silently dropping the batch's claims.- old := claimRetryBaseDelay- claimRetryBaseDelay = time.Millisecond- t.Cleanup(func() { claimRetryBaseDelay = old })-reply, _ := json.Marshal(map[string]any{"items": []any{map[string]any{"name": "a claim",@@ -339,6 +364,25 @@ func TestExtractClaimsForChunksRetriesTransientErrors(t *testing.T) {}}+func TestExtractClaimsForChunksRetriesMalformedJSON(t *testing.T) {+ reply, _ := json.Marshal(map[string]any{"items": []any{+ map[string]any{+ "name": "a claim",+ "source_chunk_ids": []any{"c1"},+ "evidence": []any{map[string]any{"quote": "alpha text", "chunk_id": "c1"}},+ },+ }})+ chat := &sequencedChatForClaims{replies: []string{"not valid JSON", string(reply)}}+ deps := common.Deps{Chat: chat, TenantID: "t"}+ got := ExtractClaimsForChunks(context.Background(), deps, "llm", []common.Chunk{{ID: "c1", Text: "alpha text"}}, EvidenceGateSoft, "")+ if len(got["c1"]) != 1 {+ t.Fatalf("a malformed response should be retried, got %+v", got)+ }+ if chat.calls != 2 {+ t.Fatalf("expected one retry after malformed JSON, got %d calls", chat.calls)+ }+}+func TestValidateClaimsHardModeDropsTheClaim(t *testing.T) {claims := []Claim{{Name: "invented",diff --git a/internal/ingestion/component/knowledge_compiler/tree/duplicate_titles.go b/internal/ingestion/component/knowledge_compiler/tree/duplicate_titles.goindex c89f4cc434..01d7b9d33e 100644--- a/internal/ingestion/component/knowledge_compiler/tree/duplicate_titles.go+++ b/internal/ingestion/component/knowledge_compiler/tree/duplicate_titles.go@@ -142,13 +142,14 @@ func rewriteTitleGroup(ctx context.Context, deps common.Deps, llmID, title strin"Nodes: " + string(itemsJSON)temp := 0.0- resp, err := deps.Chat.Chat(ctx, common.ChatRequest{+ req := common.ChatRequest{LLMID: llmID,SystemPrompt: "You rename duplicate tree node titles for display.",UserPrompt: prompt,JSONMode: true,Temperature: &temp,- })+ }+ resp, err := deps.Chat.Chat(ctx, req)if err != nil {return err}diff --git a/internal/ingestion/component/knowledge_compiler/tree/pool.go b/internal/ingestion/component/knowledge_compiler/tree/pool.gonew file mode 100644index 0000000000..9f86d10cc0--- /dev/null+++ b/internal/ingestion/component/knowledge_compiler/tree/pool.go@@ -0,0 +1,48 @@+//+// Copyright 2026 The InfiniFlow Authors. All Rights Reserved.+//+// Licensed under the Apache License, Version 2.0 (the "License");+// you may not use this file except in compliance with the License.+// You may obtain a copy of the License at+//+// http://www.apache.org/licenses/LICENSE-2.0+//+// Unless required by applicable law or agreed to in writing, software+// distributed under the License is distributed on an "AS IS" BASIS,+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+// See the License for the specific language governing permissions and+// limitations under the License.++package tree++import "context"++// batchSubmitter fans out independent Tree extraction jobs on the process-wide+// knowledge-compilation pool. It is injected by the knowledge_compiler wiring+// so Tree shares the same concurrency bound as the other compiler variants;+// when nil, batches run sequentially for direct package use and tests.+var batchSubmitter func(ctx context.Context, jobs []func() error) error++// SetBatchSubmitter installs the shared-pool fan-out used by Tree extraction.+// Pass nil to revert to serial execution.+func SetBatchSubmitter(submit func(ctx context.Context, jobs []func() error) error) {+ batchSubmitter = submit+}++// runBatches mirrors the other compiler variants: concurrent under the wired+// global compiler pool, or serial when no submitter is set. The first error is+// returned after all jobs settle; the global pool is never StopWait'd.+func runBatches(ctx context.Context, jobs []func() error) error {+ if len(jobs) == 0 {+ return nil+ }+ if batchSubmitter != nil {+ return batchSubmitter(ctx, jobs)+ }+ for _, job := range jobs {+ if err := job(); err != nil {+ return err+ }+ }+ return nil+}diff --git a/internal/ingestion/component/knowledge_compiler/tree/raptor.go b/internal/ingestion/component/knowledge_compiler/tree/raptor.goindex c83b7aad11..f276959a75 100644--- a/internal/ingestion/component/knowledge_compiler/tree/raptor.go+++ b/internal/ingestion/component/knowledge_compiler/tree/raptor.go@@ -134,8 +134,9 @@ var raptorTruncationMarkerRE = regexp.MustCompile(strings.Repeat("\u00b7", 6) + "\n由于长度的原因,回答被截断了,要继续吗?|For the content length reason, it stopped, continue?",)-// resolveMaxToken returns the generation cap (max_tokens) for summaries. Python-// uses max(self._max_token, 512) (raptor.py:403, issue #10235); we honour an+// resolveMaxToken returns the target summary length and the input truncation+// budget. It is a soft output-size guideline, not a provider max_tokens cap.+// Python uses max(self._max_token, 512) (raptor.py:427); we honour an// extra["max_token"] override with the same 512 floor.func resolveMaxToken(param common.Param) int {if v, ok := param.Extra["max_token"]; ok {@@ -453,10 +454,12 @@ func buildTree(ctx context.Context, deps common.Deps, llmID, tenantID, docID str// - trims surrounding whitespace.//// systemText is the fully-built system prompt (helper + filled task template) and-// userText is the user turn; the title instruction is passed as the user turn so-// the model emits a one-line title on the first line of the summary.+// userText is the user turn; the title instruction and soft length guideline are+// passed as the user turn so the model emits a one-line title on the first line+// of the summary. maxToken is deliberately not sent as MaxTokens: the provider+// controls its own output budget, while the prompt guides the target length.func summarizeTexts(ctx context.Context, deps common.Deps, llmID, systemText, userText string, maxToken int) (string, error) {- mt := maxToken+ userPrompt := fmt.Sprintf("%s Keep the summary concise and target approximately %d tokens.", userText, maxToken)for attempt := 0; attempt < raptorMaxRetries; attempt++ {if attempt > 0 {select {@@ -465,13 +468,13 @@ func summarizeTexts(ctx context.Context, deps common.Deps, llmID, systemText, uscase <-time.After(time.Duration(1+attempt) * time.Second):}}- resp, err := deps.Chat.Chat(ctx, common.ChatRequest{+ req := common.ChatRequest{LLMID: llmID,SystemPrompt: systemText,- UserPrompt: userText,- MaxTokens: &mt,+ UserPrompt: userPrompt,DisableThinking: true,- })+ }+ resp, err := deps.Chat.Chat(ctx, req)if err != nil {continue}diff --git a/internal/ingestion/component/knowledge_compiler/tree/raptor_test.go b/internal/ingestion/component/knowledge_compiler/tree/raptor_test.goindex fbc000cc3c..fbe0eea028 100644--- a/internal/ingestion/component/knowledge_compiler/tree/raptor_test.go+++ b/internal/ingestion/component/knowledge_compiler/tree/raptor_test.go@@ -116,13 +116,17 @@ func TestSummarizeTextsFailsAfterMaxRetries(t *testing.T) {}}-func TestSummarizeTextsPassesMaxTokens(t *testing.T) {+func TestSummarizeTextsUsesSoftMaxTokenGuidance(t *testing.T) {f := &fakeChat{responses: []*common.ChatResponse{{Content: "title\nbody"}}}if _, err := summarizeTexts(context.Background(), depsWithChat(f), "llm", "sys", "user", 1024); err != nil {t.Fatalf("unexpected err: %v", err)}- if f.lastReq.MaxTokens == nil || *f.lastReq.MaxTokens != 1024 {- t.Fatalf("MaxTokens not passed through: %v", f.lastReq.MaxTokens)+ if f.lastReq.MaxTokens != nil {+ t.Fatalf("summary should not set a provider max_tokens cap: %v", *f.lastReq.MaxTokens)+ }+ wantPrompt := "user Keep the summary concise and target approximately 1024 tokens."+ if f.lastReq.UserPrompt != wantPrompt {+ t.Fatalf("soft length guidance not added to prompt: got %q, want %q", f.lastReq.UserPrompt, wantPrompt)}}diff --git a/internal/ingestion/knowledge_compile/consumer.go b/internal/ingestion/knowledge_compile/consumer.goindex 01395b6858..b079d70e8f 100644--- a/internal/ingestion/knowledge_compile/consumer.go+++ b/internal/ingestion/knowledge_compile/consumer.go@@ -1283,10 +1283,6 @@ func rewriteMergedWikiPages(ctx context.Context, tenant string, pages []kccommonif deps.Chat == nil {return fmt.Errorf("Wiki page rewrite chat model is unavailable")}- maxTokens := deps.ModelMaxOutput- if maxTokens <= 0 {- maxTokens = 4096- }jobs := make([]CompilerJob, 0, len(indexes))for _, idx := range indexes {idx := idx@@ -1304,7 +1300,6 @@ func rewriteMergedWikiPages(ctx context.Context, tenant string, pages []kccommonSystemPrompt: wikiPageRewriteSystemPrompt,UserPrompt: prompt,Temperature: floatPtr(0.1),- MaxTokens: &maxTokens,})if err != nil {return fmt.Errorf("rewrite Wiki page %q: %w", metaString(page.Meta, "slug"), err)diff --git a/internal/ingestion/task/knowledge_compiler_wiring.go b/internal/ingestion/task/knowledge_compiler_wiring.goindex 1444cce9cd..3fa1af214e 100644--- a/internal/ingestion/task/knowledge_compiler_wiring.go+++ b/internal/ingestion/task/knowledge_compiler_wiring.go@@ -544,7 +544,7 @@ func newKnowledgeCompilerDepsResolver() kc.DepsResolver {}return kc.Deps{- Chat: &kcChatInvoker{svc: svc, tenantID: tenantID, llmID: llmID, maxTokens: llmMaxOutput},+ Chat: &kcChatInvoker{svc: svc, tenantID: tenantID, llmID: llmID},Embed: &kcEmbedder{svc: svc, tenantID: tenantID, embdID: embeddingModel},WikiPages: &kcWikiPageStore{docEngine: engine.Get()},WikiMapVersions: knowledge_compile.NewWikiMapVersionStore(engine.Get()),@@ -560,10 +560,9 @@ func newKnowledgeCompilerDepsResolver() kc.DepsResolver {// kcChatInvoker adapts service.ModelProviderService.Chat to the// knowledge_compiler ChatInvoker seam.type kcChatInvoker struct {- svc *service.ModelProviderService- tenantID string- llmID string- maxTokens int+ svc *service.ModelProviderService+ tenantID string+ llmID string}func (c *kcChatInvoker) Chat(ctx context.Context, req kc.ChatRequest) (*kc.ChatResponse, error) {@@ -578,23 +577,17 @@ func (c *kcChatInvoker) Chat(ctx context.Context, req kc.ChatRequest) (*kc.ChatR// Python's knowledge compilation pins per-call-site temperatures// (extraction 0.1, merge judging 0.0); nil leaves the driver default.var config *models.ChatConfig- // Union of both sides: per-call overrides (temperature / max tokens), this- // branch's thinking toggle (claim extraction and raptor merge ask the- // reasoning model to answer WITHOUT chain-of-thought), and upstream's- // invoker-level generation cap, which the MaxTokens else-if below applies- // when the call site itself sets none.- if req.Temperature != nil || req.MaxTokens != nil || req.DisableThinking || c.maxTokens > 0 {+ // Build a provider config only for per-call overrides. In particular, do not+ // inject the model's configured max_output as max_tokens: knowledge+ // compilation call sites that need an output cap must set MaxTokens+ // explicitly, while the model driver remains responsible for its default.+ if req.Temperature != nil || req.MaxTokens != nil || req.DisableThinking {config = &models.ChatConfig{}if req.Temperature != nil {config.Temperature = req.Temperature}- // Normal knowledge-compilation calls use the generation cap resolved- // from the selected model's max_output configuration. Specialized- // variants may still provide a smaller per-call cap.if req.MaxTokens != nil {config.MaxTokens = req.MaxTokens- } else if c.maxTokens > 0 {- config.MaxTokens = &c.maxTokens}// Reasoning models (MiniMax-M1/M3, kimi, qwen) spend the completion// budget on visible COT before the structured reply; compilation shoulddiff --git a/internal/service/dataset_structure_graph.go b/internal/service/dataset_structure_graph.goindex 1b530ef526..aa58a3639f 100644--- a/internal/service/dataset_structure_graph.go+++ b/internal/service/dataset_structure_graph.go@@ -34,6 +34,7 @@ var graphRelationFields = []string{"id", "content_with_weight", "from_entity_kwdvar graphAllFields = []string{"id", "content_with_weight", "name_kwd", "mention_count_int", "source_chunk_ids","from_entity_kwd", "to_entity_kwd", "knowledge_graph_kwd", "doc_id", "doc_ids_kwd", "source_doc_ids",+ "compile_kwd", "compilation_template_ids", "compilation_template_kind_kwd",}// StructureGraphNode is a projected entity in the structure graph response.@@ -492,7 +493,8 @@ func (s *DatasetArtifactService) buildBucket(ctx context.Context, tenantID, data}}entities = dedupEntities(entities)- return entities, normalizeRelationEndpoints(entities, relations), nil+ relations = normalizeRelationEndpoints(entities, relations)+ return entities, relations, nil}// Large bucket: sample. A = top entities by mention_count_int desc.@@ -811,7 +813,6 @@ func (s *DatasetArtifactService) GetDocumentGraph(ctx context.Context, in Documebreak}}-bucketMetas := map[string]map[string]interface{}{}bucketScopes := map[string]map[string]interface{}{}templateDAO := dao.NewCompilationTemplateDAO()@@ -840,7 +841,6 @@ func (s *DatasetArtifactService) GetDocumentGraph(ctx context.Context, in DocumebucketScopes[bid] = scope}}-grouped := map[string]DocumentStructureGraphTemplate{}for bid, meta := range bucketMetas {entities, relations, err := s.buildBucket(ctx, in.TenantID, in.DatasetID, bucketScopes[bid], nil)