Repository navigation
Conversation
… custom inputs
Three Go-mode agent canvas fixes:
1. Agent retrieval returned no chunks: the NLP retrieval adapter never
resolved the knowledge base's embedding model, so searches ran
keyword-only and were filtered out by the similarity threshold.
Resolve the kb embedding model (and optional rerank model) via an
injected RetrievalModelProvider and mount them on the nlp request
for hybrid search, matching the Python canvas. Also surface the
node's empty_response as formalized_content when nothing is found,
and thread rerank_id through the tool request.
2. Knowledge base selector showed an empty list: server-side
pagination combined with the client-side chunk_count>0 filter could
filter out an entire page, leaving an empty, unscrollable dropdown
that never loaded the next page. Auto-fetch the next page while the
filtered list is empty and more pages exist. Also stop rendering
variable icons as image URLs (bogus /sys.* img requests).
3. Begin custom inputs (test-run panel / chat form) were dropped:
RunAgent ignored the request's inputs, so {begin@<key>} references
never resolved. Thread begin inputs through RunAgent and seed them
as the Begin component's outputs; add the single-input sys.query
fallback in the Begin component, mirroring Python Begin._invoke.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (5)
🚧 Files skipped from review as they are similar to previous changes (4)
📝 WalkthroughWalkthroughThe PR adds Begin input propagation and fallback behavior, retrieval embedding/rerank model resolution, empty retrieval responses, updated ChangesRetrieval model integration
Begin input propagation
Knowledge list UI updates
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant Client
participant AgentHandler
participant AgentService
participant CanvasState
participant BeginComponent
Client->>AgentHandler: Submit query and beginInputs
AgentHandler->>AgentService: RunAgent(beginInputs)
AgentService->>CanvasState: Seed begin variables
CanvasState->>BeginComponent: Provide Begin outputs
BeginComponent-->>AgentService: Return resolved inputs
Possibly related PRs
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Nitpick comments (2)
internal/agent/tool/retrieval_nlp.go (1)
274-287: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winSilent keyword-only fallback when
tenantIDresolves empty.If
req.TenantIDis blank and no KB carries a tenant, both guards fail closed without a trace: the embedding model is never attached (reintroducing exactly the empty-results bug this change targets) and an explicitly configuredRerankIDis dropped. A debug/warn line makes that state diagnosable.♻️ Log the degraded path
+ if tenantID == "" && (embdID != "" || req.RerankID != "") { + common.Warn("agent retrieval: no tenant resolved; skipping embedding/rerank model attachment (keyword-only)", + zap.String("embd_id", embdID), + zap.String("rerank_id", req.RerankID), + ) + } if embdID != "" && tenantID != "" {Requires
common/zapimports if not already present in this file.🤖 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/agent/tool/retrieval_nlp.go` around lines 274 - 287, Update the embedding and rerank resolution flow around GetEmbeddingModel and GetRerankModel to log a debug or warning message when the corresponding ID is configured but tenantID is empty, instead of silently skipping resolution. Include enough context to identify the degraded keyword-only path, while preserving the existing guarded model attachment and error handling.internal/agent/tool/retrieval_nlp_test.go (1)
355-355: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win
fakeRetrievalModelProvider.erris never injected — the provider-failure path is untested.The field exists but no test sets it, so the error wrapping at
internal/agent/tool/retrieval_nlp.golines 277 and 284 has no coverage. Either exercise it or drop the field.♻️ Add a provider-error test
func TestAttachRetrievalModels_ProviderErrorPropagates(t *testing.T) { provider := &fakeRetrievalModelProvider{err: errors.New("boom")} SetRetrievalModelProvider(provider) t.Cleanup(func() { SetRetrievalModelProvider(nil) }) nlpReq := &nlp.RetrievalRequest{} err := attachRetrievalModels( context.Background(), RetrievalRequest{TenantID: "tenant-a"}, []*entity.Knowledgebase{{ID: "kb-1", TenantID: "tenant-a", EmbdID: "emb-a"}}, nlpReq, ) if err == nil || !strings.Contains(err.Error(), "resolve embedding model") { t.Fatalf("err = %v, want wrapped embedding resolution failure", err) } if nlpReq.EmbeddingModel != nil { t.Error("EmbeddingModel should stay nil when resolution fails") } }Also applies to: 452-467
🤖 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/agent/tool/retrieval_nlp_test.go` at line 355, Update the retrieval NLP tests around fakeRetrievalModelProvider and attachRetrievalModels to inject a provider error and exercise the failure path. Add coverage that verifies the returned error includes the embedding-model resolution context and that nlpReq.EmbeddingModel remains nil; otherwise remove the unused err field.
🤖 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/agent/component/begin.go`:
- Around line 114-118: Persist fallback values in the reserved begin namespace:
in internal/agent/component/begin.go:114-118, update the fallback branch around
Invoke to call state.SetVar("begin", fallbackKey, fallbackValue) while retaining
the returned output. In internal/agent/component/begin_test.go:180-186, add an
assertion that state.GetVar("begin@color") resolves to the fallback value.
In `@internal/agent/component/universe_a_wrappers.go`:
- Around line 182-188: Restrict the empty-response fallback in the wrapper
handling around parseToolEnvelope to confirmed empty-result envelopes: validate
that parsing succeeded, inspect the parsed chunks field, and only apply
c.params.EmptyResponse when chunks are empty and formalized_content is blank. Do
not replace non-JSON {"_raw": ...} results or envelopes containing chunks.
- Around line 182-188: The fallback logic after parseToolEnvelope in
InvokableRun must apply only to supported chunk-result envelopes with zero
chunks. Validate the decoded envelope’s chunks/result shape before setting
formalized_content, excluding raw non-object wrappers and empty objects;
preserve the configured EmptyResponse behavior for genuine zero-result chunk
responses.
---
Nitpick comments:
In `@internal/agent/tool/retrieval_nlp_test.go`:
- Line 355: Update the retrieval NLP tests around fakeRetrievalModelProvider and
attachRetrievalModels to inject a provider error and exercise the failure path.
Add coverage that verifies the returned error includes the embedding-model
resolution context and that nlpReq.EmbeddingModel remains nil; otherwise remove
the unused err field.
In `@internal/agent/tool/retrieval_nlp.go`:
- Around line 274-287: Update the embedding and rerank resolution flow around
GetEmbeddingModel and GetRerankModel to log a debug or warning message when the
corresponding ID is configured but tenantID is empty, instead of silently
skipping resolution. Include enough context to identify the degraded
keyword-only path, while preserving the existing guarded model attachment and
error handling.
🪄 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 Plus
Run ID: 03bf6b9f-79d1-43a9-b3e6-916c089bf622
📒 Files selected for processing (18)
cmd/ragflow_server.gointernal/agent/component/begin.gointernal/agent/component/begin_test.gointernal/agent/component/retrieval_swap_test.gointernal/agent/component/universe_a_wrappers.gointernal/agent/tool/retrieval.gointernal/agent/tool/retrieval_nlp.gointernal/agent/tool/retrieval_nlp_test.gointernal/agent/tool/retrieval_service.gointernal/handler/agent.gointernal/handler/agent_test.gointernal/handler/agent_wait_for_user_test.gointernal/service/agent.gointernal/service/agent_run_e2e_test.gointernal/service/agent_test.gointernal/service/bot.goweb/src/components/knowledge-base-item.tsxweb/src/hooks/use-knowledge-request.ts
💤 Files with no reviewable changes (1)
- web/src/components/knowledge-base-item.tsx
wangq8
left a comment
There was a problem hiding this comment.
Three well-scoped fixes that collectively make Go-mode agent canvas usable. Good work.
Fix 1 — Agent retrieval returned no chunks:
The root cause is clear: without resolving the KB's embedding model, the nlp request ran keyword-only and results never passed the similarity threshold. Wiring RetrievalModelProvider via injection (cleanly avoiding import cycles) and mounting embedding + rerank models on the request enables true hybrid search.
Fix 2 — KB selector empty dropdown:
The combination of server-side pagination + client-side chunk_count > 0 filter could produce an empty page that never triggers the next-page load. Auto-fetching the next page while results are empty and more pages exist is a pragmatic fix. The icon rendering fix is also correct.
Fix 3 — Begin custom inputs dropped:
Threading beginInputs through RunAgent and seeding them as Begin outputs before the first component runs correctly mirrors Python's behavior. The singleDeclaredInputKey + beginBucketEmpty guards ensure the sys.query fallback only fires when appropriate.
Minor suggestions:
seedBeginInputOutputsiteratesbeginInputsbut does not distinguish between known fields and unknown keys. Consider warning on unrecognized keys for debuggability.- The
EmptyResultFillsEmptyResponsetest uses an empty query — consider adding a test where the query matches but the similarity threshold filters everything (more representative of the actual bug scenario).
Approved — these are solid fixes.
…ed empty envelope
- Begin: write the single-input sys.query fallback into the reserved
Outputs["begin"] namespace via state.SetVar so {begin@<key>} refs
resolve even with node ids like begin_0.
- Retrieval tool: always serialize the chunks field (no omitempty) so
a zero-hit search yields a confirmed empty-result envelope
({"chunks": []}) instead of a bare {}.
- Retrieval component: apply the empty_response fallback only for a
confirmed empty-result envelope (parsed object with an empty chunks
array); raw non-JSON output, error stubs, envelopes with chunks but
no rendered text, and unrelated {} shapes are left untouched.
|
@euvre resolve conflict. |
Summary
Three fixes for the Go-mode agent canvas:
1. Agent retrieval returned no chunks. The NLP retrieval adapter never resolved the knowledge base's embedding model, so searches ran keyword-only and the results were filtered out by the similarity threshold — downstream Agent components concluded the knowledge base had no relevant content. The adapter now resolves the kb's embedding model (and the node's optional rerank model) through an injected
RetrievalModelProviderand mounts them on the nlp request, enabling hybrid (fulltext + vector + fusion) search, matching the Python canvas. Thererank_idnode param is also threaded through (previously dropped silently), and when nothing is found the node'sempty_responseis surfaced asformalized_contentinstead of an empty output map.2. Knowledge base selector showed an empty list. Server-side pagination combined with the client-side
chunk_count > 0filter could filter out an entire page, leaving an empty, unscrollable dropdown that never triggered the next-page load. The list now auto-fetches the next page while the filtered result is empty and more pages exist. Also fixed variable option icons being rendered as image URLs, which fired bogus/sys.*img requests per option.3. Begin custom inputs (test-run panel / chat form) were dropped.
RunAgentignored the request'sinputs, so{begin@<key>}references (e.g. in a Retrieval query) never resolved in Go mode. Begin inputs are now threaded throughRunAgentand seeded as the Begin component's outputs, and the Begin component applies the single-inputsys.queryfallback, mirroring Python'sBegin._invoke.Tests:
bash build.sh --test ./internal/agent/... ./internal/service/ ./cmd/...all pass; new unit tests cover the model attachment, empty-response fill, begin input seeding, and the sys.query fallback.