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…

分布式NAS集群+ceph+CTDB

分布式存储系统中&#xff0c;分布式NAS、CTDB和Ceph常常被结合使用以提供高性能、高可用性和灵活扩展的存储解决方案。以下是这三者的关系及其在分布式存储系统中的角色&#xff1a; 一、分布式NAS&#xff08;Network Attached Storage&#xff09; 分布式NAS是一种通过网络…

lua 判断变量是否是数字

lua 判断变量是否是数字 在 Lua 中&#xff0c;可以使用 tonumber 函数来判断一个值是否是数字。tonumber 函数尝试将其参数转换为数字&#xff0c;如果转换失败&#xff0c;它将返回 nil。基于这一点&#xff0c;可以编写一个函数来判断一个值是否是数字。 以下是一个示例代…

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

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

计算机系统的性能指标及其运算与表示方法

计算机系统的性能指标及其运算与表示方法 计算机系统的性能指标是评估其运行效率和处理能力的重要标准。理解这些指标&#xff0c;并结合计算机的运算和表示方法&#xff0c;有助于全面掌握计算机系统的性能及其优化策略。 计算机系统的性能指标 计算机性能指标主要包括处理…

c++初级-1-指针

文章目录 指针一、指针的定义和使用二、指针所占内存空间三、空指针和野指针四、const 修饰指针五、指针与数组六、指针与函数 指针 一、指针的定义和使用 //定义指针int a 10;int* p &a;cout << *p << endl;cout << a << endl;//使用指针*p 1…

IT领域的初学者指南:从高考到新征程

前言 七月来临&#xff0c;各省高考分数已揭榜完成。对于许多学子来说&#xff0c;高考的完结并不意味着学习的结束&#xff0c;而是新旅程的开始。特别是对于那些有志于踏入IT领域的高考少年们&#xff0c;这个假期无疑是开启探索IT世界的绝佳时机。作为该领域的前行者和经验…

android——Livedata、StateFlow、ShareFlow和Channel的介绍和使用

目录 一、LiveData介绍 二、StateFlow介绍 三、ShareFlow介绍 四、Channel介绍 小结 一、LiveData介绍 LiveData是一种在Android开发中用于观察数据变化的组件。它可以被观察者注册并在数据变化时通知观察者&#xff0c;从而实现数据的实时更新。LiveData具有生命周期感知能力&…

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;这两种方法各有特点…

vue3+ts+uniapp+vite+pinia项目配置

开发环境&#xff1a; node >18&#xff0c;npm >8.10.2&#xff0c;vue < 3.2.31 安装项目 npx degit dcloudio/uni-preset-vue#vite-ts vue3-uniapp 1、引入样式规范 npm add -D eslint eslint-config-airbnb-base eslint-config-prettier eslint-import-resolv…

陶建辉当选 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语言版数据结构详解与实现

C语言版数据结构详解与实现 大家好&#xff0c;我是微赚淘客系统3.0的小编&#xff0c;也是冬天不穿秋裤&#xff0c;天冷也要风度的程序猿&#xff01;今天我们来深入探讨C语言中数据结构的详细实现及其应用。 数据结构概述 数据结构是计算机存储、组织数据的方式&#xff…

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

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