deepset-ai / haystack

:mag: AI orchestration framework to build customizable, production-ready LLM applications. Connect components (models, vector DBs, file converters) to pipelines or agents that can interact with your data. With advanced retrieval methods, it's best suited for building RAG, question answering, semantic search or conversational agent chatbots.
https://haystack.deepset.ai
Apache License 2.0
16.81k stars 1.84k forks source link

ImportError: cannot import name 'BaseDocumentStore' from partially initialized module 'haystack.document_stores.base' (most likely due to a circular import) (haystack/haystack/document_stores/base.py) #4234

Closed bhawnapiryani closed 3 months ago

bhawnapiryani commented 1 year ago

Hello,

I installed haystack without any error but when i import it there is two error

First

PermissionError: [Errno 13] Permission denied: '/tmp/tika.log'

i solved it by using import os; os.environ["TIKA_LOG_PATH"] = "/tmp/"

Second

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
Cell In[3], line 1
----> 1 import haystack

File /haystack/haystack/__init__.py:22
     20 from haystack.schema import Document, Answer, Label, MultiLabel, Span, EvaluationResult
     21 from haystack.nodes.base import BaseComponent
---> 22 from haystack.pipelines.base import Pipeline
     23 from haystack.environment import set_pytorch_secure_model_loading
     26 pd.options.display.max_colwidth = 80

File /haystack/haystack/pipelines/__init__.py:1
----> 1 from haystack.pipelines.base import Pipeline, RootNode
      2 from haystack.pipelines.ray import RayPipeline
      3 from haystack.pipelines.standard_pipelines import (
      4     BaseStandardPipeline,
      5     DocumentSearchPipeline,
   (...)
     15     TextIndexingPipeline,
     16 )

File /haystack/haystack/pipelines/base.py:34
     31 from networkx.drawing.nx_agraph import to_agraph
     33 from haystack import __version__
---> 34 from haystack.nodes.evaluator.evaluator import semantic_answer_similarity
     35 from haystack.modeling.evaluation.squad import compute_f1 as calculate_f1_str
     36 from haystack.modeling.evaluation.squad import compute_exact as calculate_em_str

File /haystack/haystack/nodes/__init__.py:5
      1 from haystack.utils.import_utils import safe_import
      3 from haystack.nodes.base import BaseComponent
----> 5 from haystack.nodes.answer_generator import BaseGenerator, RAGenerator, Seq2SeqGenerator, OpenAIAnswerGenerator
      6 from haystack.nodes.document_classifier import BaseDocumentClassifier, TransformersDocumentClassifier
      7 from haystack.nodes.evaluator import EvalDocuments, EvalAnswers

File /haystack/haystack/nodes/answer_generator/__init__.py:4
      1 from haystack.utils.import_utils import safe_import
      3 from haystack.nodes.answer_generator.base import BaseGenerator
----> 4 from haystack.nodes.answer_generator.transformers import RAGenerator, Seq2SeqGenerator
      5 from haystack.nodes.answer_generator.openai import OpenAIAnswerGenerator

File /haystack/haystack/nodes/answer_generator/transformers.py:18
     16 from haystack.schema import Document
     17 from haystack.nodes.answer_generator.base import BaseGenerator
---> 18 from haystack.nodes.retriever.dense import DensePassageRetriever
     19 from haystack.modeling.utils import initialize_device_settings
     22 logger = logging.getLogger(__name__)

File /haystack/haystack/nodes/retriever/__init__.py:1
----> 1 from haystack.nodes.retriever.base import BaseRetriever
      2 from haystack.nodes.retriever.dense import (
      3     DensePassageRetriever,
      4     DenseRetriever,
   (...)
      7     TableTextRetriever,
      8 )
      9 from haystack.nodes.retriever.multimodal import MultiModalRetriever

File /haystack/haystack/nodes/retriever/base.py:13
     11 from haystack.errors import HaystackError, PipelineError
     12 from haystack.nodes.base import BaseComponent
---> 13 from haystack.document_stores.base import BaseDocumentStore, BaseKnowledgeGraph, FilterType
     16 logger = logging.getLogger(__name__)
     19 class BaseGraphRetriever(BaseComponent):

File /haystack/haystack/document_stores/__init__.py:4
      2 import importlib
      3 from haystack.utils.import_utils import safe_import
----> 4 from haystack.document_stores.base import BaseDocumentStore, BaseKnowledgeGraph, KeywordDocumentStore
      6 from haystack.document_stores.memory import InMemoryDocumentStore
      7 from haystack.document_stores.deepsetcloud import DeepsetCloudDocumentStore

File /haystack/haystack/document_stores/base.py:18
     16 from haystack.nodes.preprocessor import PreProcessor
     17 from haystack.document_stores.utils import eval_data_from_json, eval_data_from_jsonl, squad_json_to_jsonl
---> 18 from haystack.utils.labels import aggregate_labels
     21 logger = logging.getLogger(__name__)
     24 try:

File /haystack/haystack/utils/__init__.py:14
      5 from haystack.utils.doc_store import (
      6     launch_es,
      7     launch_milvus,
   (...)
     11     stop_service,
     12 )
     13 from haystack.utils.deepsetcloud import DeepsetCloud, DeepsetCloudError, DeepsetCloudExperiments
---> 14 from haystack.utils.export_utils import (
     15     print_answers,
     16     print_documents,
     17     print_questions,
     18     export_answers_to_csv,
     19     convert_labels_to_squad,
     20 )
     21 from haystack.utils.squad_data import SquadData
     22 from haystack.utils.context_matching import calculate_context_similarity, match_context, match_contexts

File /haystack/haystack/utils/export_utils.py:11
      8 import pandas as pd
     10 from haystack.schema import Document, Answer, SpeechAnswer
---> 11 from haystack.document_stores.sql import DocumentORM
     14 logger = logging.getLogger(__name__)
     17 def print_answers(results: dict, details: str = "all", max_text_len: Optional[int] = None):

File /haystack/haystack/document_stores/sql.py:35
     32     _optional_component_not_installed(__name__, "sql", ie)
     34 from haystack.schema import Document, Label, Answer
---> 35 from haystack.document_stores.base import BaseDocumentStore, FilterType
     36 from haystack.document_stores.filter_utils import LogicalFilterClause
     39 logger = logging.getLogger(__name__)

ImportError: cannot import name 'BaseDocumentStore' from partially initialized module 'haystack.document_stores.base' (most likely due to a circular import) (/haystack/haystack/document_stores/base.py)

System:

mayankjobanputra commented 1 year ago

@bhawnapiryani can you share the command you used to install haystack? Also maybe the environment details (maybe which cloud you're using). I am unable to reproduce this locally on my linux machine.

MozerWang commented 1 year ago

@bhawnapiryani can you share the command you used to install haystack? i have the same issue! the cmd i use was "pip install farm-haystack" I would appreciate it if u can help me solve this issue!

mayankjobanputra commented 1 year ago

@MozerWang can you share the environment details? like OS, python version, Haystack version?

MozerWang commented 1 year ago

@MozerWang can you share the environment details? like OS, python version, Haystack version?

sorry,the detail as below: os: centos7 haystack: farm-haystack-1.14.0 python:3.7.16

I also met the issue when I use the cmd "pip install "farm-haystack[all]" ":

ERROR: Packages installed from PyPI cannot depend on packages which are not also hosted on PyPI. espnet depends on pytorch-wpe@ git+https://github.com/nttcslab-sp/dnn_wpe.git

mayankjobanputra commented 1 year ago

@MozerWang I will check with the team on Monday if we have any guidelines on CentOS internally.

For the cmd "pip install "farm-haystack[all]", the issue is with one package, we fixed it on main branch but you can do it locally by running the following commands.

pip uninstall requests-cache

pip install requests-cache<1.0.0

Also please feel free post as many full logs as you can so that we can debug issues more accurately.

MozerWang commented 1 year ago

appreciate!

MozerWang commented 1 year ago

Sorry to bother u!

Still this issue when i use the cmd "import haystack"

`>>> import haystack

Traceback (most recent call last): File "", line 1, in

File "/u01/wangminzheng/miniconda3/envs/bankqa/lib/python3.8/site-packages/haystack/init.py", line 21, in from haystack.nodes.base import BaseComponent

File "/u01/wangminzheng/miniconda3/envs/bankqa/lib/python3.8/site-packages/haystack/nodes/init.py", line 1, in from haystack.utils.import_utils import safe_import

File "/u01/wangminzheng/miniconda3/envs/bankqa/lib/python3.8/site-packages/haystack/utils/init.py", line 2, in from haystack.utils.preprocessing import convert_files_to_docs, tika_convert_files_to_docs

File "/u01/wangminzheng/miniconda3/envs/bankqa/lib/python3.8/site-packages/haystack/utils/preprocessing.py", line 7, in from haystack.nodes.file_converter import BaseConverter, DocxToTextConverter, PDFToTextConverter, TextConverter

File "/u01/wangminzheng/miniconda3/envs/bankqa/lib/python3.8/site-packages/haystack/nodes/file_converter/init.py", line 8, in from haystack.nodes.file_converter.tika import TikaConverter, TikaXHTMLParser

File "/u01/wangminzheng/miniconda3/envs/bankqa/lib/python3.8/site-packages/haystack/nodes/file_converter/tika.py", line 10, in from tika import parser as tikaparser

File "/u01/wangminzheng/miniconda3/envs/bankqa/lib/python3.8/site-packages/tika/parser.py", line 19, in from .tika import parse1, callServer, ServerEndpoint

File "/u01/wangminzheng/miniconda3/envs/bankqa/lib/python3.8/site-packages/tika/tika.py", line 156, in fileHandler = logging.FileHandler(log_file)

File "/u01/wangminzheng/miniconda3/envs/bankqa/lib/python3.8/logging/init.py", line 1147, in init StreamHandler.init(self, self._open())

File "/u01/wangminzheng/miniconda3/envs/bankqa/lib/python3.8/logging/init.py", line 1176, in _open return open(self.baseFilename, self.mode, encoding=self.encoding)

PermissionError: [Errno 13] Permission denied: '/tmp/tika.log'`

michaelfeil commented 1 year ago

Also having a

PermissionError: [Errno 13] Permission denied: '/tmp/tika.log

Multiple people using haystack on a shared workstation.