Skip to content

fix: populate fileUrl for knowledge base documents on load#479

Open
code-xpertai[bot] wants to merge 1 commit into
mainfrom
code-x/dpwxbk
Open

fix: populate fileUrl for knowledge base documents on load#479
code-xpertai[bot] wants to merge 1 commit into
mainfrom
code-x/dpwxbk

Conversation

@code-xpertai

@code-xpertai code-xpertai Bot commented Mar 27, 2026

Copy link
Copy Markdown

Summary

Fixes #448 - Abnormal image path in knowledge base retrieval results

Problem

When knowledge base documents are created from uploaded files, the fileUrl field is not populated. This causes images to fail rendering in the knowledge base search results.

Root Cause

The KnowledgeDocumentSubscriber had an afterLoad hook that attempted to populate fileUrl from StorageFile, but:

  1. It used findOneBy which was deprecated (changed to findOne with where clause)
  2. It tried to access storageFile.fileUrl which doesn't exist on StorageFile entity (the entity has file and storageProvider fields, and fileUrl is computed dynamically in StorageFileSubscriber.afterLoad)

Solution

Updated the afterLoad hook in KnowledgeDocumentSubscriber to:

  1. Use findOne with proper where clause and select to only fetch needed fields
  2. Compute fileUrl directly using FileStorage API (same approach as StorageFileSubscriber)

Changes

  • Modified packages/server-ai/src/knowledge-document/document.subscriber.ts
    • Fixed beforeInsert to use findOne instead of deprecated findOneBy
    • Fixed afterLoad to properly compute fileUrl from StorageFile.file and StorageFile.storageProvider

Testing

The fix ensures that when a KnowledgeDocument entity is loaded from the database:

  1. If it has a storageFileId but no fileUrl
  2. The subscriber fetches the related StorageFile record
  3. Computes the full URL using the storage provider
  4. Populates entity.fileUrl with the correct URL

This matches the behavior of StorageFileSubscriber.afterLoad which already handles this for StorageFile entities.

@ponyfly6

ponyfly6 commented Apr 2, 2026

Copy link
Copy Markdown
Contributor

@xpert-ai 你review一下

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Abnormal image path in knowledge base retrieval results

1 participant