Repository navigation
feat[Go]: implement searches/<search_id>/completions POST - #16440
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughAdds a streaming search completion endpoint that prepares a completion plan from stored search config, resolves KB and model IDs, and streams LLM deltas over SSE. Also updates startup wiring and chunk retrieval/model resolution. ChangesSearch Completion Streaming
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Suggested reviewers
Suggested labels
Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 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
🤖 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/handler/search.go`:
- Around line 485-515: In search streaming handling, failed paths are still
followed by the terminal success SSE payload, which can make errors look
successful. Update the streaming logic in the search handler around the
plan.ModelID, h.askService, h.streamLLM checks and the
h.askService.StreamWithOptions loop so that any sseError response returns
immediately and skips the final success frame. Ensure only the successful
AskDeltaFinal path in the search stream writes the closing {"code":0,...} event.
In `@internal/service/chunk/chunk.go`:
- Around line 363-374: The mixed-KB embedding validation in the chunk retrieval
flow is only checking EmbdID, so KBs that share an embedding ID but differ by
TenantEmbdID can slip through and use the wrong model. Update the validation
logic in the chunk service path around the embedding resolution branch to
compare TenantEmbdID as part of the compatibility check, and keep it aligned
with the model selection in the TenantEmbdID-first lookup. Make sure the same
rule is applied wherever the KB embedding metadata is validated before retrieval
so the selected embedding model matches all KBs in the batch.
- Around line 232-235: The nested meta_data_filter parsing in the searchConfig
handling still only accepts map[string]interface{}, so entity.JSONMap values are
being skipped. Update the chunk.go logic around searchConfigMap and the search
detail parsing to run meta_data_filter through the same normalization helper
used for search_config, so both map types are accepted and saved filters are
preserved.
🪄 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: 005cd02c-459e-4174-808c-334956640a1d
📒 Files selected for processing (6)
cmd/server_main.gointernal/handler/search.gointernal/router/router.gointernal/service/ask_service.gointernal/service/chunk/chunk.gointernal/service/search.go
There was a problem hiding this comment.
Actionable comments posted: 2
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
internal/service/chunk/chunk.go (1)
410-415: 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick winReturn the fallback lookup error here.
Line 414 wraps
getErr, but at this point the direct provider lookup already failed and the actionable failure iserrfromLookupTenantLLMByName.Proposed fix
_, rerankCompositeName, err = dao.LookupTenantLLMByName(dao.NewTenantLLMDAO(), tenantIDs[0], *req.RerankID, entity.ModelTypeRerank) if err != nil { - return nil, fmt.Errorf("failed to get rerank model by rerank_id: %w", getErr) + return nil, fmt.Errorf("failed to get rerank model by rerank_id: %w", err) }🤖 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/service/chunk/chunk.go` around lines 410 - 415, The fallback rerank model lookup is returning the wrong error in the GetModelConfigFromProviderInstance fallback path. In chunk.go, inside the rerankCompositeName resolution logic, update the error handling in the dao.LookupTenantLLMByName fallback so the returned error wraps the local lookup failure variable err, not getErr; keep the context message the same and ensure the function returns the actionable fallback lookup error from this branch.
🤖 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/service/chunk/chunk_test.go`:
- Around line 80-120: Add a test case in knowledgebaseEmbeddingKey to cover the
empty EmbdID fallback path when TenantEmbdID is nil, and verify the returned key
uses the tenant-default behavior instead of collapsing to the same embd-based
key. Extend TestKnowledgebaseEmbeddingKey with a KB fixture that has neither
TenantEmbdID nor EmbdID, and assert the key produced by
knowledgebaseEmbeddingKey is tenant-scoped and distinct from the shared-model
embd path.
In `@internal/service/chunk/chunk.go`:
- Around line 214-216: The validation and retrieval paths are treating all KBs
with empty TenantEmbdID and EmbdID as the same embd: key, which can mix
different tenant defaults. Update knowledgebaseEmbeddingKey and the callers in
the chunk validation/retrieval flow to incorporate tenant identity when EmbdID
is empty, so defaults are resolved per tenant instead of from tenantIDs[0]. Make
sure the checks around the KB batch comparison and the embedding model selection
logic both use the tenant-aware key consistently.
---
Outside diff comments:
In `@internal/service/chunk/chunk.go`:
- Around line 410-415: The fallback rerank model lookup is returning the wrong
error in the GetModelConfigFromProviderInstance fallback path. In chunk.go,
inside the rerankCompositeName resolution logic, update the error handling in
the dao.LookupTenantLLMByName fallback so the returned error wraps the local
lookup failure variable err, not getErr; keep the context message the same and
ensure the function returns the actionable fallback lookup error from this
branch.
🪄 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: 702dead1-abd6-4783-826d-d189efee95e5
📒 Files selected for processing (3)
internal/handler/search.gointernal/service/chunk/chunk.gointernal/service/chunk/chunk_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
- internal/handler/search.go
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #16440 +/- ##
=======================================
Coverage 93.16% 93.16%
=======================================
Files 10 10
Lines 717 717
Branches 118 118
=======================================
Hits 668 668
Misses 29 29
Partials 20 20 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Summary
As title

Type of change