Repository navigation
fix: refresh Go chunk vectors when embedding input changes - #20552
GoldArowana wants to merge 2 commits into
Conversation
Preserve omitted content and questions and compare the effective embedding body before resolving the dataset embedding model. Generate and validate the weighted title/body vector before image and index writes, with offline regressions for update semantics and failures.
|
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Select update text and refresh embeddings internal/service/chunk/chunk.go, internal/service/chunk/chunk_test.go, internal/service/chunk/chunk_update_embedding_test.go |
UpdateChunk preserves omitted content and questions, trims supplied questions, and uses content when no usable questions remain. When embedding text changes, it resolves the embedding model, embeds the document name and text, and updates the vector. Tests check the update values and vector. |
Validate failures, ordering, and authorization internal/service/chunk/chunk_test.go, internal/service/chunk/chunk_update_embedding_test.go |
Tests verify that model, provider, result-count, and vector-dimension errors prevent writes. They also check that embedding precedes image storage and that authorization failures prevent model lookup and embedding. |
Priority:
Estimated code review effort: 3 (Moderate) | ~20 minutes
Change: Bug fix
Suggested reviewers: buua436
Merge Risk: 
Minimal · up to 79008
-
No actionable issue identified; the change is ready for normal merge checks.
Security architecture risk: 
Low · up to 2ecc9
-
The update preserves existing access checks and rejects embedding failures before changing stored data. No new authorization bypass was identified. Deployment-specific handling of text sent for embedding and concurrent-update guarantees remain incompletely established.
Retained concerns
No architecture-level concerns identified.Security review details
-
Security Blast Radius
- observed — An authenticated editor can now cause document title and request- or stored-field-derived text to reach the configured embedding driver during a chunk update. This is a new update-time data flow compared with base, scoped by the selected knowledge base. Provider deployment and redaction/egress policy were not established.
Trust Boundaries and Controls
- observed — The handler supplies authenticated user identity. Before embedding, the service checks accessible tenant membership, tenant-scoped dataset lookup, document membership, and stored chunk document identity. The index update retains the authorized tenant index, dataset argument, and original id/document condition; the inspected Elasticsearch entrypoint adds dataset scoping.
Resilience and Maintainability Implications
- observed — Model resolution, embedding, and vector validation failures return before image storage, index mutation, or Wiki invalidation. Subsequent image/index cleanup ordering remains as in base: image creation precedes index publication, and image removal follows it. The flow is not a cross-store transaction; those later partial-failure limitations predate this PR.
-
Pre-merge checks: 
4 · 
1
-
Failed checks: 1 warning Passed checks: 4 passed -
- Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
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.
A rabbit checks the chunk’s new text,
And keeps the questions still intact.
Two vectors merge, the index waits,
No write proceeds when errors rise.
The bunny hops; tests guard the path.
Comment @coderabbitai help to get the list of available commands.
|
@GoldArowana Please resolve the conflicts |
|
Merged current main into this branch in 7900894 and resolved the UpdateChunk conflict by retaining the new dataset permission check. Embedding lookup now uses the authorized knowledgebase returned by that check; the regression fixture and denied-access assertion were updated for the current API. Validation: |
|
Walked the refresh logic end to end. Change detection compares the rebuilt embedding text against the stored one through the same buildChunkEmbeddingText fallback chain (trimmed, non-empty questions joined with a newline, otherwise the content), so trim-equivalent edits, the legacy content field, interface-typed stored questions, and explicit-empty replacements all behave consistently - the 16-case table pins each of these. The re-embed itself reuses the exact insert-path shape: Texts [docName, embeddingText], Dimension 0, and mergeChunkEmbeddings at 0.1 title + 0.9 chunk, the same weights and ordering used when chunks are embedded during parsing. I checked the test arithmetic too: the [10,20,30]/[30,40,50] stub produces the expected [28,38,48]. Unrelated updates (available, positions, tags, keywords) correctly skip the model lookup entirely. Source-level review only, I could not run go test in this environment. |
Summary
UpdateChunkchanged content or questions without regenerating the stored embedding vector, so retrieval could use a vector for the previous effective text.This change compares the old and new effective embedding body after applying partial-update semantics. It preserves omitted content/questions, accepts stored questions as either
[]stringor[]interface{}, trims and newline-joins nonempty questions, and uses content when there are no nonempty questions. Explicitquestions: []clears questions. Content-only edits with retained nonempty questions, equivalent effective text, and unrelated field edits skip embedding.When that body changes, the authorized knowledgebase supplies the tenant and EmbdID. The service follows AddChunk's existing contract: embed document title and body with Dimension 0, require two nonempty equal-dimension vectors, combine
0.1 * title + 0.9 * body, and includeq_<dim>_vecin the index update. Model resolution, embedding, and vector validation finish before image storage and index writes. Original document authorization and{id, doc_id}update conditions are preserved.Regression coverage
Offline deterministic stubs cover content edits without questions, changed questions, omitted fields, explicit empty arrays, both stored question-array types, whitespace normalization, unchanged effective input, unrelated updates, nil title, and the exact weighted vector
[28, 38, 48]. Tests also verify the selected tenant/model, two exact embedding texts, Dimension 0, and original document scope.Seven failure cases cover model lookup/provider errors, 0/1/3 vectors, empty dimensions, and unequal dimensions, asserting no index/image/Wiki writes. A mixed image/content request verifies embedding runs before image storage. Existing image-removal behavior still has its own independent side effects: this change does not provide transaction rollback across image storage and the index.
The new regression group failed before the fix (3 of 4 main tests and 16 of 27 subtests failed, exit 1). After the fix, all 4 main tests and 27 subtests pass. Changes do not extend to
question_tks, model selection, or index schema.Validation
1.27.1, CGO enabled,cgo,statictags, verified local native dependencies and module checksums; all embeddings use deterministic stubs.build.shtest entry point,main --test -p 2 -v ./internal/service/chunk/... ./internal/handler/...: 543 main tests and 171 subtests passed, exit 0, no compiler warnings./home/agentnative cache read-only. Validation sourced the unchangedbuild.sh, redirected its cache-prefix variables to verified workspace caches, and invoked itsmain --testentry point with the arguments above. No build script, module, or environment changes are included in this PR.Upstream CI and maintainer review remain merge gates; local package validation is not a full RAGFlow readiness claim.