linux安装milvus数据库lite版本

server/2024/10/22 17:22:45/

https://milvus.io/docs/milvus_lite.md

参考上述教程,直接安装该包即可。标准版和分布式版要运行docker。

pip install -U pymilvus

下面是官方的demo,一起看看

from pymilvus import MilvusClient # 导入库,客户端
import numpy as np # # 创建客户端,并连接到一个名为 milvus_demo.db 的本地数据库。这个文件将用于存储 Milvus 数据库的索引和数据
client = MilvusClient("/root/RAG/milvus/milvus_demo.db")
client.create_collection(collection_name="demo_collection",dimension=4  # The vectors we will use in this demo has 384 dimensions
) # 创建集合,设置名称和向量维度数# 待加入的文本,三条。
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(4) ] for _ in range(len(docs)) ]
print(vectors)# 构建json字典,这是真正传入数据库的东西
data = [ {"id": i, "vector": vectors[i], "text": docs[i], "subject": "history"} for i in range(len(vectors)) ]
# insert方法插入数据
res = client.insert(collection_name="demo_collection",data=data
)
print(data)# 检索数据,传入Query向量,结合布尔检索
res = client.search(collection_name="demo_collection",data=[vectors[0]],filter="subject == 'history'",limit=2,output_fields=["text", "subject"],
)
print(res)# 查询数据,纯布尔检索
res = client.query(collection_name="demo_collection",filter="subject == 'history'",output_fields=["text", "subject"],
)
print(res)# 根据布尔条件删除记录
res = client.delete(collection_name="demo_collection",filter="subject == 'history'",
)
print(res)

输出:
vector:

[[-0.18993033343249377, -0.853204716673974, -0.6934232192055412, -0.7363553533144986], [0.6506801349937705, -0.5114297246706443, -0.6227428721418204, -0.4484672597247552], [0.3325751425210133, -0.5403168744637166, 0.6497994854622242, -0.7438264838676247]]

data:

[{'id': 0, 'vector': [-0.18993033343249377, -0.853204716673974, -0.6934232192055412, -0.7363553533144986], 'text': 'Artificial intelligence was founded as an academic discipline in 1956.', 'subject': 'history'}, {'id': 1, 'vector': [0.6506801349937705, -0.5114297246706443, -0.6227428721418204, -0.4484672597247552], 'text': 'Alan Turing was the first person to conduct substantial research in AI.', 'subject': 'history'}, {'id': 2, 'vector': [0.3325751425210133, -0.5403168744637166, 0.6497994854622242, -0.7438264838676247], 'text': 'Born in Maida Vale, London, Turing was raised in southern England.', 'subject': 'history'}]

search的res:

data: ["[{'id': 0, 'distance': 1.0, 'entity': {'text': 'Artificial intelligence was founded as an academic discipline in 1956.', 'subject': 'history'}}, {'id': 1, 'distance': 0.7123634815216064, 'entity': {'text': 'Alan Turing was the first person to conduct substantial research in AI.', 'subject': 'history'}}]"]

query的res:

data: ["{'id': 0, 'text': 'Artificial intelligence was founded as an academic discipline in 1956.', 'subject': 'history'}", "{'id': 1, 'text': 'Alan Turing was the first person to conduct substantial research in AI.', 'subject': 'history'}", "{'id': 2, 'text': 'Born in Maida Vale, London, Turing was raised in southern England.', 'subject': 'history'}"] 

delete的res:

[0, 1, 2]

在创建集合并插入数据时,Milvus 会默认使用 FLAT(扁平)索引。
可以在插入数据之后随时创建或修改索引。


http://www.ppmy.cn/server/110274.html

相关文章

Golang 开发使用 gorm 时打印 SQL 语句

目录 1. 使用 Debug 方法2. 全局设置日志级别3. 自定义 Logger4. 总结 参考 gorm 文档:https://gorm.io/zh_CN/docs/logger.html Gorm 有一个 默认 logger 实现,默认情况下,它会打印慢 SQL 和错误。如果想要全部或部分打印 SQL 的话可以通过设…

小柴带你学AutoSar系列三、标准和规范篇(3)ModeManagement

目录 ModeManagementGuide 2 Overall mechanisms and concepts 2.1 Declaration of modes 2.2 Mode managers and mode users 2.3 Modes in the RTE 2.4 Modes in the Basic Software Scheduler 2.5 Communication of modes 3 Configuration of the Basic Software Mod…

我如何解决 java.lang.ClassNotFoundException:javax.xml.bind.DatatypeConverter

优质博文:IT-BLOG-CN 问题 我如何解决java.lang.ClassNotFoundException:javax.xml.bind.DatatypeConverter 2024-08-25T02:31:25.46202:00 ERROR 21868 --- [fintonic-oauth] [nio-8080-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet…

入行「游戏策划」,该从何处下手?

想知道策划岗位该怎么入行可点击蓝链 相比较起以技术为最重要评判标准的开发岗, 「游戏策划」这一岗位在非业界人士的眼中 一直都是一个风评方差很大的岗位。 有人说策划岗又轻松又威风, 只需要输出想法,落地都交给开发, 干…

【Qt 事件】—— 详解Qt事件处理

目录 (一)事件介绍 (二)事件的处理 (三)按键事件 3.1 单个按键 3.2 组合按键 (四)鼠标事件 4.1 鼠标单击事件 4.2 鼠标释放事件 4.3 鼠标双击事件 4.4 鼠标移动事件 4.5…

PHP:构建高效Web应用的强大语言

PHP:构建高效Web应用的强大语言 在当今的Web开发领域,PHP依然是一个不可忽视的强大工具。自1995年诞生以来,PHP(Hypertext Preprocessor)已经发展成为一种广泛使用的开源脚本语言,特别适用于Web开发并可嵌入HTML中使用。本文将深入探讨PHP的核心优势、最新发展,并通过一…

uni-app - - - - - 自定义tabbar

uni-app - - - - - 自定义tabbar 1. 创建页面2. pages.json3. 自定义tabbar4. 隐藏原生tabbar5. 全局注册组件6. 页面使用7. 效果图展示 1. 创建页面 2. pages.json 配置tabbar {"tabBar": {"list": [{"pagePath": "pages/ballroom/ballr…

数学建模--皮尔逊相关系数、斯皮尔曼相关系数

目录 1.总体的皮尔逊相关系数 2.样本的皮尔逊相关系数 3.对于皮尔逊相关系数的认识 4.描述性统计以及corr函数 ​编辑 5.数据导入实际操作 6.引入假设性检验 6.1简单认识 6.2具体步骤 7.p值判断法 8.检验正态分布 8.1jb检验 8.2威尔克检验:针对于p值进行…