Skip to content

feat[Go]: implement searches/<search_id>/completions POST - #16440

Merged
JinHai-CN merged 8 commits into
infiniflow:mainfrom
Haruko386:master
Jun 29, 2026
Merged

JinHai-CN merged 8 commits into
infiniflow:mainfrom
Haruko386:master

Conversation

@Haruko386

@Haruko386 Haruko386 commented Jun 29, 2026 •

Copy link
Copy Markdown
Member

Summary

As title
8e9a1d94cc1fff59eb66fc0d5b948bac

Type of change

  • New Feature (non-breaking change which adds functionality)
  • Bug Fix (non-breaking change which fixes an issue)

@Haruko386 Haruko386 added 🐞 bug Something isn't working, pull request that fix bug. ci Continue Integration labels Jun 29, 2026
@Haruko386
Haruko386 marked this pull request as draft June 29, 2026 05:35
@dosubot dosubot Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Jun 29, 2026
@Haruko386
Haruko386 marked this pull request as ready for review June 29, 2026 05:35
@dosubot dosubot Bot added the 💞 feature Feature request, pull request that fullfill a new feature. label Jun 29, 2026
@coderabbitai

coderabbitai Bot commented Jun 29, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It 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 reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds 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.

Changes

Search Completion Streaming

Layer / File(s) Summary
Search completion planning and AskStreamOptions contracts
internal/service/search.go, internal/service/ask_service.go
SearchService gains tenantService, completion access/planning, search-config parsing helpers, and request/plan types; AskService gains AskStreamOptions and StreamWithOptions.
Completion SSE handler and route registration
internal/handler/search.go, internal/router/router.go
SearchHandler gains completion streaming fields and SetCompletionDependencies; Completion authenticates, prepares the plan, configures SSE, and streams answer/marker/error/final deltas. Two POST routes map to the new handler.
Dependency wiring in server startup
cmd/server_main.go
searchService.SetTenantService(tenantService) is added, and completion dependencies are wired onto searchHandler through a shared askService instance.
Embedding and rerank model resolution refactor in ChunkService
internal/service/chunk/chunk.go, internal/service/chunk/chunk_test.go
RetrievalTest switches to provider-instance-first embedding resolution with default fallback, normalizes search_config, updates rerank lookup, and adds knowledgebaseEmbeddingKey plus its test.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Suggested reviewers

  • qinling0210
  • yuzhichang

Suggested labels

lgtm

Possibly related PRs

  • infiniflow/ragflow#16124: Both PRs modify internal/service/search.go’s SearchService and related search-detail plumbing.

Poem

🐇 Hop hop, the search lights gleam,
SSE streams a comin’ beam.
KBs, models, answers too,
Rabbit ears say “through and through!”
A carrot toast for code that sings 🥕

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 13.33% 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 says "As title" and lacks the brief purpose and context requested by the template. Expand the Summary with the problem being solved, why the endpoint is needed, and any relevant background or behavior changes.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly matches the main change: adding a POST completion endpoint for searches.
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.

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.

@Haruko386
Haruko386 marked this pull request as draft June 29, 2026 05:36
@Haruko386
Haruko386 marked this pull request as ready for review June 29, 2026 05:36

@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: 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

📥 Commits

Reviewing files that changed from the base of the PR and between a339e8a and a393b3f.

📒 Files selected for processing (6)
  • cmd/server_main.go
  • internal/handler/search.go
  • internal/router/router.go
  • internal/service/ask_service.go
  • internal/service/chunk/chunk.go
  • internal/service/search.go

Comment thread internal/handler/search.go Resolved
Comment thread internal/service/chunk/chunk.go Resolved
Comment thread internal/service/chunk/chunk.go Resolved
@Haruko386 Haruko386 added ci Continue Integration and removed ci Continue Integration labels Jun 29, 2026
@Haruko386 Haruko386 changed the title Master feat[Go]: implement searches/<search_id>/completions POST Jun 29, 2026
@Haruko386
Haruko386 marked this pull request as draft June 29, 2026 05:57
@Haruko386
Haruko386 marked this pull request as ready for review June 29, 2026 05:57

@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

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 win

Return the fallback lookup error here.

Line 414 wraps getErr, but at this point the direct provider lookup already failed and the actionable failure is err from LookupTenantLLMByName.

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

📥 Commits

Reviewing files that changed from the base of the PR and between a393b3f and 9066ea6.

📒 Files selected for processing (3)
  • internal/handler/search.go
  • internal/service/chunk/chunk.go
  • internal/service/chunk/chunk_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • internal/handler/search.go

Comment thread internal/service/chunk/chunk_test.go Resolved
Comment thread internal/service/chunk/chunk.go Resolved
@codecov

codecov Bot commented Jun 29, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.16%. Comparing base (c0f6429) to head (fd142df).
⚠️ Report is 8 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@JinHai-CN
JinHai-CN merged commit 1c0cdd8 into infiniflow:main Jun 29, 2026
3 checks passed
@Haruko386
Haruko386 deleted the master branch June 30, 2026 05:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🐞 bug Something isn't working, pull request that fix bug. ci Continue Integration 💞 feature Feature request, pull request that fullfill a new feature. size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants