Milvus 是一个高性能、可扩展的矢量数据库。它支持各种规模的使用案例,从在 Jupyter Notebook 中本地运行的演示到处理数百亿个向量的大规模 Kubernetes 集群。目前,Milvus 有三种部署选项:Milvus Lite、Milvus Standalone 和 Milvus Distributed。
官网地址:Overview of Milvus Deployment Options | Milvus Documentation
一、Milvus Lite
网址:(两个项目不太一样,各有参考)
milvus-lite - GitCodehttps://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. - GitCode
https://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)