Skip to content

utf-8 encoding issue for PDFs #174

Description

@caizixian

I'm currently running the latest rag_api docker image, and have trouble with some of the PDF files.
This is the backtrace from the FastAPI backend

2025-07-21 12:42:02,569 - root - ERROR - Error during file processing: 'utf-8' codec can't encode character '\ud835' in position 416: surrogates not allowed
Traceback: Traceback (most recent call last):
  File "/app/app/routes/document_routes.py", line 419, in embed_file
    result = await store_data_in_vector_db(
  File "/app/app/routes/document_routes.py", line 274, in store_data_in_vector_db
    docs = [
  File "/app/app/routes/document_routes.py", line 280, in <listcomp>
    "digest": generate_digest(doc.page_content),
  File "/app/app/routes/document_routes.py", line 252, in generate_digest
    hash_obj = hashlib.md5(page_content.encode())
UnicodeEncodeError: 'utf-8' codec can't encode character '\ud835' in position 416: surrogates not allowed

So the PDFs might contain invalid utf-8 characters for hashing

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions