Milvus ConnectionRefusedError: how to connect locally

题意:怎样在本地连接到 Milvus 数据库。连接 Milvus 数据库被拒绝的错误

问题背景:

I am trying to run a RAG pipeline using haystack & Milvus.

我正在尝试使用 haystack 和 Milvus 运行一个 RAG(检索增强型生成)管道。

Its my first time using Milvus, and I seem to have an issue with it.

这是我第一次使用 Milvus,但我似乎遇到了一个问题。

I'm following this tutorial, with some basic changes: Retrieval-Augmented Generation (RAG) with Milvus and Haystack | Milvus Documentation

Here is my code:

import os
import urllib.requestfrom haystack import Pipeline
from haystack.components.converters import MarkdownToDocument
from haystack_integrations.components.embedders.ollama import OllamaDocumentEmbedder, OllamaTextEmbedderfrom haystack.components.preprocessors import DocumentSplitter
from haystack.components.writers import DocumentWriterfrom milvus_haystack import MilvusDocumentStore
from milvus_haystack.milvus_embedding_retriever import MilvusEmbeddingRetrieverurl = "https://www.gutenberg.org/cache/epub/7785/pg7785.txt"
file_path = "./davinci.txt"if not os.path.exists(file_path):urllib.request.urlretrieve(url, file_path) document_store = MilvusDocumentStore(connection_args={"uri": "./milvus.db"},drop_old=True,
)indexing_pipeline = Pipeline()
indexing_pipeline.add_component("converter", MarkdownToDocument())
indexing_pipeline.add_component("splitter", DocumentSplitter(split_by="sentence", split_length=2)
)
indexing_pipeline.add_component("embedder", OllamaDocumentEmbedder())
indexing_pipeline.add_component("writer", DocumentWriter(document_store))
indexing_pipeline.connect("converter", "splitter")
indexing_pipeline.connect("splitter", "embedder")
indexing_pipeline.connect("embedder", "writer")indexing_pipeline.draw('./pipeline_diagram.png')indexing_pipeline.run({"converter": {"sources": [file_path]}})

It all works well until the last line, where I get a ConnectionRefusedError. First the conversion (from markdown to document) runs well, but then the code fails.

直到最后一行,一切都运行正常,但随后我遇到了一个 ConnectionRefusedError。首先,转换(从 Markdown 到文档)运行得很好,但随后代码失败了。

I am not sure why it happens, as I see the milvus.db and milvus.db.lock files created as expected.

我不确定为什么会发生这种情况,因为我看到 milvus.db 和 milvus.db.lock 文件已经按预期被创建。

The full error is:

---------------------------------------------------------------------------
ConnectionRefusedError                    Traceback (most recent call last)
File /opt/anaconda3/envs/haystack_milvus_playground/lib/python3.11/site-packages/urllib3/connection.py:203, in HTTPConnection._new_conn(self)202 try:
--> 203     sock = connection.create_connection(204         (self._dns_host, self.port),205         self.timeout,206         source_address=self.source_address,207         socket_options=self.socket_options,208     )209 except socket.gaierror as e:File /opt/anaconda3/envs/haystack_milvus_playground/lib/python3.11/site-packages/urllib3/util/connection.py:85, in create_connection(address, timeout, source_address, socket_options)84 try:
---> 85     raise err86 finally:87     # Break explicitly a reference cycleFile /opt/anaconda3/envs/haystack_milvus_playground/lib/python3.11/site-packages/urllib3/util/connection.py:73, in create_connection(address, timeout, source_address, socket_options)72     sock.bind(source_address)
---> 73 sock.connect(sa)74 # Break explicitly a reference cycleConnectionRefusedError: [Errno 61] Connection refusedThe above exception was the direct cause of the following exception:NewConnectionError                        Traceback (most recent call last)
File /opt/anaconda3/envs/haystack_milvus_playground/lib/python3.11/site-packages/urllib3/connectionpool.py:791, in HTTPConnectionPool.urlopen(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, preload_content, decode_content, **response_kw)790 # Make the request on the HTTPConnection object
--> 791 response = self._make_request(792     conn,793     method,794     url,795     timeout=timeout_obj,796     body=body,797     headers=headers,798     chunked=chunked,799     retries=retries,800     response_conn=response_conn,801     preload_content=preload_content,802     decode_content=decode_content,803     **response_kw,804 )806 # Everything went great!File /opt/anaconda3/envs/haystack_milvus_playground/lib/python3.11/site-packages/urllib3/connectionpool.py:497, in HTTPConnectionPool._make_request(self, conn, method, url, body, headers, retries, timeout, chunked, response_conn, preload_content, decode_content, enforce_content_length)496 try:
--> 497     conn.request(498         method,499         url,500         body=body,501         headers=headers,502         chunked=chunked,503         preload_content=preload_content,504         decode_content=decode_content,505         enforce_content_length=enforce_content_length,506     )508 # We are swallowing BrokenPipeError (errno.EPIPE) since the server is509 # legitimately able to close the connection after sending a valid response.510 # With this behaviour, the received response is still readable.File /opt/anaconda3/envs/haystack_milvus_playground/lib/python3.11/site-packages/urllib3/connection.py:395, in HTTPConnection.request(self, method, url, body, headers, chunked, preload_content, decode_content, enforce_content_length)394     self.putheader(header, value)
--> 395 self.endheaders()397 # If we're given a body we start sending that in chunks.File /opt/anaconda3/envs/haystack_milvus_playground/lib/python3.11/http/client.py:1289, in HTTPConnection.endheaders(self, message_body, encode_chunked)1288     raise CannotSendHeader()
-> 1289 self._send_output(message_body, encode_chunked=encode_chunked)File /opt/anaconda3/envs/haystack_milvus_playground/lib/python3.11/http/client.py:1048, in HTTPConnection._send_output(self, message_body, encode_chunked)1047 del self._buffer[:]
-> 1048 self.send(msg)1050 if message_body is not None:1051 1052     # create a consistent interface to message_bodyFile /opt/anaconda3/envs/haystack_milvus_playground/lib/python3.11/http/client.py:986, in HTTPConnection.send(self, data)985 if self.auto_open:
--> 986     self.connect()987 else:File /opt/anaconda3/envs/haystack_milvus_playground/lib/python3.11/site-packages/urllib3/connection.py:243, in HTTPConnection.connect(self)242 def connect(self) -> None:
--> 243     self.sock = self._new_conn()244     if self._tunnel_host:245         # If we're tunneling it means we're connected to our proxy.File /opt/anaconda3/envs/haystack_milvus_playground/lib/python3.11/site-packages/urllib3/connection.py:218, in HTTPConnection._new_conn(self)217 except OSError as e:
--> 218     raise NewConnectionError(219         self, f"Failed to establish a new connection: {e}"220     ) from e222 # Audit hooks are only available in Python 3.8+NewConnectionError: <urllib3.connection.HTTPConnection object at 0x30ca49690>: Failed to establish a new connection: [Errno 61] Connection refusedThe above exception was the direct cause of the following exception:MaxRetryError                             Traceback (most recent call last)
File /opt/anaconda3/envs/haystack_milvus_playground/lib/python3.11/site-packages/requests/adapters.py:486, in HTTPAdapter.send(self, request, stream, timeout, verify, cert, proxies)485 try:
--> 486     resp = conn.urlopen(487         method=request.method,488         url=url,489         body=request.body,490         headers=request.headers,491         redirect=False,492         assert_same_host=False,493         preload_content=False,494         decode_content=False,495         retries=self.max_retries,496         timeout=timeout,497         chunked=chunked,498     )500 except (ProtocolError, OSError) as err:File /opt/anaconda3/envs/haystack_milvus_playground/lib/python3.11/site-packages/urllib3/connectionpool.py:845, in HTTPConnectionPool.urlopen(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, preload_content, decode_content, **response_kw)843     new_e = ProtocolError("Connection aborted.", new_e)
--> 845 retries = retries.increment(846     method, url, error=new_e, _pool=self, _stacktrace=sys.exc_info()[2]847 )848 retries.sleep()File /opt/anaconda3/envs/haystack_milvus_playground/lib/python3.11/site-packages/urllib3/util/retry.py:515, in Retry.increment(self, method, url, response, error, _pool, _stacktrace)514     reason = error or ResponseError(cause)
--> 515     raise MaxRetryError(_pool, url, reason) from reason  # type: ignore[arg-type]517 log.debug("Incremented Retry for (url='%s'): %r", url, new_retry)MaxRetryError: HTTPConnectionPool(host='localhost', port=11434): Max retries exceeded with url: /api/embeddings (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x30ca49690>: Failed to establish a new connection: [Errno 61] Connection refused'))During handling of the above exception, another exception occurred:ConnectionError                           Traceback (most recent call last)
Cell In[15], line 1
----> 1 indexing_pipeline.run({"converter": {"sources": [file_path]}})3 print("Number of documents:", document_store.count_documents())File /opt/anaconda3/envs/haystack_milvus_playground/lib/python3.11/site-packages/haystack/core/pipeline/pipeline.py:197, in Pipeline.run(self, data, debug, include_outputs_from)195 span.set_content_tag("haystack.component.input", last_inputs[name])196 logger.info("Running component {component_name}", component_name=name)
--> 197 res = comp.run(**last_inputs[name])198 self.graph.nodes[name]["visits"] += 1200 if not isinstance(res, Mapping):File /opt/anaconda3/envs/haystack_milvus_playground/lib/python3.11/site-packages/haystack_integrations/components/embedders/ollama/document_embedder.py:139, in OllamaDocumentEmbedder.run(self, documents, generation_kwargs)136     raise TypeError(msg)138 texts_to_embed = self._prepare_texts_to_embed(documents=documents)
--> 139 embeddings, meta = self._embed_batch(140     texts_to_embed=texts_to_embed, batch_size=self.batch_size, generation_kwargs=generation_kwargs141 )143 for doc, emb in zip(documents, embeddings):144     doc.embedding = embFile /opt/anaconda3/envs/haystack_milvus_playground/lib/python3.11/site-packages/haystack_integrations/components/embedders/ollama/document_embedder.py:107, in OllamaDocumentEmbedder._embed_batch(self, texts_to_embed, batch_size, generation_kwargs)105 batch = texts_to_embed[i]  # Single batch only106 payload = self._create_json_payload(batch, generation_kwargs)
--> 107 response = requests.post(url=self.url, json=payload, timeout=self.timeout)108 response.raise_for_status()109 result = response.json()File /opt/anaconda3/envs/haystack_milvus_playground/lib/python3.11/site-packages/requests/api.py:115, in post(url, data, json, **kwargs)103 def post(url, data=None, json=None, **kwargs):104     r"""Sends a POST request.105 106     :param url: URL for the new :class:`Request` object.(...)112     :rtype: requests.Response113     """
--> 115     return request("post", url, data=data, json=json, **kwargs)File /opt/anaconda3/envs/haystack_milvus_playground/lib/python3.11/site-packages/requests/api.py:59, in request(method, url, **kwargs)55 # By using the 'with' statement we are sure the session is closed, thus we56 # avoid leaving sockets open which can trigger a ResourceWarning in some57 # cases, and look like a memory leak in others.58 with sessions.Session() as session:
---> 59     return session.request(method=method, url=url, **kwargs)File /opt/anaconda3/envs/haystack_milvus_playground/lib/python3.11/site-packages/requests/sessions.py:589, in Session.request(self, method, url, params, data, headers, cookies, files, auth, timeout, allow_redirects, proxies, hooks, stream, verify, cert, json)584 send_kwargs = {585     "timeout": timeout,586     "allow_redirects": allow_redirects,587 }588 send_kwargs.update(settings)
--> 589 resp = self.send(prep, **send_kwargs)591 return respFile /opt/anaconda3/envs/haystack_milvus_playground/lib/python3.11/site-packages/requests/sessions.py:703, in Session.send(self, request, **kwargs)700 start = preferred_clock()702 # Send the request
--> 703 r = adapter.send(request, **kwargs)705 # Total elapsed time of the request (approximately)706 elapsed = preferred_clock() - startFile /opt/anaconda3/envs/haystack_milvus_playground/lib/python3.11/site-packages/requests/adapters.py:519, in HTTPAdapter.send(self, request, stream, timeout, verify, cert, proxies)515     if isinstance(e.reason, _SSLError):516         # This branch is for urllib3 v1.22 and later.517         raise SSLError(e, request=request)
--> 519     raise ConnectionError(e, request=request)521 except ClosedPoolError as e:522     raise ConnectionError(e, request=request)ConnectionError: HTTPConnectionPool(host='localhost', port=11434): Max retries exceeded with url: /api/embeddings (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x30ca49690>: Failed to establish a new connection: [Errno 61] Connection refused'))

any help resolving this would be appreciated. My assumption is that it is something very simple in creating the milvus database local connection, but I dont know where it is.

任何帮助解决这个问题都将不胜感激。我的猜测是,在创建 Milvus 数据库本地连接时可能有一些非常简单的设置问题,但我不知道问题出在哪里。

问题解决:

As suggested in earlier replies, Ollama was not running locally.

正如之前的回复所建议的,Ollama并没有在本地运行。

To resolve this I needed to:        解决这个问题需要做如下步骤:
1 - download and install Ollama 下载并安装 Ollama
2 - pull (or run) in the terminal ollama pull nomic-embed-text for the embedders. This is not clear enough in the haystack documentation for the ollama integration but once this is done it should run.

在终端中执行(或运行)ollama pull nomic-embed-text 命令来获取嵌入器(embedders)。在 haystack 的文档中,关于 ollama 集成的这一部分说明得不够清楚,但一旦完成这一步,它应该能够运行。

Also I would suggest to change from:        我建议替换如下代码:
indexing_pipeline.add_component("embedder", OllamaDocumentEmbedder())
to:

indexing_pipeline.add_component("embedder", OllamaDocumentEmbedder(model="nomic-embed-text", url="http://localhost:11434/api/embeddings"))

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/pingmian/39681.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

vue+element-ui简洁完美实现个人博客“​响石潭 ​”

目录 一、项目介绍 二、项目截图 1.项目结构图 2.首页 3.生活 ​编辑 4.文章详情 ​编辑 5.关于我 ​编辑 ​编辑 三、源码实现 1.项目依赖package.json 2.项目启动 3.首页源码 四、总结 一、项目介绍 本项目在线预览&#xff1a;点击访问 参考官网&#xff1…

腾讯 TRANSAGENTS: 多智能体翻译框架上线

之前介绍的由腾讯 AI 实验室搞得TRANSAGENTS&#xff08;多 Agent 系统&#xff0c;模拟现实翻译出版流程&#xff09;终于上线演示了&#xff01;提供了基于 GPT-4o 的免费试用, 暂时还是期货开源。

R语言fastshap包进行支持向量机shap可视化分析

1995年VAPINK 等人在统计学习理论的基础上提出了一种模式识别的新方法—支持向量机 。它根据有限的样本信息在模型的复杂性和学习能力之间寻求一种最佳折衷。 以期获得最好的泛化能力.支持向量机的理论基础决定了它最终求得的是全局最优值而不是局部极小值,从而也保证了它对未知…

[数据集][目标检测]围栏破损检测数据集VOC+YOLO格式1196张1类别

数据集格式&#xff1a;Pascal VOC格式YOLO格式(不包含分割路径的txt文件&#xff0c;仅仅包含jpg图片以及对应的VOC格式xml文件和yolo格式txt文件) 图片数量(jpg文件个数)&#xff1a;1196 标注数量(xml文件个数)&#xff1a;1196 标注数量(txt文件个数)&#xff1a;1196 标注…

40V转5V,40V转3.3V,40V转3V使用什么降压芯片型号?

40V转5V,40V转3.3V,40V转3V使用什么降压芯片型号? # 40V转5V、3.3V、3V降压芯片&#xff1a;AH8820A的介绍与应用 在电子电路设计中&#xff0c;电压转换是一个常见的需求。特别是在需要将较高电压转换为较低电压以供微控制器、传感器和其他低电压设备使用时&#xff0c;降压…

力扣1685.有序数组中差绝对值之和

力扣1685.有序数组中差绝对值之和 记录左边之和 和 右边之和从左到右遍历每个元素 求res class Solution {public:vector<int> getSumAbsoluteDifferences(vector<int>& nums) {int n nums.size(),lsum 0,rsum accumulate(nums.begin(),nums.end(),0);ve…

匿名方法与Lambda表达式

知识集锦 一、lambda表达式介绍 无参数 () >{return "1";}; 等同于 string getnum(){ return "1"; } 有两个参数 (p1, p2) >{ return p1*p2;}; 等同于 int mul(p1, p2) { return p1*p2;}; lambda表达式可以捕获外部变量&#xff0c;并在其主体中使用…

怎么在电脑上录屏?跟着教程一步步操作

随着数字化时代的到来&#xff0c;电脑录屏已经成为一项必备技能。无论是录制游戏画面、制作教程视频&#xff0c;还是保存线上会议记录&#xff0c;录屏都能帮上大忙。可是怎么在电脑上录屏呢&#xff1f;本文将介绍两种在电脑上进行录屏的方法&#xff0c;这两种方法各有特点…

陶建辉当选 GDOS 全球数据库及开源峰会荣誉顾问

近日&#xff0c;第二十三届 GOPS 全球运维大会暨 XOps 技术创新峰会在北京正式召开。本次会议重点议题方向包括开源数据库落地思考、金融数据库自主可控、云原生时代下数据库、数据库智能运维、数据库安全与隐私、开源数据库与治理。大会深入探讨这些方向&#xff0c;促进了数…

宇宙第一大厂亚马逊云科技AWS人工智能/机器学习证书即将上线,一篇文章教你轻松拿下

据麦肯锡《在华企业如何填补AI人才缺口》研究表明&#xff0c;到2030年人工智能为中国带来的潜在价值有望超过1万亿美元&#xff0c;而随着各大企业进入人工智能化&#xff0c;对该领域的人才需求将从目前的100万增长到2030年的600万。然而到保守估计&#xff0c;到2030可以满足…

DevOps:开发与运维的无缝融合

目录 前言1. DevOps的起源与概念1.1 DevOps的起源1.2 DevOps的定义 2. DevOps的核心实践2.1 持续集成2.2 持续交付2.3 自动化 3. DevOps工具链3.1 版本控制系统3.2 持续集成工具3.3 配置管理工具3.4 容器化与编排工具3.5 监控和日志工具 4. DevOps的实际应用4.1 案例分析&#…

C语言实战 | 用户管理系统

近期推出的青少年防沉迷系统&#xff0c;采用统一运行模式和功能标准。在“青少年模式”下&#xff0c;未成年人的上网时段、时长、功能和浏览内容等方面都有明确的规范。防沉迷系统为青少年打开可控的网络空间。 01、综合案例 防沉迷系统的基础是需要一个用户管理系统管理用户…

C# 计算椭圆上任意一点坐标

已知圆心坐标 &#xff08;x0&#xff0c;y0&#xff09;&#xff0c;横轴 A&#xff08;长半轴&#xff09;&#xff0c;竖轴 B&#xff08;短半轴&#xff09;&#xff0c;角度 a&#xff0c;则圆边上点&#xff08;x&#xff0c;y&#xff09;的坐标为&#xff1a; 方法一 …

docker push 推送镜像到阿里云仓库

1.登陆阿里云 镜像服务&#xff0c;跟着指引操作就行 创建个人实例&#xff0c;创建命名空间、镜像仓库&#xff0c;绑定代码源头 2.将镜像推送到Registry $ docker login --username*** registry.cn-beijing.aliyuncs.com $ docker tag [ImageId] registry.cn-beijing.aliy…

Vue入门-如何创建一个Vue实例

创建一个一个Vue实例总共分为四步&#xff1a; 1.创建一个容器 2.引包&#xff1a;地址栏搜索v2.cn.vuejs.org这是vue2的官网地址&#xff0c;把2去掉就是vue3的官网地址&#xff0c;我们的包分为开发版本和生产版本&#xff0c;开发版本包含完整的警告和调试模式生产版本删除…

太阳辐射系统日光全光谱模拟太阳光模拟器

太阳光模拟器是一种用于评估太阳能电池性能的重要设备。它能够模拟太阳光的特性&#xff0c;通过测试电池的短路电流、开路电压、填充因子和光电转化效率等关键指标&#xff0c;来评估电池的性能优劣。 设备型号&#xff1a;KYF-GC004品牌制造商&#xff1a;科迎法电气太阳光模…

UE5基本操作(二)

文章目录 前言相机的移动速度修改默认地图使用初学者内容包文件夹结构 总结 前言 在我们的上一篇文章中&#xff0c;我们已经介绍了一些Unreal Engine 5&#xff08;UE5&#xff09;的基本操作。UE5是一款强大的游戏开发引擎&#xff0c;它提供了许多工具和功能&#xff0c;使…

蓝牙压力测试和稳定性测试工具(nRF Connect)

蓝牙压力测试和稳定性测试工具&#xff08;nRF Connect&#xff09; 文章目录 1、如何使用nRF Connect事件记录功能2、如何使用nRF Connect录制操作2.1、点击右下角的开始录制2.2、输入想要测试的指令2.3、模拟持续数据访问2.4、开始压力测试 1、如何使用nRF Connect事件记录功…

【python】OpenCV—QR Code

文章目录 1 QR Code2 准备工作3 生成 QR 码4 读取 QR 码5 与 Zbar 比较 1 QR Code QR Code&#xff08;Quick Response Code&#xff09;是一种二维条码&#xff0c;由日本Denso-Wave公司于1994年发明。QR Code的主要特点是存储信息量大、编码范围广、容错能力强、识读速度快&…

基于PI控制的三相整流器控制系统的simulink建模与仿真,包含超级电容充电和电机

目录 1.课题概述 2.系统仿真结果 3.核心程序与模型 4.系统原理简介 5.完整工程文件 1.课题概述 基于PI控制的三相整流器控制系统的simulink建模与仿真,用MATLAB自带的PMSM电机设为发电机&#xff0c;输入为转速&#xff0c;后面接一个可以调节电流的三相整流器&#xff0c…