mirror of
https://github.com/open-webui/open-webui.git
synced 2026-10-06 02:48:04 +00:00
Fix knowledge file upload
* https://github.com/open-webui/open-webui/issues/24974
This commit is contained in:
parent
084d040e22
commit
c4d5054b7b
1 changed files with 11 additions and 9 deletions
|
|
@ -1,5 +1,3 @@
|
|||
from datetime import datetime
|
||||
|
||||
from open_webui.utils.misc import sanitize_text_for_db
|
||||
|
||||
KEYS_TO_EXCLUDE = ['content', 'pages', 'tables', 'paragraphs', 'sections', 'figures']
|
||||
|
|
@ -14,16 +12,20 @@ def filter_metadata(metadata: dict[str, any]) -> dict[str, any]:
|
|||
def process_metadata(
|
||||
metadata: dict[str, any],
|
||||
) -> dict[str, any]:
|
||||
# Removes large fields, converts non-serializable types (datetime, list, dict) to strings,
|
||||
# and sanitizes strings for database storage (strips null bytes and invalid surrogates).
|
||||
# Returns a dict whose values are only str/int/float/bool, which all supported
|
||||
# vector DBs accept (notably ChromaDB's Rust bindings, which reject None and
|
||||
# non-primitive types). Drops KEYS_TO_EXCLUDE and None values; coerces any
|
||||
# other non-primitive (datetime, list, dict, tuple, bytes, numpy, ...) via str().
|
||||
result = {}
|
||||
for key, value in metadata.items():
|
||||
# Skip large fields
|
||||
if key in KEYS_TO_EXCLUDE:
|
||||
continue
|
||||
# Convert non-serializable fields to strings
|
||||
if isinstance(value, (datetime, list, dict)):
|
||||
result[key] = sanitize_text_for_db(str(value))
|
||||
else:
|
||||
if value is None:
|
||||
continue
|
||||
if isinstance(value, bool) or isinstance(value, (int, float)):
|
||||
result[key] = value
|
||||
elif isinstance(value, str):
|
||||
result[key] = sanitize_text_for_db(value)
|
||||
else:
|
||||
result[key] = sanitize_text_for_db(str(value))
|
||||
return result
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue