我有一个相当简单的程序,它包括在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上。
1条答案
按热度按时间um6iljoc1#
您可以在添加文档时传递批量参数,这有助于防止在输入大量文档时超时。
有关详细信息,请参阅文档以获取使用此功能的指导。