File tree Expand file tree Collapse file tree
backend/open_webui/routers Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -590,6 +590,29 @@ def update_file_data_content_by_id(
590590 log .exception (e )
591591 log .error (f"Error processing file: { file .id } " )
592592
593+ # Propagate content change to all knowledge collections referencing
594+ # this file. Without this the old embeddings remain in the knowledge
595+ # collection and RAG returns both stale and current data (#20558).
596+ knowledges = Knowledges .get_knowledges_by_file_id (id , db = db )
597+ for knowledge in knowledges :
598+ try :
599+ # Remove old embeddings for this file from the KB collection
600+ VECTOR_DB_CLIENT .delete (
601+ collection_name = knowledge .id , filter = {"file_id" : id }
602+ )
603+ # Re-add from the now-updated file-{file_id} collection
604+ process_file (
605+ request ,
606+ ProcessFileForm (file_id = id , collection_name = knowledge .id ),
607+ user = user ,
608+ db = db ,
609+ )
610+ except Exception as e :
611+ log .warning (
612+ f"Failed to update knowledge { knowledge .id } after "
613+ f"content change for file { id } : { e } "
614+ )
615+
593616 return {"content" : file .data .get ("content" , "" )}
594617 else :
595618 raise HTTPException (
You can’t perform that action at this time.
0 commit comments