当前位置: 首页 > news >正文

轻量级milvus安装和应用示例

轻量级milvus适合需要向量库,但不方便使用k8s或docker,有将milvus集成到python中的场景。

1 安装milvus

pip install milvus -i https://pypi.tuna.tsinghua.edu.cn/simple

2 启动milvus

1)终端启动

# 终端启动
milvus-server
# 后台启动
nohup milvus-server > run.log &

2)在python模块中启动

from milvus import default_server
from pymilvus import connections, utility
# Start your milvus server

default_server.start()
# Now you can connect with localhost and the given port
# Port is defined by default_server.listen_portconnections.connect(host='127.0.0.1', port=default_server.listen_port)# Check if the server is ready.print(utility.get_server_version())
# Stop your milvus server

default_server.stop()

3 测试milvus

走完上述步骤后,就可以测试和正常使用milvus了。

具体操作参考milvus client操作简单示例-CSDN博客

1)测试服务启动和连接

from milvus import default_server
from pymilvus import connections

# 配置数据存储路径(避免使用临时目录)
default_server.set_base_dir("milvus_data")  

# 启动服务(默认端口19530)
default_server.start()  

# 连接客户端
connections.connect("default", host="127.0.0.1", port=default_server.listen_port)

2)定义client和collection

from pymilvus import MilvusClient, DataType

client = MilvusClient(
    uri="http://localhost:19530",
    token="root:Milvus"
)

3)插入数据

data = [
    {"id": i, "vector": vectors[i], "text": docs[i], "subject": "history"}
    for i in range(len(vectors))

res = client.insert(collection_name="demo_collection", data=data)

print(res)

4)执行检索

# 执行搜索

query_vectors = [xxx] # 这里query向量已计算好,采用和准备数据是一样模型参数计算
res = client.search(
    collection_name="demo_collection",  # target collection
    data=query_vectors,  # query vectors
    limit=2,  # number of returned entities
    output_fields=["text", "subject"],  # specifies fields to be returned
)
print(res)

reference

---

基于Milvus Lite的轻量级向量数据库实战指南

https://juejin.cn/post/7528313969151033390

Milvus Lite 已交卷!轻量版 Milvus,主打就是一个轻便、无负担

https://zhuanlan.zhihu.com/p/635690303

milvus client操作简单示例

https://blog.csdn.net/liliang199/article/details/149904178

http://www.dtcms.com/a/339187.html

相关文章:

  • 一文精通 Swagger 在 .NET 中的全方位配置与应用
  • 软件测试-Selenium学习笔记
  • Dify-MCP服务创建案例
  • 循环高级综合练习①
  • 46 C++ STL模板库15-容器7-顺序容器-双端队列(deque)
  • 人工智能统一信息结构的挑战与前景
  • Vue3编程中更多常见书写错误场景
  • 使用OpenCV计算灰度图像的质心
  • 云原生堡垒机渗透测试场景
  • 所有普通I/O口都支持中断的51单片机@Ai8051U, AiCube 图形化配置
  • 微服务架构的演进:从 Spring Cloud Netflix 到云原生新生态
  • 大模型微调RAG、LORA、强化学习
  • 如何使用VNC对openEuler系统进行远程图形化操作
  • Ubuntu Server 22.04 k8s部署服务较时,文件描述符超过限制的处理方法
  • RabbitMQ:SpringBoot+RabbitMQ 多消费者绑定同一队列
  • Node.js 在 Windows Server 上的离线部署方案
  • leetcode349. 两个数组的交集
  • 轻度娱乐浪潮下定制开发开源AI智能名片S2B2C商城小程序的机遇与策略
  • 厚板数控矫平机的“第三堂课”——把视角拉远,看看它如何重塑整条制造链
  • 供水设备智慧化管理物联网解决方案:远程监控与运维
  • 搭建最新--若依分布式spring cloudv3.6.6 前后端分离项目--步骤与记录常见的坑
  • BKP相关知识点
  • 从机器视觉到图像识别:计算机视觉的多维探索
  • LINUX819 shell:for for,shift ,{} ,array[0] array[s] ,declare -x -a
  • 服务注册与服务发现原理与实现
  • CentOS 8开发测试环境:直接安装还是Docker更优?
  • Docker核心---数据卷(堵门秘籍)
  • 应用控制技术、内容审计技术、AAA服务器技术
  • 深入理解Redis持久化:让你的数据永不丢失
  • 电子电气架构 ---SDV技术基础与传统E/E架构有何不同?