Failed to save knowledge base
Self Checks
- [x] This is only for bug report, if you would like to ask a question, please head to Discussions.
- [x] I have searched for existing issues search for existing issues, including closed ones.
- [x] I confirm that I am using English to submit this report (我已阅读并同意 Language Policy).
- [x] [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
- [x] Please do not modify this template :) and fill in all the required fields.
Dify version
1.0.0
Cloud or Self Hosted
Self Hosted (Docker)
Steps to reproduce
When I create a new knowledge base, an error occurs when saving. The error log is as follows:
This problem was solved by modifying the length of the corresponding field in the data.
✔️ Expected Behavior
No response
❌ Actual Behavior
No response
@suxinshuo Hello! I'm here to help you with any bugs, questions, or contributions. Let's work together to solve the issue you're facing.
The error you're encountering is a StringDataRightTruncation error in SQLAlchemy, which occurs when a string value exceeds the allowed length for a column. In your case, it seems to be related to the provider_name column in the dataset_collection_bindings table, which has a maximum length of 40 characters [1].
To resolve this issue, you can increase the column length in the database. Here are the steps you can follow:
-
Connect to the Docker database container:
docker exec -it docker-db-1 bash -
Connect to the Dify database:
psql -d dify -
Alter the column length:
ALTER TABLE dataset_collection_bindings ALTER COLUMN provider_name TYPE VARCHAR(255); -
Verify the change with:
\d dataset_collection_bindings;
This should resolve the error by allowing longer strings to be stored in the provider_name column [2].
To continue talking to Dosu, mention @dosu.
Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Bug Report | Other
The same error occurred while debugging the local plugin 本地插件调试时发生了相同错误
2025-03-03 17:33:00 2025-03-03 09:33:00.893 ERROR [Dummy-28] [app.py:875] - Exception on /console/api/datasets/init [POST]
2025-03-03 17:33:00 Traceback (most recent call last):
2025-03-03 17:33:00 File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/engine/base.py", line 1967, in _exec_single_context
2025-03-03 17:33:00 self.dialect.do_execute(
2025-03-03 17:33:00 File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/engine/default.py", line 941, in do_execute
2025-03-03 17:33:00 cursor.execute(statement, parameters)
2025-03-03 17:33:00 psycopg2.errors.StringDataRightTruncation: value too long for type character varying(40)
2025-03-03 17:33:00
2025-03-03 17:33:00
2025-03-03 17:33:00 The above exception was the direct cause of the following exception:
2025-03-03 17:33:00
2025-03-03 17:33:00 Traceback (most recent call last):
2025-03-03 17:33:00 File "/app/api/.venv/lib/python3.12/site-packages/flask/app.py", line 917, in full_dispatch_request
2025-03-03 17:33:00 rv = self.dispatch_request()
2025-03-03 17:33:00 ^^^^^^^^^^^^^^^^^^^^^^^
2025-03-03 17:33:00 File "/app/api/.venv/lib/python3.12/site-packages/flask/app.py", line 902, in dispatch_request
2025-03-03 17:33:00 return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args) # type: ignore[no-any-return]
2025-03-03 17:33:00 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2025-03-03 17:33:00 File "/app/api/.venv/lib/python3.12/site-packages/flask_restful/__init__.py", line 489, in wrapper
2025-03-03 17:33:00 resp = resource(*args, **kwargs)
2025-03-03 17:33:00 ^^^^^^^^^^^^^^^^^^^^^^^^^
2025-03-03 17:33:00 File "/app/api/.venv/lib/python3.12/site-packages/flask/views.py", line 110, in view
2025-03-03 17:33:00 return current_app.ensure_sync(self.dispatch_request)(**kwargs) # type: ignore[no-any-return]
2025-03-03 17:33:00 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2025-03-03 17:33:00 File "/app/api/.venv/lib/python3.12/site-packages/flask_restful/__init__.py", line 604, in dispatch_request
2025-03-03 17:33:00 resp = meth(*args, **kwargs)
2025-03-03 17:33:00 ^^^^^^^^^^^^^^^^^^^^^
2025-03-03 17:33:00 File "/app/api/controllers/console/wraps.py", line 147, in decorated
2025-03-03 17:33:00 return view(*args, **kwargs)
2025-03-03 17:33:00 ^^^^^^^^^^^^^^^^^^^^^
2025-03-03 17:33:00 File "/app/api/libs/login.py", line 94, in decorated_view
2025-03-03 17:33:00 return current_app.ensure_sync(func)(*args, **kwargs)
2025-03-03 17:33:00 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2025-03-03 17:33:00 File "/app/api/controllers/console/wraps.py", line 27, in decorated
2025-03-03 17:33:00 return view(*args, **kwargs)
2025-03-03 17:33:00 ^^^^^^^^^^^^^^^^^^^^^
2025-03-03 17:33:00 File "/app/api/.venv/lib/python3.12/site-packages/flask_restful/__init__.py", line 696, in wrapper
2025-03-03 17:33:00 resp = f(*args, **kwargs)
2025-03-03 17:33:00 ^^^^^^^^^^^^^^^^^^
2025-03-03 17:33:00 File "/app/api/controllers/console/wraps.py", line 86, in decorated
2025-03-03 17:33:00 return view(*args, **kwargs)
2025-03-03 17:33:00 ^^^^^^^^^^^^^^^^^^^^^
2025-03-03 17:33:00 File "/app/api/controllers/console/datasets/datasets_document.py", line 374, in post
2025-03-03 17:33:00 dataset, documents, batch = DocumentService.save_document_without_dataset_id(
2025-03-03 17:33:00 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2025-03-03 17:33:00 File "/app/api/services/dataset_service.py", line 1257, in save_document_without_dataset_id
2025-03-03 17:33:00 dataset_collection_binding = DatasetCollectionBindingService.get_dataset_collection_binding(
2025-03-03 17:33:00 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2025-03-03 17:33:00 File "/app/api/services/dataset_service.py", line 2085, in get_dataset_collection_binding
2025-03-03 17:33:00 db.session.commit()
2025-03-03 17:33:00 File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/orm/scoping.py", line 597, in commit
2025-03-03 17:33:00 return self._proxied.commit()
2025-03-03 17:33:00 ^^^^^^^^^^^^^^^^^^^^^^
2025-03-03 17:33:00 File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/orm/session.py", line 2028, in commit
2025-03-03 17:33:00 trans.commit(_to_root=True)
2025-03-03 17:33:00 File "<string>", line 2, in commit
2025-03-03 17:33:00 File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/orm/state_changes.py", line 139, in _go
2025-03-03 17:33:00 ret_value = fn(self, *arg, **kw)
2025-03-03 17:33:00 ^^^^^^^^^^^^^^^^^^^^
2025-03-03 17:33:00 File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/orm/session.py", line 1313, in commit
2025-03-03 17:33:00 self._prepare_impl()
2025-03-03 17:33:00 File "<string>", line 2, in _prepare_impl
2025-03-03 17:33:00 File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/orm/state_changes.py", line 139, in _go
2025-03-03 17:33:00 ret_value = fn(self, *arg, **kw)
2025-03-03 17:33:00 ^^^^^^^^^^^^^^^^^^^^
2025-03-03 17:33:00 File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/orm/session.py", line 1288, in _prepare_impl
2025-03-03 17:33:00 self.session.flush()
2025-03-03 17:33:00 File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/orm/session.py", line 4352, in flush
2025-03-03 17:33:00 self._flush(objects)
2025-03-03 17:33:00 File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/orm/session.py", line 4487, in _flush
2025-03-03 17:33:00 with util.safe_reraise():
2025-03-03 17:33:00 ^^^^^^^^^^^^^^^^^^^
2025-03-03 17:33:00 File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/util/langhelpers.py", line 146, in __exit__
2025-03-03 17:33:00 raise exc_value.with_traceback(exc_tb)
2025-03-03 17:33:00 File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/orm/session.py", line 4448, in _flush
2025-03-03 17:33:00 flush_context.execute()
2025-03-03 17:33:00 File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/orm/unitofwork.py", line 466, in execute
2025-03-03 17:33:00 rec.execute(self)
2025-03-03 17:33:00 File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/orm/unitofwork.py", line 642, in execute
2025-03-03 17:33:00 util.preloaded.orm_persistence.save_obj(
2025-03-03 17:33:00 File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/orm/persistence.py", line 93, in save_obj
2025-03-03 17:33:00 _emit_insert_statements(
2025-03-03 17:33:00 File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/orm/persistence.py", line 1233, in _emit_insert_statements
2025-03-03 17:33:00 result = connection.execute(
2025-03-03 17:33:00 ^^^^^^^^^^^^^^^^^^^
2025-03-03 17:33:00 File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/engine/base.py", line 1418, in execute
2025-03-03 17:33:00 return meth(
2025-03-03 17:33:00 ^^^^^
2025-03-03 17:33:00 File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/sql/elements.py", line 515, in _execute_on_connection
2025-03-03 17:33:00 return connection._execute_clauseelement(
2025-03-03 17:33:00 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2025-03-03 17:33:00 File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/engine/base.py", line 1640, in _execute_clauseelement
2025-03-03 17:33:00 ret = self._execute_context(
2025-03-03 17:33:00 ^^^^^^^^^^^^^^^^^^^^^^
2025-03-03 17:33:00 File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/engine/base.py", line 1846, in _execute_context
2025-03-03 17:33:00 return self._exec_single_context(
2025-03-03 17:33:00 ^^^^^^^^^^^^^^^^^^^^^^^^^^
2025-03-03 17:33:00 File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/engine/base.py", line 1986, in _exec_single_context
2025-03-03 17:33:00 self._handle_dbapi_exception(
2025-03-03 17:33:00 File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/engine/base.py", line 2355, in _handle_dbapi_exception
2025-03-03 17:33:00 raise sqlalchemy_exception.with_traceback(exc_info[2]) from e
2025-03-03 17:33:00 File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/engine/base.py", line 1967, in _exec_single_context
2025-03-03 17:33:00 self.dialect.do_execute(
2025-03-03 17:33:00 File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/engine/default.py", line 941, in do_execute
2025-03-03 17:33:00 cursor.execute(statement, parameters)
2025-03-03 17:33:00 sqlalchemy.exc.DataError: (psycopg2.errors.StringDataRightTruncation) value too long for type character varying(40)
2025-03-03 17:33:00
2025-03-03 17:33:00 [SQL: INSERT INTO dataset_collection_bindings (provider_name, model_name, type, collection_name) VALUES (%(provider_name)s, %(model_name)s, %(type)s, %(collection_name)s) RETURNING dataset_collection_bindings.id, dataset_collection_bindings.created_at]
2025-03-03 17:33:00 [parameters: {'provider_name': 'cf5cab9c-344b-40cc-8cff-6e4b03841b8c/baidu_qianfan/baidu_qianfan', 'model_name': 'bge-large-zh', 'type': 'dataset', 'collection_name': 'Vector_index_c03ea74f_4dc7_47ec_a291_0cd183092f55_Node'}]
2025-03-03 17:33:00 (Background on this error at: https://sqlalche.me/e/20/9h9h)
I found the same problem when deploying the embedding model locally in TEI "sqlalchemy.exc.DataError: (psycopg2.errors.StringDataRightTruncation) value too long for type character varying(40)"
@crazywoola Please take a look
db-1 | 2025-03-04 02:07:44.452 UTC [391257] ERROR: value too long for type character varying(40)
db-1 | 2025-03-04 02:07:44.452 UTC [391257] STATEMENT: INSERT INTO dataset_collection_bindings (provider_name, model_name, type, collection_name) VALUES ('langgenius/huggingface_tei/huggingface_tei', 'text-embeddings-router --model-id /home/text-embeddings-inference/models/gte-Qwen2-1.5B-instruct', 'dataset', 'Vector_index_9f2c49ca_e5fa_4f12_bf4a_e9f664abd3e1_Node') RETURNING dataset_collection_bindings.id, dataset_collection_bindings.created_at
api-1 | 2025-03-04 02:07:44.453 ERROR [Dummy-413] [app.py:875] - Exception on /console/api/datasets/cca5160c-f890-4eac-a2aa-4419f22d311a [PATCH]
api-1 | Traceback (most recent call last):
nginx-1 | 10.147.145.56 - - [04/Mar/2025:02:07:44 +0000] "PATCH /console/api/datasets/cca5160c-f890-4eac-a2aa-4419f22d311a HTTP/1.1" 500 56 "http://10.147.11.21/datasets/cca5160c-f890-4eac-a2aa-4419f22d311a/settings" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36 Edg/133.0.0.0" "-"
api-1 | File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/engine/base.py", line 1967, in _exec_single_context
api-1 | self.dialect.do_execute(
api-1 | File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/engine/default.py", line 941, in do_execute
api-1 | cursor.execute(statement, parameters)
api-1 | psycopg2.errors.StringDataRightTruncation: value too long for type character varying(40)
api-1 |
api-1 |
api-1 | The above exception was the direct cause of the following exception:
api-1 |
api-1 | Traceback (most recent call last):
api-1 | File "/app/api/.venv/lib/python3.12/site-packages/flask/app.py", line 917, in full_dispatch_request
api-1 | rv = self.dispatch_request()
api-1 | ^^^^^^^^^^^^^^^^^^^^^^^
api-1 | File "/app/api/.venv/lib/python3.12/site-packages/flask/app.py", line 902, in dispatch_request
api-1 | return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args) # type: ignore[no-any-return]
api-1 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
api-1 | File "/app/api/.venv/lib/python3.12/site-packages/flask_restful/__init__.py", line 489, in wrapper
api-1 | resp = resource(*args, **kwargs)
api-1 | ^^^^^^^^^^^^^^^^^^^^^^^^^
api-1 | File "/app/api/.venv/lib/python3.12/site-packages/flask/views.py", line 110, in view
api-1 | return current_app.ensure_sync(self.dispatch_request)(**kwargs) # type: ignore[no-any-return]
api-1 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
api-1 | File "/app/api/.venv/lib/python3.12/site-packages/flask_restful/__init__.py", line 604, in dispatch_request
api-1 | resp = meth(*args, **kwargs)
api-1 | ^^^^^^^^^^^^^^^^^^^^^
api-1 | File "/app/api/controllers/console/wraps.py", line 147, in decorated
api-1 | return view(*args, **kwargs)
api-1 | ^^^^^^^^^^^^^^^^^^^^^
api-1 | File "/app/api/libs/login.py", line 94, in decorated_view
api-1 | return current_app.ensure_sync(func)(*args, **kwargs)
api-1 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
api-1 | File "/app/api/controllers/console/wraps.py", line 27, in decorated
api-1 | return view(*args, **kwargs)
api-1 | ^^^^^^^^^^^^^^^^^^^^^
api-1 | File "/app/api/controllers/console/datasets/datasets.py", line 289, in patch
api-1 | dataset = DatasetService.update_dataset(dataset_id_str, args, current_user)
api-1 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
api-1 | File "/app/api/services/dataset_service.py", line 351, in update_dataset
api-1 | dataset_collection_binding = DatasetCollectionBindingService.get_dataset_collection_binding(
api-1 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
api-1 | File "/app/api/services/dataset_service.py", line 2085, in get_dataset_collection_binding
api-1 | db.session.commit()
api-1 | File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/orm/scoping.py", line 597, in commit
api-1 | return self._proxied.commit()
api-1 | ^^^^^^^^^^^^^^^^^^^^^^
api-1 | File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/orm/session.py", line 2028, in commit
api-1 | trans.commit(_to_root=True)
api-1 | File "<string>", line 2, in commit
api-1 | File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/orm/state_changes.py", line 139, in _go
api-1 | ret_value = fn(self, *arg, **kw)
api-1 | ^^^^^^^^^^^^^^^^^^^^
api-1 | File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/orm/session.py", line 1313, in commit
api-1 | self._prepare_impl()
api-1 | File "<string>", line 2, in _prepare_impl
api-1 | File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/orm/state_changes.py", line 139, in _go
api-1 | ret_value = fn(self, *arg, **kw)
api-1 | ^^^^^^^^^^^^^^^^^^^^
api-1 | File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/orm/session.py", line 1288, in _prepare_impl
api-1 | self.session.flush()
api-1 | File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/orm/session.py", line 4352, in flush
api-1 | self._flush(objects)
api-1 | File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/orm/session.py", line 4487, in _flush
api-1 | with util.safe_reraise():
api-1 | ^^^^^^^^^^^^^^^^^^^
api-1 | File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/util/langhelpers.py", line 146, in __exit__
api-1 | raise exc_value.with_traceback(exc_tb)
api-1 | File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/orm/session.py", line 4448, in _flush
api-1 | flush_context.execute()
api-1 | File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/orm/unitofwork.py", line 466, in execute
api-1 | rec.execute(self)
api-1 | File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/orm/unitofwork.py", line 642, in execute
api-1 | util.preloaded.orm_persistence.save_obj(
api-1 | File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/orm/persistence.py", line 93, in save_obj
api-1 | _emit_insert_statements(
api-1 | File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/orm/persistence.py", line 1233, in _emit_insert_statements
api-1 | result = connection.execute(
api-1 | ^^^^^^^^^^^^^^^^^^^
api-1 | File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/engine/base.py", line 1418, in execute
api-1 | return meth(
api-1 | ^^^^^
api-1 | File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/sql/elements.py", line 515, in _execute_on_connection
api-1 | return connection._execute_clauseelement(
api-1 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
api-1 | File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/engine/base.py", line 1640, in _execute_clauseelement
api-1 | ret = self._execute_context(
api-1 | ^^^^^^^^^^^^^^^^^^^^^^
api-1 | File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/engine/base.py", line 1846, in _execute_context
api-1 | return self._exec_single_context(
api-1 | ^^^^^^^^^^^^^^^^^^^^^^^^^^
api-1 | File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/engine/base.py", line 1986, in _exec_single_context
api-1 | self._handle_dbapi_exception(
api-1 | File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/engine/base.py", line 2355, in _handle_dbapi_exception
api-1 | raise sqlalchemy_exception.with_traceback(exc_info[2]) from e
api-1 | File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/engine/base.py", line 1967, in _exec_single_context
api-1 | self.dialect.do_execute(
api-1 | File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/engine/default.py", line 941, in do_execute
api-1 | cursor.execute(statement, parameters)
api-1 | sqlalchemy.exc.DataError: (psycopg2.errors.StringDataRightTruncation) value too long for type character varying(40)
api-1 |
api-1 | [SQL: INSERT INTO dataset_collection_bindings (provider_name, model_name, type, collection_name) VALUES (%(provider_name)s, %(model_name)s, %(type)s, %(collection_name)s) RETURNING dataset_collection_bindings.id, dataset_collection_bindings.created_at]
api-1 | [parameters: {'provider_name': 'langgenius/huggingface_tei/huggingface_tei', 'model_name': 'text-embeddings-router --model-id /home/text-embeddings-inference/models/gte-Qwen2-1.5B-instruct', 'type': 'dataset', 'collection_name': 'Vector_index_9f2c49ca_e5fa_4f12_bf4a_e9f664abd3e1_Node'}]
api-1 | (Background on this error at: https://sqlalche.me/e/20/9h9h)
Fixed in this PR fix: (psycopg2.errors.StringDataRightTruncation) value too long for type character varying(40) Fixes #14593 (#14597)