diff --git a/haystack/document_store/sql.py b/haystack/document_store/sql.py index 62243ffb3..7878b92ae 100644 --- a/haystack/document_store/sql.py +++ b/haystack/document_store/sql.py @@ -74,7 +74,8 @@ class SQLDocumentStore(BaseDocumentStore): url: str = "sqlite://", index: str = "document", label_index: str = "label", - duplicate_documents: str = "overwrite" + duplicate_documents: str = "overwrite", + check_same_thread: bool = False ): """ An SQL backed DocumentStore. Currently supports SQLite, PostgreSQL and MySQL backends. @@ -89,14 +90,15 @@ class SQLDocumentStore(BaseDocumentStore): overwrite: Update any existing documents with the same ID when adding documents. fail: an error is raised if the document ID of the document being added already exists. + :param check_same_thread: Set to False to mitigate multithreading issues in older SQLite versions (see https://docs.sqlalchemy.org/en/14/dialects/sqlite.html?highlight=check_same_thread#threading-pooling-behavior) """ # save init parameters to enable export of component config as YAML self.set_config( - url=url, index=index, label_index=label_index, duplicate_documents=duplicate_documents + url=url, index=index, label_index=label_index, duplicate_documents=duplicate_documents, check_same_thread=check_same_thread ) - engine = create_engine(url) + engine = create_engine(url,connect_args={'check_same_thread': check_same_thread}) ORMBase.metadata.create_all(engine) Session = sessionmaker(bind=engine) self.session = Session()