langgenius / dify

Dify is an open-source LLM app development platform. Dify's intuitive interface combines AI workflow, RAG pipeline, agent capabilities, model management, observability features and more, letting you quickly go from prototype to production.
https://dify.ai
Other
37.03k stars 5.02k forks source link

Internal Server Error (code: unknown) occurs when specifying more than 252 characters in a Knowledge document name. #5272

Open microaijp opened 3 weeks ago

microaijp commented 3 weeks ago

Self Checks

Dify version

0.6.11

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

curl --location --request POST 'https://xxxxxxxxxx/v1/datasets/ca90acc9-2ead-490b-bd38-63254425db10/document/create_by_text' \
--header 'Authorization: Bearer dataset-XXXXXXXXXXXXXX' \
--header 'Content-Type: application/json' \
--data-raw '{"name": "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012","text": "--","indexing_technique": "high_quality","process_rule": {"mode": "automatic"}}'
{"message": "Internal Server Error", "code": "unknown"}

This may be a bit of a special use, but I specify JSON for the Knowledge document name, decode the context file name as JSON when answering, and include that information in the answer. This may result in longer document names.

We checked and found that an Internal Server Error occurred if the document name was longer than 252 characters. This is a special use case, but it is very useful, and we hope that it will be possible to make the names as long as possible.

✔️ Expected Behavior

Errors other than Internal Server Error occur and over character error messages are displayed.

❌ Actual Behavior

Internal Server Error

dosubot[bot] commented 3 weeks ago

The issue you're encountering is due to a database constraint that limits the length of the Knowledge document name. Specifically, the name field in the Tag table is defined as db.String(255), which limits the length to 255 characters [1].

To address this issue, you can consider the following steps:

  1. Update the Database Schema: Modify the schema to increase the length of the name field if necessary. This involves altering the column definition in the database migration files.

  2. Input Validation: Implement input validation to ensure that the document name does not exceed the allowed length. This can be done in the API request handling logic to provide a more user-friendly error message instead of an internal server error.

  3. Configuration Parameters: Check if there are any configuration parameters or environment variables that influence the maximum length of document names and adjust them accordingly [2].

By following these steps, you can prevent internal server errors and provide appropriate feedback to users when the document name exceeds the allowed length.

To continue talking to Dosu, mention @dosu.