Skip to content

Feat: add embedding support - #16769

Merged
yingfeng merged 5 commits into
infiniflow:mainfrom
xugangqiang:feat/te-embedding
Jul 9, 2026
Merged

yingfeng merged 5 commits into
infiniflow:mainfrom
xugangqiang:feat/te-embedding

Conversation

@xugangqiang

Copy link
Copy Markdown
Contributor

Summary

Feat: add embedding support

@coderabbitai

coderabbitai Bot commented Jul 9, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

This PR adds context- and instance-scoped component factory overrides, replaces tokenizer embedding injection with resolver-based contracts, rewires dataflow embedding resolution and task-scoped pipeline execution, updates ingestion checkpoint handling, loads task context from ingestion foreign keys, standardizes shared SQLite test setup, and removes legacy chunk helpers.

Changes

Context-Scoped Embedding & Pipeline Refactor

Layer / File(s) Summary
Canvas context-based component factory
internal/agent/canvas/factory_context.go, internal/agent/canvas/node_body.go, internal/agent/canvas/loop_subgraph.go, internal/agent/canvas/scheduler.go, internal/agent/canvas/node_body_per_class_timeout_integration_test.go
Adds context-scoped factory override helpers and threads context through node body construction call sites.
Pipeline instance-scoped component factory
internal/ingestion/pipeline/pipeline.go, internal/ingestion/pipeline/pipeline_test.go
Adds a pipeline-level factory override, compiles with a context carrying that override, and tests override precedence and concurrent isolation.
Tokenizer embedder resolver contract
internal/ingestion/component/tokenizer.go, internal/ingestion/component/tokenizer_test.go, internal/ingestion/component/slice3_test.go
Replaces the global tokenizer embedding seam with resolver-backed embedding contracts, embedding output validation, and resolver-injected tests.
Dataflow embedding resolution and task-scoped factory
internal/ingestion/task/dataflow_service.go, internal/ingestion/task/dataflow_service_test.go, internal/ingestion/task/task_handler.go, internal/ingestion/task/task_handler_test.go
Updates dataflow embedding model resolution, wires task-scoped pipeline factories, removes the old embedChunks path, and propagates task context into pipeline execution.
Deterministic embedder and tokenizer test helpers
internal/ingestion/pipeline/test_helpers.go, internal/ingestion/pipeline/template_integration_test.go, internal/ingestion/pipeline/real_storage_integration_test.go
Adds deterministic embedder wiring for pipeline integration tests, switches tokenizer resource setup to a system dictionary path, and adds shared pipeline test helpers.
Legacy chunk-building and merge code removal
internal/ingestion/task/chunk_builder.go, internal/ingestion/task/chunk_builder_test.go, internal/ingestion/task/chunk_process.go, internal/ingestion/task/chunk_utils.go, internal/ingestion/task/chunk_utils_test.go
Removes unused chunk-building and vector-attachment helpers and trims the corresponding tests.

Ingestion Service Error Handling & Task Context Loading

Layer / File(s) Summary
Ingestion service failure handling
internal/ingestion/service/ingestion_service.go, internal/ingestion/service/execute_task_test.go, internal/ingestion/service/test_helpers.go
Reworks ingestion task log/checkpoint failure handling, removes template post-processing, and replaces removed storage/DAO wiring with a runDocumentTask hook.
TaskContext loading via IngestionTask foreign keys
internal/ingestion/task/task_context.go, internal/ingestion/task/task_context_test.go, internal/ingestion/service/real_consumer_dataflow_test.go, internal/ingestion/task/dataflow_real_pipeline_integration_test.go, internal/ingestion/task/real_consumer_test.go
Adds task-based TaskContext loading, removes the old doc-based helper, and updates task-context construction in tests.
Shared SQLite in-memory test DB helper
internal/dao/task_test.go, internal/ingestion/testutil/helpers.go
Changes test database setup to use a per-test shared in-memory SQLite DSN and limits the SQLite connection pool.

Unrelated Error Message Updates

Layer / File(s) Summary
Error message text updates
internal/service/document.go, internal/service/model_service.go
Changes the DocumentService.Ingest failure message and enriches the tenant default model lookup error.

Estimated code review effort: 4 (Complex) | ~75 minutes

Possibly related issues

Possibly related PRs

  • infiniflow/ragflow#16549: Shares the same TaskContext/Ctx and task execution flow changes now used when passing context into ingestion and pipeline runs.

Suggested labels: 💞 feature, ci, size:XXL

Suggested reviewers: yuzhichang, yingfeng, JinHai-CN

Poem

A rabbit hops through context streams,
And factories now follow themes.
No global embers set astray—
Resolvers light the pipeline way.
Soft failures hop, not crash and fall,
While old chunks vanish, one and all. 🐇

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 21.78% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ❓ Inconclusive The description only repeats the title and does not provide the required summary context or purpose. Expand the Summary with the problem being solved, background context, and the main implementation details.
✅ Passed checks (3 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title is concise and accurately reflects the main change: adding embedding support.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

1. e2e - execute pipeline to parse pdf file and save chunks to ES
2. chunks can be retrieved for using in chat
@xugangqiang xugangqiang added the ci Continue Integration label Jul 9, 2026
@xugangqiang
xugangqiang marked this pull request as ready for review July 9, 2026 05:31
@dosubot dosubot Bot added size:XXL This PR changes 1000+ lines, ignoring generated files. 💞 feature Feature request, pull request that fullfill a new feature. labels Jul 9, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (6)
internal/ingestion/service/ingestion_service.go (1)

227-232: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Extract a markTaskFailed helper to eliminate duplicated error-handling blocks.

The UpdateStatus(FAILED) + log + return pattern is repeated four times in the changed executeTask code (lines 229–232, 245–248, 257–260, 265–268). A small helper would reduce duplication and ensure consistent handling if the failure path ever changes.

As per coding guidelines for internal/ingestion/**, prefer collapsing duplicate paths over preserving transitional wrappers.

♻️ Proposed helper extraction
+func (e *Ingestor) markTaskFailed(taskID string) {
+	if uErr := e.ingestionTaskDAO.UpdateStatus(taskID, common.FAILED); uErr != nil {
+		common.Error(fmt.Sprintf("Failed to set task %s to FAILED", taskID), uErr)
+	}
+}
+
 func (e *Ingestor) executeTask(taskCtx *taskpkg.TaskContext) {
 	ctx := taskCtx.Ctx
 	task := taskCtx.IngestionTask
 	common.Info(fmt.Sprintf("Starting task %s", task.ID))

 	latestLog, err := e.ingestionTaskLogDAO.LatestLogByTaskID(task.ID)
 	if err != nil {
 		if !errors.Is(err, gorm.ErrRecordNotFound) {
 			common.Error(fmt.Sprintf("Failed to get latest task log for task %s", task.ID), err)
-			if uErr := e.ingestionTaskDAO.UpdateStatus(task.ID, common.FAILED); uErr != nil {
-				common.Error(fmt.Sprintf("Failed to set task %s to FAILED", task.ID), uErr)
-			}
+			e.markTaskFailed(task.ID)
 			return
 		}
 		// ...
 		err = e.ingestionTaskLogDAO.Create(latestLog)
 		if err != nil {
 			common.Error(fmt.Sprintf("Failed to create task log for task %s", task.ID), err)
-			if uErr := e.ingestionTaskDAO.UpdateStatus(task.ID, common.FAILED); uErr != nil {
-				common.Error(fmt.Sprintf("Failed to set task %s to FAILED", task.ID), uErr)
-			}
+			e.markTaskFailed(task.ID)
 			return
 		}
 	}
 	// ...
 	currentStep, ok := common.GetInt(checkpointMap["current_step"])
 	if !ok {
 		common.Error(fmt.Sprintf("Failed to get current step from task log for task %s", task.ID), nil)
-		if uErr := e.ingestionTaskDAO.UpdateStatus(task.ID, common.FAILED); uErr != nil {
-			common.Error(fmt.Sprintf("Failed to set task %s to FAILED", task.ID), uErr)
-		}
+		e.markTaskFailed(task.ID)
 		return
 	}
 	totalStep, ok := common.GetInt(checkpointMap["total_step"])
 	if !ok {
 		common.Error(fmt.Sprintf("Failed to get total step from task log for task %s", task.ID), nil)
-		if uErr := e.ingestionTaskDAO.UpdateStatus(task.ID, common.FAILED); uErr != nil {
-			common.Error(fmt.Sprintf("Failed to set task %s to FAILED", task.ID), uErr)
-		}
+		e.markTaskFailed(task.ID)
 		return
 	}

Also applies to: 245-247, 256-267

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/ingestion/service/ingestion_service.go` around lines 227 - 232,
Extract a reusable markTaskFailed helper in executeTask to handle the repeated
failure path: log the original error, call
ingestionTaskDAO.UpdateStatus(task.ID, common.FAILED), log any status-update
error, and return. Replace the duplicated blocks in executeTask with calls to
this helper at each failure site so the behavior stays consistent and the code
is easier to maintain.

Source: Coding guidelines

internal/ingestion/task/real_consumer_test.go (1)

62-71: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Collapse duplicated SQLite DSN construction into a shared helper.

Same DSN pattern as testutil.SetupTestDB — per coding guidelines for internal/ingestion/**, prefer collapsing duplicate paths. Once testutil.SharedMemoryDSN is extracted (see comment on task_context_test.go), replace the inline construction here.

♻️ Proposed refactor
-	dsn := fmt.Sprintf("file:%s?mode=memory&cache=shared", strings.NewReplacer("/", "_", " ", "_").Replace(t.Name()))
+	dsn := testutil.SharedMemoryDSN(t)
 	db, err := gorm.Open(sqlite.Open(dsn), &gorm.Config{TranslateError: true})
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/ingestion/task/real_consumer_test.go` around lines 62 - 71, The
SQLite DSN is being built inline in this test, duplicating the same
shared-memory pattern used elsewhere. Replace the local `dsn` construction in
`real_consumer_test.go` with the shared helper once it exists, ideally
`testutil.SharedMemoryDSN`, so `TestRealConsumer` relies on a single source of
truth for the in-memory SQLite connection string. Keep the rest of the setup
(`gorm.Open`, `db.DB()`, and `SetMaxOpenConns`) unchanged.

Source: Coding guidelines

internal/ingestion/task/task_context_test.go (1)

33-42: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Collapse duplicated SQLite DSN construction into a shared helper.

The DSN pattern fmt.Sprintf("file:%s?mode=memory&cache=shared", strings.NewReplacer("/", "_", " ", "_").Replace(t.Name())) is identical to testutil.SetupTestDB in internal/ingestion/testutil/helpers.go:50. Per the coding guidelines for internal/ingestion/**, prefer collapsing duplicate paths. Consider extracting a small SharedMemoryDSN(t *testing.T) string helper into testutil and calling it here, which avoids the gorm.Config differences (TranslateError vs Logger: Silent) while eliminating the copy.

♻️ Proposed refactor: extract DSN helper into testutil

In internal/ingestion/testutil/helpers.go:

func SharedMemoryDSN(t *testing.T) string {
	t.Helper()
	return fmt.Sprintf("file:%s?mode=memory&cache=shared", strings.NewReplacer("/", "_", " ", "_").Replace(t.Name()))
}

Then in task_context_test.go:

 func setupTestDB(t *testing.T) *gorm.DB {
 	t.Helper()
-	dsn := fmt.Sprintf("file:%s?mode=memory&cache=shared", strings.NewReplacer("/", "_", " ", "_").Replace(t.Name()))
+	dsn := testutil.SharedMemoryDSN(t)
 	db, err := gorm.Open(sqlite.Open(dsn), &gorm.Config{TranslateError: true})
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/ingestion/task/task_context_test.go` around lines 33 - 42, The
SQLite DSN construction in task_context_test.go is duplicated from
testutil.SetupTestDB, so collapse it into a shared helper in testutil instead of
repeating the fmt.Sprintf/strings.NewReplacer logic. Add a small
SharedMemoryDSN(t *testing.T) helper in internal/ingestion/testutil/helpers.go
and use it from the task context test, keeping the existing gorm.Open and
TranslateError settings intact while removing the copy.

Source: Coding guidelines

internal/ingestion/pipeline/real_storage_integration_test.go (2)

196-211: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Duplicate bootstrap logic with dataflow_real_pipeline_integration_test.go.

prepareTokenizerResourceForIntegration here is byte-for-byte identical to prepareTokenizerResourceForTaskIntegration in internal/ingestion/task/dataflow_real_pipeline_integration_test.go (same const path, same skip/setenv/cleanup logic). Consider hoisting this into the shared internal/ingestion/testutil helper package (already used for the SQLite DSN test helper in this cohort) to avoid drift between the two copies.

♻️ Suggested consolidation
// internal/ingestion/testutil/helpers.go
func PrepareTokenizerResource(t *testing.T) {
	t.Helper()
	if os.Getenv("RAGFLOW_DICT_PATH") != "" {
		return
	}
	const systemDictPath = "/usr/share/infinity/resource"
	if _, err := os.Stat(filepath.Join(systemDictPath, "rag", "huqie.txt")); err != nil {
		t.Skipf("system tokenizer resource not found at %s: %v", systemDictPath, err)
	}
	if err := os.Setenv("RAGFLOW_DICT_PATH", systemDictPath); err != nil {
		t.Fatalf("set RAGFLOW_DICT_PATH=%s: %v", systemDictPath, err)
	}
	t.Cleanup(func() { _ = os.Unsetenv("RAGFLOW_DICT_PATH") })
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/ingestion/pipeline/real_storage_integration_test.go` around lines
196 - 211, The tokenizer bootstrap logic in
prepareTokenizerResourceForIntegration is duplicated elsewhere, so consolidate
it into the shared internal/ingestion/testutil helper package used by the SQLite
DSN helper. Move the environment setup, systemDictPath check, and cleanup
behavior into a single helper (for example, a shared PrepareTokenizerResource
function) and update both prepareTokenizerResourceForIntegration and
prepareTokenizerResourceForTaskIntegration to call it instead of keeping
separate copies.

Source: Coding guidelines


196-299: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Remove the unused tokenizer bootstrap helpers

mustWriteTokenizerPOSDef, mustPrepareTokenizerWordNet, and mustPrepareTokenizerOpenCC have no callers anywhere in the repo now; mustSymlink is only used by mustPrepareTokenizerOpenCC, so it goes with them.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/ingestion/pipeline/real_storage_integration_test.go` around lines
196 - 299, Remove the dead tokenizer bootstrap helpers from
real_storage_integration_test.go: mustWriteTokenizerPOSDef,
mustPrepareTokenizerWordNet, mustPrepareTokenizerOpenCC, and the
now-only-related mustSymlink. Since these functions have no callers anywhere in
the repo, delete their definitions and any now-unused imports they were pulling
in. Keep prepareTokenizerResourceForIntegration as the remaining tokenizer setup
helper.

Source: Coding guidelines

internal/ingestion/component/tokenizer.go (1)

17-19: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Keep tokenizer comments focused on the current Go runtime path.

These new doc comments still describe the Python migration/source behavior. Please rewrite them around the current Go component behavior instead.

As per coding guidelines, "internal/**/*.go: Keep Go package comments and doc comments aligned with the current runtime path, not with migration history."

Proposed comment cleanup
-// Tokenizer ingestion component. Port of Python
-// `rag/flow/tokenizer/tokenizer.py`, including the title/content
-// embedding merge and token-accounting behavior of `_embedding`.
+// Package component contains ingestion runtime components, including
+// tokenization and embedding preparation for chunk documents.
 package component
@@
-// tokenizerEmbeddingBatchSize mirrors Python's
-// settings.EMBEDDING_BATCH_SIZE default.
+// tokenizerEmbeddingBatchSize controls the number of content texts sent
+// to the embedder per request.
 var tokenizerEmbeddingBatchSize = 16
@@
-// NewTokenizerComponent constructs a TokenizerComponent from DSL
-// params. Mirrors python `TokenizerParam` defaults (search_method =
-// ["full_text","embedding"], filename_embd_weight=0.1, fields=["text"]).
+// NewTokenizerComponent constructs a TokenizerComponent from DSL params
+// using TokenizerParam defaults.
 func NewTokenizerComponent(params map[string]any) (runtime.Component, error) {

Also applies to: 45-47, 104-106

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/ingestion/component/tokenizer.go` around lines 17 - 19, The doc
comments on the tokenizer package and related symbols still describe Python
migration history instead of the current Go runtime behavior. Rewrite the
comments for the tokenizer component and the affected identifiers in this file
(including the package-level comment and the related methods/types referenced by
the repeated comment blocks) so they explain what the Go implementation does
now, using current behavior and responsibilities rather than mentioning the
Python source or porting history.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@internal/ingestion/component/tokenizer.go`:
- Around line 335-347: The timeout wrapper in encodeWithTimeout does not
actually stop a hung Embedder.Encode call because the timeout context is never
passed into the embedder. Update the Embedder interface or the call path in
encodeWithTimeout so the encoding work accepts and observes context
cancellation, and ensure the blocking Encode(texts) operation in tokenizер.go is
tied to timeoutCtx or otherwise enforced within the timeout boundary.

In `@internal/ingestion/task/dataflow_service.go`:
- Around line 520-524: The resolveEmbeddingModel method currently ignores the
explicit modelID override and always falls back to the KB embedding settings.
Update PipelineExecutor.resolveEmbeddingModel to check modelID first and resolve
that embedding model before considering taskCtx.KB.EmbdID or any kbID-based
fallback, while keeping the existing behavior when modelID is empty. Make sure
the tokenizer flow that calls resolveEmbeddingModel can honor request/DSL-level
overrides without changing the existing KB fallback logic.

---

Nitpick comments:
In `@internal/ingestion/component/tokenizer.go`:
- Around line 17-19: The doc comments on the tokenizer package and related
symbols still describe Python migration history instead of the current Go
runtime behavior. Rewrite the comments for the tokenizer component and the
affected identifiers in this file (including the package-level comment and the
related methods/types referenced by the repeated comment blocks) so they explain
what the Go implementation does now, using current behavior and responsibilities
rather than mentioning the Python source or porting history.

In `@internal/ingestion/pipeline/real_storage_integration_test.go`:
- Around line 196-211: The tokenizer bootstrap logic in
prepareTokenizerResourceForIntegration is duplicated elsewhere, so consolidate
it into the shared internal/ingestion/testutil helper package used by the SQLite
DSN helper. Move the environment setup, systemDictPath check, and cleanup
behavior into a single helper (for example, a shared PrepareTokenizerResource
function) and update both prepareTokenizerResourceForIntegration and
prepareTokenizerResourceForTaskIntegration to call it instead of keeping
separate copies.
- Around line 196-299: Remove the dead tokenizer bootstrap helpers from
real_storage_integration_test.go: mustWriteTokenizerPOSDef,
mustPrepareTokenizerWordNet, mustPrepareTokenizerOpenCC, and the
now-only-related mustSymlink. Since these functions have no callers anywhere in
the repo, delete their definitions and any now-unused imports they were pulling
in. Keep prepareTokenizerResourceForIntegration as the remaining tokenizer setup
helper.

In `@internal/ingestion/service/ingestion_service.go`:
- Around line 227-232: Extract a reusable markTaskFailed helper in executeTask
to handle the repeated failure path: log the original error, call
ingestionTaskDAO.UpdateStatus(task.ID, common.FAILED), log any status-update
error, and return. Replace the duplicated blocks in executeTask with calls to
this helper at each failure site so the behavior stays consistent and the code
is easier to maintain.

In `@internal/ingestion/task/real_consumer_test.go`:
- Around line 62-71: The SQLite DSN is being built inline in this test,
duplicating the same shared-memory pattern used elsewhere. Replace the local
`dsn` construction in `real_consumer_test.go` with the shared helper once it
exists, ideally `testutil.SharedMemoryDSN`, so `TestRealConsumer` relies on a
single source of truth for the in-memory SQLite connection string. Keep the rest
of the setup (`gorm.Open`, `db.DB()`, and `SetMaxOpenConns`) unchanged.

In `@internal/ingestion/task/task_context_test.go`:
- Around line 33-42: The SQLite DSN construction in task_context_test.go is
duplicated from testutil.SetupTestDB, so collapse it into a shared helper in
testutil instead of repeating the fmt.Sprintf/strings.NewReplacer logic. Add a
small SharedMemoryDSN(t *testing.T) helper in
internal/ingestion/testutil/helpers.go and use it from the task context test,
keeping the existing gorm.Open and TranslateError settings intact while removing
the copy.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 911eeb21-2cba-40b7-a3ce-c6d0888d5a54

📥 Commits

Reviewing files that changed from the base of the PR and between b9ed077 and 68ac2cf.

📒 Files selected for processing (36)
  • internal/agent/canvas/factory_context.go
  • internal/agent/canvas/loop_subgraph.go
  • internal/agent/canvas/node_body.go
  • internal/agent/canvas/node_body_per_class_timeout_integration_test.go
  • internal/agent/canvas/scheduler.go
  • internal/dao/task_test.go
  • internal/ingestion/component/tokenizer.go
  • internal/ingestion/component/tokenizer_test.go
  • internal/ingestion/pipeline/pipeline.go
  • internal/ingestion/pipeline/pipeline_test.go
  • internal/ingestion/pipeline/real_storage_integration_test.go
  • internal/ingestion/pipeline/template_integration_test.go
  • internal/ingestion/service/execute_task_test.go
  • internal/ingestion/service/ingestion_service.go
  • internal/ingestion/service/real_consumer_dataflow_test.go
  • internal/ingestion/service/test_helpers.go
  • internal/ingestion/task/chunk_builder.go
  • internal/ingestion/task/chunk_builder_test.go
  • internal/ingestion/task/chunk_process.go
  • internal/ingestion/task/chunk_process_test.go
  • internal/ingestion/task/chunk_utils.go
  • internal/ingestion/task/chunk_utils_test.go
  • internal/ingestion/task/dataflow_real_pipeline_integration_test.go
  • internal/ingestion/task/dataflow_service.go
  • internal/ingestion/task/dataflow_service_test.go
  • internal/ingestion/task/embedding_test.go
  • internal/ingestion/task/naive_merge.go
  • internal/ingestion/task/naive_merge_test.go
  • internal/ingestion/task/real_consumer_test.go
  • internal/ingestion/task/task_context.go
  • internal/ingestion/task/task_context_test.go
  • internal/ingestion/task/task_handler.go
  • internal/ingestion/task/task_handler_test.go
  • internal/ingestion/testutil/helpers.go
  • internal/service/document.go
  • internal/service/model_service.go
💤 Files with no reviewable changes (9)
  • internal/ingestion/task/naive_merge.go
  • internal/ingestion/task/chunk_utils.go
  • internal/ingestion/task/chunk_process_test.go
  • internal/ingestion/task/chunk_builder.go
  • internal/ingestion/task/naive_merge_test.go
  • internal/ingestion/service/test_helpers.go
  • internal/ingestion/task/task_context.go
  • internal/ingestion/task/embedding_test.go
  • internal/ingestion/task/chunk_utils_test.go

Comment on lines +335 to +347
func encodeWithTimeout(ctx context.Context, embedder Embedder, texts []string) ([]EmbeddingResult, error) {
var (
results []EmbeddingResult
encErr error
)
timeoutErr := runtime.WithTimeout(ctx, tokenizerTimeout, func(timeoutCtx context.Context) error {
results, encErr = embedder.Encode(texts)
return encErr
})
if timeoutErr != nil {
return nil, timeoutErr
}
return results, nil

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🩺 Stability & Availability | 🟠 Major | 🏗️ Heavy lift

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Inspect runtime.WithTimeout semantics and tokenizer call sites.
rg -n -C4 'func\s+WithTimeout|WithTimeout\(' internal/agent/runtime internal/ingestion/component/tokenizer.go

Repository: infiniflow/ragflow

Length of output: 6259


🏁 Script executed:

#!/bin/bash
sed -n '90,140p' internal/agent/runtime/helpers.go
printf '\n--- tests ---\n'
sed -n '150,270p' internal/agent/runtime/helpers_test.go

Repository: infiniflow/ragflow

Length of output: 6038


🏁 Script executed:

#!/bin/bash
rg -n -C3 'type\s+Embedder|Encode\(' internal/ingestion/component internal -g '*.go'

Repository: infiniflow/ragflow

Length of output: 50375


Timeout doesn’t bound Embedder.Encode here

runtime.WithTimeout only notices the deadline after fn returns, and Embedder.Encode(texts) has no way to observe timeoutCtx. A hung embedder can therefore keep running past tokenizerTimeout; make the embedder call context-aware or enforce the timeout around the blocking work itself. (internal/ingestion/component/tokenizer.go:340-341)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/ingestion/component/tokenizer.go` around lines 335 - 347, The
timeout wrapper in encodeWithTimeout does not actually stop a hung
Embedder.Encode call because the timeout context is never passed into the
embedder. Update the Embedder interface or the call path in encodeWithTimeout so
the encoding work accepts and observes context cancellation, and ensure the
blocking Encode(texts) operation in tokenizер.go is tied to timeoutCtx or
otherwise enforced within the timeout boundary.

@xugangqiang
xugangqiang marked this pull request as draft July 9, 2026 05:46
@xugangqiang
xugangqiang marked this pull request as ready for review July 9, 2026 05:46

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@internal/ingestion/pipeline/test_helpers.go`:
- Around line 205-207: The helper expectedFixedEmbedderFirst is out of sync with
fixedEmbedder.Encode: it still computes a weighted name/text value instead of
matching the embedder’s first vector element. Update expectedFixedEmbedderFirst
to mirror fixedEmbedder.Encode by deriving the first value from the text length
only, so the integration assertions use the same behavior as the embedder.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 78cfef15-7d6e-4bf8-8389-2d8f2ab2d7f5

📥 Commits

Reviewing files that changed from the base of the PR and between 68ac2cf and de21785.

📒 Files selected for processing (5)
  • internal/ingestion/component/tokenizer.go
  • internal/ingestion/component/tokenizer_test.go
  • internal/ingestion/pipeline/real_storage_integration_test.go
  • internal/ingestion/pipeline/template_integration_test.go
  • internal/ingestion/pipeline/test_helpers.go
🚧 Files skipped from review as they are similar to previous changes (4)
  • internal/ingestion/pipeline/real_storage_integration_test.go
  • internal/ingestion/component/tokenizer.go
  • internal/ingestion/component/tokenizer_test.go
  • internal/ingestion/pipeline/template_integration_test.go

Comment on lines +205 to +207
func expectedFixedEmbedderFirst(name, text string) float64 {
return 0.1*float64(len(name)) + 0.9*float64(len(text))
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Check the current fixedEmbedder.Encode implementation
rg -n -A10 'func.*fixedEmbedder.*Encode' internal/ingestion/pipeline/template_integration_test.go
# Check all usages of expectedFixedEmbedderFirst
rg -n 'expectedFixedEmbedderFirst' internal/ingestion/

Repository: infiniflow/ragflow

Length of output: 1487


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Inspect the helper and the one non-empty-name call site
sed -n '180,220p' internal/ingestion/pipeline/test_helpers.go
sed -n '1080,1125p' internal/ingestion/pipeline/template_integration_test.go

# Look for any other expected-vector helpers that might explain the formula
rg -n -A3 -B3 'expected.*First|Vector:\s+\[]float64|0\.1\*float64\(len\(name\)\)' internal/ingestion/pipeline/

Repository: infiniflow/ragflow

Length of output: 9033


🏁 Script executed:

#!/bin/bash
set -euo pipefail

sed -n '1040,1110p' internal/ingestion/pipeline/template_integration_test.go

Repository: infiniflow/ragflow

Length of output: 2570


🏁 Script executed:

#!/bin/bash
set -euo pipefail

rg -n -A4 -B4 'assertTokenizerTerminalChunk\(' internal/ingestion/pipeline/template_integration_test.go

Repository: infiniflow/ragflow

Length of output: 865


Align expectedFixedEmbedderFirst with fixedEmbedder.Encode internal/ingestion/pipeline/test_helpers.go:205

fixedEmbedder.Encode sets the first vector element to float64(len(text)), but this helper still uses the weighted name/text formula. That makes the integration assertions compare against the wrong value; update the helper to match the embedder.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/ingestion/pipeline/test_helpers.go` around lines 205 - 207, The
helper expectedFixedEmbedderFirst is out of sync with fixedEmbedder.Encode: it
still computes a weighted name/text value instead of matching the embedder’s
first vector element. Update expectedFixedEmbedderFirst to mirror
fixedEmbedder.Encode by deriving the first value from the text length only, so
the integration assertions use the same behavior as the embedder.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
internal/ingestion/pipeline/test_helpers.go (1)

205-207: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Make expectedFixedEmbedderFirst text-only internal/ingestion/pipeline/test_helpers.go:205 still mixes name into the expected first vector value, but fixedEmbedder.Encode sets it to float64(len(text)). The name-aware call at internal/ingestion/pipeline/template_integration_test.go:1101 will compare against the wrong value.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/ingestion/pipeline/test_helpers.go` around lines 205 - 207,
`expectedFixedEmbedderFirst` is still calculating the first vector value from
both `name` and `text`, but `fixedEmbedder.Encode` uses only the text length for
that slot. Update `expectedFixedEmbedderFirst` in `test_helpers.go` to be
text-only, and make sure the `template_integration_test` expectation that passes
`name` still matches the new helper behavior by using only the text value for
the first element.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@internal/ingestion/pipeline/test_helpers.go`:
- Around line 205-207: `expectedFixedEmbedderFirst` is still calculating the
first vector value from both `name` and `text`, but `fixedEmbedder.Encode` uses
only the text length for that slot. Update `expectedFixedEmbedderFirst` in
`test_helpers.go` to be text-only, and make sure the `template_integration_test`
expectation that passes `name` still matches the new helper behavior by using
only the text value for the first element.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: e56cd54f-cd7c-478a-9b1a-1cda80d50c02

📥 Commits

Reviewing files that changed from the base of the PR and between de21785 and 03dd618.

📒 Files selected for processing (4)
  • internal/ingestion/component/slice3_test.go
  • internal/ingestion/component/tokenizer.go
  • internal/ingestion/pipeline/real_storage_integration_test.go
  • internal/ingestion/pipeline/test_helpers.go
🚧 Files skipped from review as they are similar to previous changes (2)
  • internal/ingestion/pipeline/real_storage_integration_test.go
  • internal/ingestion/component/tokenizer.go

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continue Integration 💞 feature Feature request, pull request that fullfill a new feature. size:XXL This PR changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants