The conversation_var can't store long texts. #5061

Closed
opened 2026-02-21 18:09:12 -05:00 by yindo · 4 comments
Owner

Originally created by @Lsyyy0828 on GitHub (Aug 15, 2024).

Self Checks

  • This is only for bug report, if you would like to ask a question, please head to Discussions.
  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report (我已阅读并同意 Language Policy).
  • [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
  • Please do not modify this template :) and fill in all the required fields.

Dify version

0.7.0

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

conversation_var cannot store long texts.

I stored the text of an article in conversation_var, and an internal error occurred. When I tested shorter documents, conversation_var was stored and used well, but when the text content became longer, a crash would definitely occur.

Arc 2024-08-15 22 43 09 Arc 2024-08-15 22 55 26 Arc 2024-08-15 22 55 37

When I store shorter texts, the conversation_var works properly, and I'm sure there's no issue with the logic of my workflow.

✔️ Expected Behavior

The conversation_var is used and read normally.

Actual Behavior

The entire workflow crashed, and no further conversation can proceed. Checking conversation_var, there is nothing stored inside. If the text content is shortened, it can be stored normally.

Originally created by @Lsyyy0828 on GitHub (Aug 15, 2024). ### Self Checks - [X] This is only for bug report, if you would like to ask a question, please head to [Discussions](https://github.com/langgenius/dify/discussions/categories/general). - [X] I have searched for existing issues [search for existing issues](https://github.com/langgenius/dify/issues), including closed ones. - [X] I confirm that I am using English to submit this report (我已阅读并同意 [Language Policy](https://github.com/langgenius/dify/issues/1542)). - [X] [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:) - [X] Please do not modify this template :) and fill in all the required fields. ### Dify version 0.7.0 ### Cloud or Self Hosted Self Hosted (Docker) ### Steps to reproduce `conversation_var` cannot store long texts. I stored the text of an article in `conversation_var`, and an **internal error** occurred. When I tested shorter documents, `conversation_var` was stored and used well, but when the text content became longer, a crash would definitely occur. <img width="500" alt="Arc 2024-08-15 22 43 09" src="https://github.com/user-attachments/assets/099a0818-9087-4f4b-9fed-09290a6d208b"> <img width="318" alt="Arc 2024-08-15 22 55 26" src="https://github.com/user-attachments/assets/15ef28e1-07d1-433a-baa4-408ffbf2dd66"> <img width="594" alt="Arc 2024-08-15 22 55 37" src="https://github.com/user-attachments/assets/310f606e-311c-499e-b6bc-b50b516e9c6e"> When I store shorter texts, the `conversation_var` works properly, and I'm sure there's no issue with the logic of my workflow. ### ✔️ Expected Behavior The `conversation_var` is used and read normally. ### ❌ Actual Behavior The entire workflow crashed, and no further conversation can proceed. Checking `conversation_var`, there is nothing stored inside. If the text content is shortened, it can be stored normally.
yindo added the 🐞 bug label 2026-02-21 18:09:12 -05:00
yindo closed this issue 2026-02-21 18:09:12 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Aug 15, 2024):

Hey @Lsyyy0828, I'm here to help you with bugs, questions, and becoming a contributor. Let's squash those bugs together! 🐞

To resolve the issue where conversation_var in Dify version 0.7.0, self-hosted using Docker, cannot store long texts and causes an internal error, you can try the following steps:

  1. Lower the value of "Max token" in the parameter settings of the Prompt Eng:

    Query or prefix prompt is too long, you can reduce the prefix prompt, or shrink the max token, or switch to a llm with a larger token limit size
    
  2. Split long text data into smaller units:

    In some natural language processing applications, text is often split into paragraphs or sentences for better processing and understanding of semantic and structural information in the text. The minimum splitting unit depends on the specific task and technical implementation.
    

By reducing the max token value and splitting long texts into smaller units, you can mitigate the internal error caused by storing long texts in conversation_var [1].

Additionally, the maximum token limit for conversation_var is determined by the model being used. For models gpt-4 and gpt-3.5-turbo-16k, the limit is 8000 tokens, and for other models, it is 4000 tokens [2].

To continue talking to Dosu, mention @dosu.

@dosubot[bot] commented on GitHub (Aug 15, 2024): <!-- Greeting --> Hey @Lsyyy0828, I'm here to help you with bugs, questions, and becoming a contributor. Let's squash those bugs together! 🐞 <!-- Answer --> To resolve the issue where `conversation_var` in Dify version 0.7.0, self-hosted using Docker, cannot store long texts and causes an internal error, you can try the following steps: 1. **Lower the value of "Max token" in the parameter settings of the Prompt Eng**: ```json Query or prefix prompt is too long, you can reduce the prefix prompt, or shrink the max token, or switch to a llm with a larger token limit size ``` 2. **Split long text data into smaller units**: ```md In some natural language processing applications, text is often split into paragraphs or sentences for better processing and understanding of semantic and structural information in the text. The minimum splitting unit depends on the specific task and technical implementation. ``` By reducing the max token value and splitting long texts into smaller units, you can mitigate the internal error caused by storing long texts in `conversation_var` <sup>[[1]](https://github.com/langgenius/dify-docs/blob/main/en/guides/application-orchestrate/llms-use-faq.md)</sup>. Additionally, the maximum token limit for `conversation_var` is determined by the model being used. For models `gpt-4` and `gpt-3.5-turbo-16k`, the limit is 8000 tokens, and for other models, it is 4000 tokens <sup>[[2]](https://github.com/langgenius/dify/blob/main/web/config/index.ts)</sup>. <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://dosu.dev), mention @dosu.*
Author
Owner

@crazywoola commented on GitHub (Aug 15, 2024):

Please provide the container logs of this error, I checked the code, it's already set to db.TEXT

https://github.com/langgenius/dify/blob/935e72d4495530d7ee8725718c19655591582cb1/api/models/workflow.py#L732

@crazywoola commented on GitHub (Aug 15, 2024): Please provide the container logs of this error, I checked the code, it's already set to `db.TEXT` https://github.com/langgenius/dify/blob/935e72d4495530d7ee8725718c19655591582cb1/api/models/workflow.py#L732
Author
Owner

@Lsyyy0828 commented on GitHub (Aug 15, 2024):

Please provide the container logs of this error, I checked the code, it's already set to db.TEXT

https://github.com/langgenius/dify/blob/935e72d4495530d7ee8725718c19655591582cb1/api/models/workflow.py#L732

[on_tool_start] ToolCall:parse
{'content': '{"text":"The text related to copyright issues and I remove them .","filename":"æ\x9cºå\x99¨ç¿»è¯\x91ä¸\x8e人工翻è¯\x91ç\x9a\x84æ¯\x94è¾\x83-以-å\x8c\x97é£\x8e-ä��ºä¾\x8b.pdf"}', 'json_filter': '"text"'}

[on_tool_end]
Tool: parse
Inputs: {'ensure_ascii': False, 'content': '{"text":"The text related to copyright issues and I remove them","filename":"æ\x9cºå\x99¨ç¿»è¯\x91ä¸\x8e人工翻è¯\x91ç\x9a\x84æ¯\x94è¾\x83-以-å\x8c\x97é£\x8e-为ä¾\x8b.pdf"}', 'json_filter': '"text"'}
Outputs: [ToolInvokeMessage(type=<MessageType.TEXT: 'text'>, message='The text related to copyright issues and I remove them"}\n', 'json_filter': '"文本内容"'}
2024-08-15 15:18:24,265.265 INFO [Thread-265 (_generate_worker)] [_client.py:1026] - HTTP Request: POST http://sandbox:8194/v1/sandbox/run "HTTP/1.1 200 OK"
2024-08-15 15:18:40,248.248 ERROR [Dummy-270] [app.py:838] - Exception on /console/api/apps/14512c4f-0c6b-434c-8f2f-b1e943b5dbee/conversation-variables [GET]
Traceback (most recent call last):
  File "/app/api/.venv/lib/python3.10/site-packages/flask/app.py", line 880, in full_dispatch_request
    rv = self.dispatch_request()
  File "/app/api/.venv/lib/python3.10/site-packages/flask/app.py", line 865, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)  # type: ignore[no-any-return]
  File "/app/api/.venv/lib/python3.10/site-packages/flask_restful/__init__.py", line 489, in wrapper
    resp = resource(*args, **kwargs)
  File "/app/api/.venv/lib/python3.10/site-packages/flask/views.py", line 110, in view
    return current_app.ensure_sync(self.dispatch_request)(**kwargs)  # type: ignore[no-any-return]
  File "/app/api/.venv/lib/python3.10/site-packages/flask_restful/__init__.py", line 604, in dispatch_request
    resp = meth(*args, **kwargs)
  File "/app/api/controllers/console/setup.py", line 75, in decorated
    return view(*args, **kwargs)
  File "/app/api/libs/login.py", line 91, in decorated_view
    return current_app.ensure_sync(func)(*args, **kwargs)
  File "/app/api/controllers/console/wraps.py", line 22, in decorated
    return view(*args, **kwargs)
  File "/app/api/controllers/console/app/wraps.py", line 49, in decorated_view
    return view_func(*args, **kwargs)
  File "/app/api/.venv/lib/python3.10/site-packages/flask_restful/__init__.py", line 696, in wrapper
    resp = f(*args, **kwargs)
  File "/app/api/controllers/console/app/conversation_variables.py", line 50, in get
    'data': [
  File "/app/api/controllers/console/app/conversation_variables.py", line 54, in <listcomp>
    **row.to_variable().model_dump(),
  File "/app/api/models/workflow.py", line 754, in to_variable
    return factory.build_variable_from_mapping(mapping)
  File "/app/api/core/app/segments/factory.py", line 69, in build_variable_from_mapping
    raise VariableError(f'variable size {result.size} exceeds limit {dify_config.MAX_VARIABLE_SIZE}')
core.app.segments.exc.VariableError: variable size 15190 exceeds limit 5120
2024-08-15 15:18:45,332.332 ERROR [Thread-271 (_generate_worker)] [app_generator.py:312] - Unknown Error when generating
Traceback (most recent call last):
  File "/app/api/core/app/apps/advanced_chat/app_generator.py", line 291, in _generate_worker
    runner.run(
  File "/app/api/core/app/apps/advanced_chat/app_runner.py", line 122, in run
    conversation_variables = [item.to_variable() for item in conversation_variables]
  File "/app/api/core/app/apps/advanced_chat/app_runner.py", line 122, in <listcomp>
    conversation_variables = [item.to_variable() for item in conversation_variables]
  File "/app/api/models/workflow.py", line 754, in to_variable
    return factory.build_variable_from_mapping(mapping)
  File "/app/api/core/app/segments/factory.py", line 69, in build_variable_from_mapping
    raise VariableError(f'variable size {result.size} exceeds limit {dify_config.MAX_VARIABLE_SIZE}')
core.app.segments.exc.VariableError: variable size 15190 exceeds limit 5120
2024-08-15 15:18:45,351.351 ERROR [Dummy-272] [base_app_generate_response_converter.py:125] - variable size 15190 exceeds limit 5120
@Lsyyy0828 commented on GitHub (Aug 15, 2024): > Please provide the container logs of this error, I checked the code, it's already set to `db.TEXT` > > https://github.com/langgenius/dify/blob/935e72d4495530d7ee8725718c19655591582cb1/api/models/workflow.py#L732 ``` [on_tool_start] ToolCall:parse {'content': '{"text":"The text related to copyright issues and I remove them .","filename":"æ\x9cºå\x99¨ç¿»è¯\x91ä¸\x8e人工翻è¯\x91ç\x9a\x84æ¯\x94è¾\x83-以-å\x8c\x97é£\x8e-ä��ºä¾\x8b.pdf"}', 'json_filter': '"text"'} [on_tool_end] Tool: parse Inputs: {'ensure_ascii': False, 'content': '{"text":"The text related to copyright issues and I remove them","filename":"æ\x9cºå\x99¨ç¿»è¯\x91ä¸\x8e人工翻è¯\x91ç\x9a\x84æ¯\x94è¾\x83-以-å\x8c\x97é£\x8e-为ä¾\x8b.pdf"}', 'json_filter': '"text"'} Outputs: [ToolInvokeMessage(type=<MessageType.TEXT: 'text'>, message='The text related to copyright issues and I remove them"}\n', 'json_filter': '"文本内容"'} 2024-08-15 15:18:24,265.265 INFO [Thread-265 (_generate_worker)] [_client.py:1026] - HTTP Request: POST http://sandbox:8194/v1/sandbox/run "HTTP/1.1 200 OK" 2024-08-15 15:18:40,248.248 ERROR [Dummy-270] [app.py:838] - Exception on /console/api/apps/14512c4f-0c6b-434c-8f2f-b1e943b5dbee/conversation-variables [GET] Traceback (most recent call last): File "/app/api/.venv/lib/python3.10/site-packages/flask/app.py", line 880, in full_dispatch_request rv = self.dispatch_request() File "/app/api/.venv/lib/python3.10/site-packages/flask/app.py", line 865, in dispatch_request return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args) # type: ignore[no-any-return] File "/app/api/.venv/lib/python3.10/site-packages/flask_restful/__init__.py", line 489, in wrapper resp = resource(*args, **kwargs) File "/app/api/.venv/lib/python3.10/site-packages/flask/views.py", line 110, in view return current_app.ensure_sync(self.dispatch_request)(**kwargs) # type: ignore[no-any-return] File "/app/api/.venv/lib/python3.10/site-packages/flask_restful/__init__.py", line 604, in dispatch_request resp = meth(*args, **kwargs) File "/app/api/controllers/console/setup.py", line 75, in decorated return view(*args, **kwargs) File "/app/api/libs/login.py", line 91, in decorated_view return current_app.ensure_sync(func)(*args, **kwargs) File "/app/api/controllers/console/wraps.py", line 22, in decorated return view(*args, **kwargs) File "/app/api/controllers/console/app/wraps.py", line 49, in decorated_view return view_func(*args, **kwargs) File "/app/api/.venv/lib/python3.10/site-packages/flask_restful/__init__.py", line 696, in wrapper resp = f(*args, **kwargs) File "/app/api/controllers/console/app/conversation_variables.py", line 50, in get 'data': [ File "/app/api/controllers/console/app/conversation_variables.py", line 54, in <listcomp> **row.to_variable().model_dump(), File "/app/api/models/workflow.py", line 754, in to_variable return factory.build_variable_from_mapping(mapping) File "/app/api/core/app/segments/factory.py", line 69, in build_variable_from_mapping raise VariableError(f'variable size {result.size} exceeds limit {dify_config.MAX_VARIABLE_SIZE}') core.app.segments.exc.VariableError: variable size 15190 exceeds limit 5120 2024-08-15 15:18:45,332.332 ERROR [Thread-271 (_generate_worker)] [app_generator.py:312] - Unknown Error when generating Traceback (most recent call last): File "/app/api/core/app/apps/advanced_chat/app_generator.py", line 291, in _generate_worker runner.run( File "/app/api/core/app/apps/advanced_chat/app_runner.py", line 122, in run conversation_variables = [item.to_variable() for item in conversation_variables] File "/app/api/core/app/apps/advanced_chat/app_runner.py", line 122, in <listcomp> conversation_variables = [item.to_variable() for item in conversation_variables] File "/app/api/models/workflow.py", line 754, in to_variable return factory.build_variable_from_mapping(mapping) File "/app/api/core/app/segments/factory.py", line 69, in build_variable_from_mapping raise VariableError(f'variable size {result.size} exceeds limit {dify_config.MAX_VARIABLE_SIZE}') core.app.segments.exc.VariableError: variable size 15190 exceeds limit 5120 2024-08-15 15:18:45,351.351 ERROR [Dummy-272] [base_app_generate_response_converter.py:125] - variable size 15190 exceeds limit 5120 ```
Author
Owner

@crazywoola commented on GitHub (Aug 28, 2024):

raise VariableError(f'variable size {result.size} exceeds limit {dify_config.MAX_VARIABLE_SIZE}')

I guess you could set this MAX_VARIABLE_SIZE in environment variables.

@crazywoola commented on GitHub (Aug 28, 2024): `raise VariableError(f'variable size {result.size} exceeds limit {dify_config.MAX_VARIABLE_SIZE}')` I guess you could set this `MAX_VARIABLE_SIZE` in environment variables.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#5061