milvus向量库-避坑(一)

Milvus 是一个高性能、可扩展的矢量数据库。它支持各种规模的使用案例,从在 Jupyter Notebook 中本地运行的演示到处理数百亿个向量的大规模 Kubernetes 集群。目前,Milvus 有三种部署选项:Milvus Lite、Milvus Standalone 和 Milvus Distributed。

官网地址:Overview of Milvus Deployment Options | Milvus Documentation

一、Milvus Lite

网址:(两个项目不太一样,各有参考)

milvus-lite - GitCodeicon-default.png?t=O83Ahttps://gitcode.com/gh_mirrors/em/embd-milvus/overview?utm_source=artical_gitcode&index=top&type=card&&isLogin=1milvus-lite:A lightweight version of Milvus wrapped with Python. - GitCodeicon-default.png?t=O83Ahttps://gitcode.com/gh_mirrors/mi/milvus-lite/overview?utm_source=artical_gitcode&index=top&type=card&&isLogin=1

安装:

注意:pymilvus现在需要Python 3.7+


pip install -U pymilvus

代码:

from pymilvus import MilvusClient
import numpy as np
 
# 创建 Milvus Lite 客户端
client = MilvusClient("/milvus_demo.db")
 
# 创建一个集合
client.create_collection(
    collection_name="demo_collection",
    dimension=384  # 向量的维度
)
 
# 准备一些文本数据
docs = [
    "Artificial intelligence was founded as an academic discipline in 1956.",
    "Alan Turing was the first person to conduct substantial research in AI.",
    "Born in Maida Vale, London, Turing was raised in southern England."
]
 
# 生成随机向量(示例中使用随机数)
vectors = [[np.random.uniform(-1, 1) for _ in range(384)] for _ in range(len(docs))]
 
# 插入数据
data = [
    {"id": i, "vector": vectors[i], "text": docs[i], "subject": "history"}
    for i in range(len(vectors))
]
 
client.insert(
    collection_name="demo_collection",
    data=data
)
 
# 搜索向量
res = client.search(
    collection_name="demo_collection",
    data=[vectors[0]],
    filter="subject == 'history'",
    limit=2,
    output_fields=["text", "subject"]
)
 
print(res)

报错:

Failed to create new connection using: 0087f29a50714e73aa6264d8f581afb3

ModuleNotFoundError: No module named 'milvus_lite'

解决:milvus_lite只支持Ubuntu and MacOS,win系统不支持。

Milvus Lite currently supports the following environments:
- Ubuntu >= 20.04 (x86_64 and arm64)
- MacOS >= 11.0 (Apple Silicon M1/M2 and x86_64)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值