mirror of
https://github.com/open-webui/open-webui.git
synced 2026-10-11 03:38:02 +00:00
fix: show a knowledge file's current name in citations after it is renamed (#31860)
This commit is contained in:
parent
0c3f74c9c1
commit
94e9c7fef9
2 changed files with 31 additions and 0 deletions
|
|
@ -1704,6 +1704,24 @@ async def get_sources_from_items(
|
|||
sources.append(source)
|
||||
except Exception as e:
|
||||
log.exception(e)
|
||||
|
||||
file_ids = {
|
||||
metadata['file_id']
|
||||
for source in sources
|
||||
for metadata in source['metadata']
|
||||
if isinstance(metadata, dict) and metadata.get('file_id')
|
||||
}
|
||||
if file_ids:
|
||||
file_names = {
|
||||
file.id: (file.meta or {}).get('name') for file in await Files.get_file_metadatas_by_ids(list(file_ids))
|
||||
}
|
||||
for source in sources:
|
||||
for metadata in source['metadata']:
|
||||
file_name = file_names.get(metadata.get('file_id')) if isinstance(metadata, dict) else None
|
||||
if file_name:
|
||||
if metadata.get('source') == metadata.get('name'):
|
||||
metadata['source'] = file_name
|
||||
metadata['name'] = file_name
|
||||
return sources
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -3325,6 +3325,19 @@ async def query_knowledge_files(
|
|||
metadatas = query_results.get('metadatas', [[]])[0]
|
||||
distances = query_results.get('distances', [[]])[0]
|
||||
|
||||
file_ids = {metadata['file_id'] for metadata in metadatas if metadata.get('file_id')}
|
||||
if file_ids:
|
||||
file_names = {
|
||||
file.id: (file.meta or {}).get('name')
|
||||
for file in await Files.get_file_metadatas_by_ids(list(file_ids))
|
||||
}
|
||||
for metadata in metadatas:
|
||||
file_name = file_names.get(metadata.get('file_id'))
|
||||
if file_name:
|
||||
if metadata.get('source') == metadata.get('name'):
|
||||
metadata['source'] = file_name
|
||||
metadata['name'] = file_name
|
||||
|
||||
for idx, doc in enumerate(documents):
|
||||
chunk_info = {
|
||||
**filter_source_metadata(metadatas[idx]),
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue