Conversation
…g tenant A knowledge base shared into a shared space is written by the owning tenant but parsed with the viewer's tenant in ctx, so the plain ctx-tenant model lookup searched a tenant that never had the model row. Every document in a shared knowledge base then failed with "Model not found" and stayed unindexed, so it was unsearchable for anyone but its owner. Resolve under kb.TenantID when it differs from ctx, the same branch the search path already uses in knowledgeBaseService.GetQueryEmbedding, and route all five processing-pipeline call sites through it so a shared knowledge base embeds and queries with one provider and vector space. A ctx carrying no tenant still falls through to the plain lookup: that error belongs to the model service, as it was before. Fixes Tencent#1998
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
A knowledge base shared into a shared space is written by the tenant that owns it, but it is parsed with the viewer's tenant in
ctx. Every embedding-model resolution in the processing pipeline therefore looked the model row up in a tenant that never had it, and each document failed withModel not found:The result is that a shared knowledge base is unsearchable for everyone but its owner — every document it ingests ends in
parse_status=failedwithenable_status=disabled, so the shared space silently has nothing to retrieve.The search side already gets this right:
knowledgeBaseService.GetQueryEmbeddingresolves a shared knowledge base's model underkb.TenantID. Only the processing pipeline was still resolving byctx, so a shared knowledge base indexed and queried through different code paths.This adds
resolveKBEmbeddingModel, which applies the same branch the search path uses, and routes all five processing-pipeline call sites through it:processChunksProcessSummaryGenerationprocessQuestionGenerationForKnowledgeprocessQuestionGenerationForChunksupdateChunkVectorA
ctxcarrying no tenant still falls through to the plain lookup rather than panicking in the new branch: that error is the model service's to report, exactly as it was before.Scoping notes
knowledgeBaseService.ProcessKBDeletealso resolves a model byctx, but it is a different service, it groups by the knowledge row's ownEmbeddingModelID, and it already treats a resolution failure as non-fatal (logger.Warnf+continue) — so it does not produce the reported breakage. Left alone to keep this diff to one concern.knowledge_clone_move.goresolves against a destination knowledge base the calling tenant owns, soctxandkb.TenantIDagree there by construction.Type of Change
Related Issue
Fixes #1998
Testing
New regression coverage in
internal/application/service/knowledge_process_shared_kb_embedding_test.go, reusing the existingprocessChunkscollaborators so the real code path runs:TestProcessChunksIndexesSharedKnowledgeBaseUnderOwningTenant— a knowledge base owned by tenant 10000, parsed with tenant 10001 inctx, against a model service that only knows the owner's row. Asserts the model is resolved under the owning tenant, the viewer's tenant is never used for the lookup, and the document is chunked and indexed.TestProcessChunksKeepsCtxLookupForOwnKnowledgeBase— the ordinary owned path still uses the plainctxlookup, so behaviour is unchanged without cross-tenant sharing.TestResolveKBEmbeddingModel— the branch itself: shared → owner tenant, owned →ctx, actxwith no tenant still falls through to the plain lookup instead of panicking, and an owner-side provider failure still surfaces.Commands run (all green):
The new tests were confirmed to be real regressions: reverting only the five call sites to the previous
ctx-tenant lookup makesTestProcessChunksIndexesSharedKnowledgeBaseUnderOwningTenantfail with "a shared knowledge base must resolve its embedding model under the owning tenant", and the fix is what turns it green.The full package suite (
go test ./internal/application/service/) passes exceptTestSkillPythonVerifier, which also fails on the unmodifiedmainin this environment and is unrelated to this change (skill Python verifier, no shared-knowledge-base involvement).Checklist
git diff --check origin/main...HEADpassesgolangci-lint run --new-from-rev=origin/main ./...) —golangci-lintis not available in this environment;go vetandgofmtare cleanwebsite-docs/, Swagger annotations, etc.) — no user-facing behaviour or API surface changes