Milvus向量库安装部署

news2024/9/19 13:43:09

GitHub - milvus-io/milvus-sdk-java: Java SDK for Milvus.

1、安装Standstone 版本

参考:Linux之milvus向量数据库安装_milvus安装-CSDN博客

参考:Install Milvus Standalone with Docker Milvus documentation

一、安装步骤

1、安装docker

  docker的安装见博文Linux之docker安装,这里不再赘述。

2、安装fio命令

   yum install -y fio

3、磁盘性能测试

fio --rw=write --ioengine=sync --fdatasync=1 --directory=test-data --size=2200m --bs=2300 --name=mytest

4、检查CPU支持的指令集

我们使用lscpu命令可以查看CPU支持的指令集,Flags的参数值就是该服务器支持的CPU指令集

lscpu

5、检查docker版本

  根据milvus安装要求,docker版本要求是19.03以上版本,我们这里安装的docker版本为23.0.1,满足要求。

6、安装docker compose组件

  根据milvus安装要求,docker compose版本要求是1.25.1以上,我们这里安装的版本是1.29.2,满足要求。

yum -y install python3-pip

pip3 install --upgrade pip

 pip install docker-compose

下载

wget https://raw.githubusercontent.com/milvus-io/milvus/master/scripts/standalone_embed.sh

启动 Start Milvus

bash standalone_embed.sh start

  • Stop Milvus

bash standalone_embed.sh stop

  • Connect to Milvus

To delete data after stopping Milvus, run:

bash standalone_embed.sh delete

运行

Run Milvus using Python Milvus documentation

安装 PyMilvus 

python3 -m pip install pymilvus==2.3.6

python3 -m pip install pymilvus  最新版本是2.2.4

python3 -c "from pymilvus import Collection"

wget https://raw.githubusercontent.com/milvus-io/pymilvus/master/examples/hello_milvus.py

Run the example code

# hello_milvus.py demonstrates the basic operations of PyMilvus, a Python SDK of Milvus.
# 1. connect to Milvus
# 2. create collection
# 3. insert data
# 4. create index
# 5. search, query, and hybrid search on entities
# 6. delete entities by PK
# 7. drop collection
import time

import numpy as np
from pymilvus import (
    connections,
    utility,
    FieldSchema, CollectionSchema, DataType,
    Collection,
)

fmt = "\n=== {:30} ===\n"
search_latency_fmt = "search latency = {:.4f}s"
num_entities, dim = 3000, 8

#################################################################################
# 1. connect to Milvus
# Add a new connection alias `default` for Milvus server in `localhost:19530`
# Actually the "default" alias is a buildin in PyMilvus.
# If the address of Milvus is the same as `localhost:19530`, you can omit all
# parameters and call the method as: `connections.connect()`.
#
# Note: the `using` parameter of the following methods is default to "default".
print(fmt.format("start connecting to Milvus"))
# connects to a server
connections.connect("default", host="localhost", port="19530")

has = utility.has_collection("hello_milvus")
print(f"Does collection hello_milvus exist in Milvus: {has}")

#################################################################################
# 2. create collection
# We're going to create a collection with 3 fields.
# +-+------------+------------+------------------+------------------------------+
# | | field name | field type | other attributes |       field description      |
# +-+------------+------------+------------------+------------------------------+
# |1|    "pk"    |   VarChar  |  is_primary=True |      "primary field"         |
# | |            |            |   auto_id=False  |                              |
# +-+------------+------------+------------------+------------------------------+
# |2|  "random"  |    Double  |                  |      "a double field"        |
# +-+------------+------------+------------------+------------------------------+
# |3|"embeddings"| FloatVector|     dim=8        |  "float vector with dim 8"   |
# +-+------------+------------+------------------+------------------------------+
fields = [
    FieldSchema(name="pk", dtype=DataType.VARCHAR, is_primary=True, auto_id=False, max_length=100),
    FieldSchema(name="random", dtype=DataType.DOUBLE),
    FieldSchema(name="embeddings", dtype=DataType.FLOAT_VECTOR, dim=dim)
]

schema = CollectionSchema(fields, "hello_milvus is the simplest demo to introduce the APIs")

print(fmt.format("Create collection `hello_milvus`"))
hello_milvus = Collection("hello_milvus", schema, consistency_level="Strong")

################################################################################
# 3. insert data
# We are going to insert 3000 rows of data into `hello_milvus`
# Data to be inserted must be organized in fields.
#
# The insert() method returns:
# - either automatically generated primary keys by Milvus if auto_id=True in the schema;
# - or the existing primary key field from the entities if auto_id=False in the schema.
# inserts vectors in the collection
print(fmt.format("Start inserting entities"))
rng = np.random.default_rng(seed=19530)
entities = [
    # provide the pk field because `auto_id` is set to False
    [str(i) for i in range(num_entities)],
    rng.random(num_entities).tolist(),  # field random, only supports list
    rng.random((num_entities, dim)),    # field embeddings, supports numpy.ndarray and list
]

insert_result = hello_milvus.insert(entities)

hello_milvus.flush()
print(f"Number of entities in Milvus: {hello_milvus.num_entities}")  # check the num_entities

################################################################################
# 4. create index
# We are going to create an IVF_FLAT index for hello_milvus collection.
# create_index() can only be applied to `FloatVector` and `BinaryVector` fields.
# builds indexes on the entities:
print(fmt.format("Start Creating index IVF_FLAT"))
index = {
    "index_type": "IVF_FLAT",
    "metric_type": "L2",
    "params": {"nlist": 128},
}

hello_milvus.create_index("embeddings", index)

################################################################################
# 5. search, query, and hybrid search
# After data were inserted into Milvus and indexed, you can perform:
# - search based on vector similarity
# - query based on scalar filtering(boolean, int, etc.)
# - hybrid search based on vector similarity and scalar filtering.
#

# Before conducting a search or a query, you need to load the data in `hello_milvus` into memory.
# Loads the collection to memory and performs a vector similarity search:
print(fmt.format("Start loading"))
hello_milvus.load()

# -----------------------------------------------------------------------------
# search based on vector similarity
print(fmt.format("Start searching based on vector similarity"))
vectors_to_search = entities[-1][-2:]
search_params = {
    "metric_type": "L2",
    "params": {"nprobe": 10},
}

start_time = time.time()
result = hello_milvus.search(vectors_to_search, "embeddings", search_params, limit=3, output_fields=["random"])
end_time = time.time()

for hits in result:
    for hit in hits:
        print(f"hit: {hit}, random field: {hit.entity.get('random')}")
print(search_latency_fmt.format(end_time - start_time))

# -----------------------------------------------------------------------------
# query based on scalar filtering(boolean, int, etc.)
print(fmt.format("Start querying with `random > 0.5`"))

start_time = time.time()
result = hello_milvus.query(expr="random > 0.5", output_fields=["random", "embeddings"])
end_time = time.time()

print(f"query result:\n-{result[0]}")
print(search_latency_fmt.format(end_time - start_time))

# -----------------------------------------------------------------------------
# pagination
r1 = hello_milvus.query(expr="random > 0.5", limit=4, output_fields=["random"])
r2 = hello_milvus.query(expr="random > 0.5", offset=1, limit=3, output_fields=["random"])
print(f"query pagination(limit=4):\n\t{r1}")
print(f"query pagination(offset=1, limit=3):\n\t{r2}")


# -----------------------------------------------------------------------------
# hybrid search
print(fmt.format("Start hybrid searching with `random > 0.5`"))

start_time = time.time()
result = hello_milvus.search(vectors_to_search, "embeddings", search_params, limit=3, expr="random > 0.5", output_fields=["random"])
end_time = time.time()

for hits in result:
    for hit in hits:
        print(f"hit: {hit}, random field: {hit.entity.get('random')}")
print(search_latency_fmt.format(end_time - start_time))

###############################################################################
# 6. delete entities by PK
# You can delete entities by their PK values using boolean expressions.
ids = insert_result.primary_keys

expr = f'pk in ["{ids[0]}" , "{ids[1]}"]'
print(fmt.format(f"Start deleting with expr `{expr}`"))

result = hello_milvus.query(expr=expr, output_fields=["random", "embeddings"])
print(f"query before delete by expr=`{expr}` -> result: \n-{result[0]}\n-{result[1]}\n")

hello_milvus.delete(expr)

result = hello_milvus.query(expr=expr, output_fields=["random", "embeddings"])
print(f"query after delete by expr=`{expr}` -> result: {result}\n")


###############################################################################
# 7. drop collection
# Finally, drop the hello_milvus collection
print(fmt.format("Drop collection `hello_milvus`"))
utility.drop_collection("hello_milvus")

python3 hello_milvus.py

docker ps

192.168.1.242:9091/api/v1/health

使用浏览器访问连接地址http://ip:9091/api/v1/health,返回{“status”:“ok”}说明milvus数据库服务器运行正常。

docker port milvus-standalone

安装Attu

参考:https://github.com/zilliztech/attu/blob/main/doc/zh-CN/attu_install-docker.md

执行:

docker run -p 8000:3000 -e MILVUS_URL=192.168.1.242:19530 zilliz/attu:latest

待参考:kubernetes部署milvus_milvus集群版-CSDN博客

具体使用:

参考:Milvus技术探究 - 知乎 (zhihu.com)

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

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

相关文章

【开源】SpringBoot框架开发婚恋交友网站

目录 一、摘要1.1 项目介绍1.2 项目录屏 二、功能模块2.1 数据中心模块2.2 会员管理模块2.3 新闻管理模块2.4 相亲大会管理模块2.5 留言管理模块 三、系统设计3.1 用例设计3.2 数据库设计3.2.1 会员信息表3.2.2 新闻表3.2.3 相亲大会表3.2.4 留言表 四、系统展示五、核心代码5.…

六、回归与聚类算法 - 岭回归

目录 1、带有L2正则化的线性回归 - 岭回归 1.1 API 2、正则化程度的变化对结果的影响 3、波士顿房价预测 线性回归欠拟合与过拟合线性回归的改进 - 岭回归分类算法:逻辑回归模型保存与加载无监督学习:K-means算法 1、带有L2正则化的线性回归 - 岭回…

day53 String

创建String 对象 String s "abc"; String s new String(); String的常用方法 长度方法 length(); 比较方法 equals() equalsIgnoreCase() 忽略大小写比较 compareTo() compareToIgnoreCase() 比较是否相等 基本类型比较数值是否相等 引用类型比较两个引用是…

【MATLAB源码-第144期】基于matlab的蝴蝶优化算法(BOA)无人机三维路径规划,输出做短路径图和适应度曲线。

操作环境: MATLAB 2022a 1、算法描述 ​蝴蝶优化算法(Butterfly Optimization Algorithm, BOA)是基于蝴蝶觅食行为的一种新颖的群体智能算法。它通过模拟蝴蝶个体在寻找食物过程中的嗅觉导向行为以及随机飞行行为,来探索解空间…

应对电脑重新分区文件消失:预防措施、常见成因与恢复关键要点

电脑重新分区文件不见了是一个常见的问题,通常发生在用户对硬盘进行重新分区、格式化或操作系统重装过程中,可能导致已存在的文件和数据暂时不可见或永久丢失。 **预防文件丢失的方法:** 1. **提前备份**: 在进行任何重大磁盘操作前&#xff…

EXCEL 在列不同单元格之间插入N个空行

1、第一步数据,要求在每个数字之间之间插入3个空格 2、拿数据个数*(要插入空格数1) 19*4 3、填充 4、复制数据到D列 5、下拉数据,选择复制填充这样1-19就会重复4次 6、全选数据D列排序,这样即完成了插入空格 以…

SQLite 的使用

SQLite 是一个轻量级、自包含和无服务器的关系型数据库管理系统(RDBMS),广泛应用于嵌入式系统、移动应用程序和小中型网站。它易于创建、需要的配置较少,并且提供了用于管理和操作数据的强大功能集。本文,我们将带领你…

mysql 自定义函数create function

方便后续查询,做以下记录; 自定义函数是一种与存储过程十分相似的过程式数据库对象, 它与存储过程一样,都是由 SQL 语句和过程式语句组成的代码片段,并且可以被应用程序和其他 SQL 语句调用。 自定义函数与存储过程之间…

「递归算法」:求根节点到叶节点数字之和

一、题目 给你一个二叉树的根节点 root ,树中每个节点都存放有一个 0 到 9 之间的数字。 每条从根节点到叶节点的路径都代表一个数字: 例如,从根节点到叶节点的路径 1 -> 2 -> 3 表示数字 123 。 计算从根节点到叶节点生成的 所有数…

MyBatis参数处理和查询语句专题

MyBatis参数处理和查询语句专题 一、MyBatis参数处理1.单个简单类型参数2.单个Map参数3.单个实体类参数4.多参数5.Param注解(命名参数) 二、MyBatis查询语句专题1.结果映射(1)as 给列起别名(2)使⽤resultMa…

【C++】STL容器之string(迭代器,范围for)

💐 🌸 🌷 🍀 🌹 🌻 🌺 🍁 🍃 🍂 🌿 🍄🍝 🍛 🍤 📃个人主页 :阿然成长日记 …

ChatGPT回答模式

你发现了吗,ChatGPT的回答总是遵循这些类型方式。 目录 1.解释模式 2.类比模式 3.列举模式 4.限制模式 5.转换模式 6.增改模式 7.对比模式 8.翻译模式 9.模拟模式 10.推理模式 1.解释模式 ChatGPT 在回答问题或提供信息时,不仅仅给出…

【C++私房菜】面向对象中的简单继承

文章目录 一、 继承基本概念二、派生类对象及派生类向基类的类型转换三、继承中的公有、私有和受保护的访问控制规则四、派生类的作用域五、继承中的静态成员 一、 继承基本概念 通过继承(inheritance)联系在一起的类构成一种层次关系。通常在层次关系的…

2.22 作业

顺序表 运行结果 fun.c #include "fun.h" seq_p create_seq_list() {seq_p L (seq_p)malloc(sizeof(seq_list));if(LNULL){printf("空间申请失败\n");return NULL;}L->len 0; bzero(L,sizeof(L->data)); return L; } int seq_empty(seq_p L) {i…

音频声波的主观感受

一、响度 声压是“客观”的,响度是“主观”的。 响度又称音量。人耳感受到的声音强弱,它是人对声音大小的一个主观感觉量。响度的大小决定于声音接收处的波幅,就同一声源来说,波幅传播的愈远,响度愈小…

mybatis 集成neo4j实现

文章目录 前言一、引入jar包依赖二、配置 application.properties三、Mybatis Neo4j分页插件四、Mybatis Neo4j自定义转换器handler五、MybatisNeo4j代码示例总结 前言 MyBatis是一个基于Java语言的持久层框架,它通过XML描述符或注解将对象与存储过程或SQL语句进行…

面试必问!JVM 不得不说的知识点(三)

一、 JVM指令集: 1. 了解Java虚拟机的指令集是什么?举例说明一些常见的指令及其作用。 Java虚拟机的指令集是一组用于执行Java程序的低级操作码。这些指令直接在Java虚拟机上执行,可以认为是Java程序的二进制表示形式。以下是一些常见的Java虚拟机指令及其作用的例子: ic…

微信小程序 ---- 生命周期

目录 生命周期 1. 小程序运行机制 2. 小程序更新机制 3. 生命周期介绍 4. 应用级别生命周期 5. 页面级别生命周期 6. 生命周期两个细节补充说明 7. 组件生命周期 总结 生命周期 1. 小程序运行机制 冷启动与热启动: 小程序启动可以分为两种情况&#xff0…

【云动世纪:Apache Doris 技术之光】

本文节选自《基础软件之路:企业级实践及开源之路》一书,该书集结了中国几乎所有主流基础软件企业的实践案例,由 28 位知名专家共同编写,系统剖析了基础软件发展趋势、四大基础软件(数据库、操作系统、编程语言与中间件…

基于Android的校园请假App的研究与实现

博主介绍:✌程序员徐师兄、7年大厂程序员经历。全网粉丝12w、csdn博客专家、掘金/华为云/阿里云/InfoQ等平台优质作者、专注于Java技术领域和毕业项目实战✌ 🍅文末获取源码联系🍅 👇🏻 精彩专栏推荐订阅👇…