elasticsearch elastic_transport.ConnectionTimeout:连接超时原因:连接错误

rbl8hiat  于 11个月前  发布在  ElasticSearch
关注(0)|答案(1)|浏览(650)

我有一个相当简单的程序,它包括在python中向elasticsearch服务器添加项目:

dir = DATA_DIR
embeddings = OpenAIEmbeddings(openai_api_key=settings_app.OPENAI_API_KEY)
db = ElasticVectorSearch(
        elasticsearch_url=settings_app.ELASTICSEARCH_URL,
        index_name=settings_app.ELASTICSEARCH_INDEX,
        embedding=embeddings,
    )    

loader = DirectoryLoader(dir, glob="**/*.pdf", loader_cls=PyPDFLoader)
documents = loader.load()

# Split the loaded PDF files into smaller text pieces for easier processing
text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0)
texts = text_splitter.split_documents(documents)

db.add_documents(texts)

Elastic VectorSearch类由langchain库提供。当我运行这个程序时,我得到以下错误:

elastic_transport.ConnectionTimeout: Connection timeout caused by: ConnectionError(Connection error caused by: ProtocolError(('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))))

我的索引已经存在并且可以访问,因为我已经尝试使用另一种方法向其中添加一些数据。问题是我必须使用这个langchain函数,因为我有一个聊天机器人在上面运行。elasticsearch服务器在我工作的公司的网络上,而不是在localhost上。

um6iljoc

um6iljoc1#

您可以在添加文档时传递批量参数,这有助于防止在输入大量文档时超时。

  • bulk_kwargs -传递给Elasticsearch bulk的额外参数。
  • chunk_size:可选。一次添加到索引的文本数。默认值为500。
vector_store.add_texts(
  texts,
  bulk_kwargs={
      "chunk_size": 50,
      "max_chunk_bytes": 200000000
  })

有关详细信息,请参阅文档以获取使用此功能的指导。

相关问题