Skip to content

fix: correct multi-tenant retrieval scope - #20824

Merged
wangq8 merged 3 commits into
infiniflow:mainfrom
QAQadws:codex/fix-multi-tenant-retrieval
Oct 12, 2026
Merged

wangq8 merged 3 commits into
infiniflow:mainfrom
QAQadws:codex/fix-multi-tenant-retrieval

Conversation

@QAQadws

@QAQadws QAQadws commented Oct 12, 2026

Copy link
Copy Markdown
Contributor
  • Search metadata across all requested dataset tenants instead of only the first, preventing missing documents in metadata filtering.

  • Search all relevant tenant indices for KNN rescoring and parent-chunk lookup, preserving scores and parent context across tenants.

@coderabbitai

coderabbitai Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 0328ff5c-126b-453c-beca-aedc14ec34d9

📥 Commits

Reviewing files that changed from the base of the PR and between 8079fe5 and c2ed921.


📒 Files selected for processing (11)
  • internal/dao/kb.go
  • internal/engine/elasticsearch/chunk.go
  • internal/engine/elasticsearch/chunk_helpers_test.go
  • internal/engine/elasticsearch/metadata.go
  • internal/engine/elasticsearch/metadata_pushdown_test.go
  • internal/engine/infinity/metadata.go
  • internal/engine/infinity/metadata_pushdown_test.go
  • internal/service/metadata.go
  • internal/service/metadata_resolver_test.go
  • internal/service/nlp/retrieval.go
  • internal/service/nlp/retrieval_test.go

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.



📝 Walkthrough

Walkthrough

The change adds tenant-based grouping for knowledge-base IDs and uses it across metadata searches, metadata pushdown, KNN scoring, and parent-chunk lookup. Elasticsearch searches all relevant indices with partial results disabled. Infinity combines per-tenant metadata results, deduplicates IDs, and returns nil when lookup or result limits prevent a complete result.

Changes

Tenant-scoped searches

Layer / File(s) Summary
Tenant grouping and service metadata search
internal/dao/kb.go, internal/service/metadata.go, internal/service/metadata_resolver_test.go
Adds a tenant-grouping function for knowledge-base IDs. SearchMetadataByKBs searches each tenant with that tenant’s IDs and combines the records. SearchMetadataResponse no longer includes IndexName. Tests cover tenant grouping, result combination, and failed tenant searches.
Elasticsearch cross-index searches
internal/engine/elasticsearch/chunk.go, internal/engine/elasticsearch/chunk_helpers_test.go, internal/engine/elasticsearch/metadata.go, internal/engine/elasticsearch/metadata_pushdown_test.go, internal/service/nlp/retrieval.go, internal/service/nlp/retrieval_test.go
KNN scoring and metadata pushdown search across candidate or tenant indices. Both searches disable partial results. Parent-chunk lookup searches all tenant indices while retaining the child document and knowledge-base filters. Tests cover the expanded search scopes and failure cases.
Infinity metadata pushdown
internal/engine/infinity/metadata.go, internal/engine/infinity/metadata_pushdown_test.go
Metadata pushdown queries each tenant and combines deduplicated document IDs. It returns nil when a tenant query fails or the combined result exceeds the limit. If the total-hit count is unavailable, reaching the limit also returns nil.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Bug fix

Suggested reviewers: jinhai-cn


Merge Risk: ⚪ Minimal · up to c2ed9

No actionable merge-blocking issue was established in the reviewed changes. The multi-tenant searches appear mergeable after normal checks.

Pre-merge checks | Passed 4 | Failed 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 36.36% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 11 functions across 11 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check Passed The title clearly summarizes the main change: correcting retrieval scope across multiple tenants.
Description check Passed The description explains the main objective and covers metadata search, KNN rescoring, and parent-chunk lookup across tenant indices. It does not include the template's "### Summary" heading, but the …
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.

  • Fix all pre-merge checks with AI
  • Autofix · 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.

❤️ Share

A rabbit checks each tenant trail
And sends the search to every dale
IDs come back, duplicates flee
The indices answer separately
Then carrots mark the counts complete

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

@QAQadws QAQadws added the ci Continue Integration label Oct 12, 2026
@QAQadws
QAQadws requested a review from Lynn-Inf October 12, 2026 08:30

@Lynn-Inf Lynn-Inf 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.

LGTM — the fix correctly scopes retrieval to all requested dataset tenants for the officially supported engines (Elasticsearch and Infinity).

For reference (not blocking): oceanbase (also backing seekdb) still has the same pattern in FilterDocIdsByMetaPushdown — it resolves only kbIDs[0]'s tenant while filtering the full kbIDs list, so multi-tenant metadata filtering silently drops docs there too. Since oceanbase is externally maintained (and vastbase/serenedb are community engines whose push-down is a no-op), this can be left to community contributors rather than included here.

@wangq8
wangq8 merged commit e7a3aef into infiniflow:main Oct 12, 2026
6 checks passed
Xavierando added a commit to Xavierando/ragflow that referenced this pull request Oct 12, 2026
# Conflicts:
#	internal/service/metadata.go
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continue Integration

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants