fix: populate fileUrl for knowledge base documents on load#479
Open
code-xpertai[bot] wants to merge 1 commit into
Open
fix: populate fileUrl for knowledge base documents on load#479code-xpertai[bot] wants to merge 1 commit into
code-xpertai[bot] wants to merge 1 commit into
Conversation
4 tasks
Contributor
|
@xpert-ai 你review一下 |
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.
Summary
Fixes #448 - Abnormal image path in knowledge base retrieval results
Problem
When knowledge base documents are created from uploaded files, the
fileUrlfield is not populated. This causes images to fail rendering in the knowledge base search results.Root Cause
The
KnowledgeDocumentSubscriberhad anafterLoadhook that attempted to populatefileUrlfromStorageFile, but:findOneBywhich was deprecated (changed tofindOnewithwhereclause)storageFile.fileUrlwhich doesn't exist onStorageFileentity (the entity hasfileandstorageProviderfields, andfileUrlis computed dynamically inStorageFileSubscriber.afterLoad)Solution
Updated the
afterLoadhook inKnowledgeDocumentSubscriberto:findOnewith properwhereclause andselectto only fetch needed fieldsfileUrldirectly usingFileStorageAPI (same approach asStorageFileSubscriber)Changes
packages/server-ai/src/knowledge-document/document.subscriber.tsbeforeInsertto usefindOneinstead of deprecatedfindOneByafterLoadto properly computefileUrlfromStorageFile.fileandStorageFile.storageProviderTesting
The fix ensures that when a
KnowledgeDocumententity is loaded from the database:storageFileIdbut nofileUrlStorageFilerecordentity.fileUrlwith the correct URLThis matches the behavior of
StorageFileSubscriber.afterLoadwhich already handles this forStorageFileentities.