南山网站优化wordpress前端用户网址
南山网站优化,wordpress前端用户网址,招标投标公共服务平台,什么网站能买建设摩托车1、Milvus 概述 向量是神经网络模型的输出数据格式#xff0c;可以有效地对信息进行编码#xff0c;在知识库、语义搜索、检索增强生成#xff08;RAG#xff09;等人工智能应用中发挥着举足轻重的作用。Milvus 是一个开源的向量数据库#xff0c;适合各种规模的人工智能应…1、Milvus 概述向量是神经网络模型的输出数据格式可以有效地对信息进行编码在知识库、语义搜索、检索增强生成RAG等人工智能应用中发挥着举足轻重的作用。Milvus 是一个开源的向量数据库适合各种规模的人工智能应用。Milvus 是一种高性能、高扩展性的向量数据库可在从笔记本电脑到大规模分布式系统等各种环境中高效运行。它既可以开源软件的形式提供也可以云服务的形式提供。2、Embeddings 和 Milvus文本、图像和音频等非结构化数据格式各异并带有丰富的底层语义因此分析起来极具挑战性。为了处理这种复杂性Embeddings 被用来将非结构化数据转换成能够捕捉其基本特征的数字向量。然后将这些向量存储在向量数据库中从而实现快速、可扩展的搜索和分析。Milvus 提供强大的数据建模功能使您能够将非结构化或多模式数据组织成结构化的 Collections。它支持多种数据类型适用于不同的属性模型包括常见的数字和字符类型、各种向量类型、数组、集合和 JSON为您节省了维护多个数据库系统的精力。3、Milvus的三种部署模式Milvus 提供三种部署模式涵盖各种数据规模--从本地原型到管理数百亿向量的大规模 Kubernetes 集群此专栏只讲述前两种模式图片为3种模式对于不同数据的应用Milvus Lite 是一个 Python 库可以轻松集成到您的应用程序中。作为 Milvus 的轻量级版本它非常适合在 开发环境 中进行快速原型开发或在资源有限的边缘设备上运行。Milvus Standalone 是单机服务器部署所有组件都捆绑在一个 Docker 镜像中方便部署。Milvus Distributed 可部署在 Kubernetes 集群上采用云原生架构专为十亿规模甚至更大的场景而设计。该架构可确保关键组件的冗余。4、Milvus LiteMilvus Lite是一个 Python 库可导入到您的应用程序中。作为 Milvus 的轻量级版本它非常适合在 Jupyter 笔记本或资源有限的智能设备上运行快速原型。Milvus Lite 支持与 Milvus 其他部署相同的 API。与 Milvus Lite 交互的客户端代码也能与其他部署模式下的 Milvus 实例协同工作。由于milvus-lite已包含在pymilvus2.4.2或更高版本中因此可通过pip install与-U强制更新到最新版本milvus-lite会自动安装。要将 Milvus Lite 集成到应用程序中请运行pip install pymilvus进行安装并使用MilvusClient(./demo.db) 语句实例化一个带有本地文件的向量数据库以持久化所有数据。ps:windows不支持可以租借Linux服务器在服务器上安装请在python需要环境下进行安装。Milvus Lite 目前支持以下环境Ubuntu 20.04x86_64 和 arm64MacOS 11.0苹果硅 M1/M2 和 x86_641、安装2、代码测试# 导入必要的库 from pymilvus import MilvusClient # Milvus 客户端用于操作嵌入式向量数据库 import numpy as np # NumPy 库用于生成随机数和处理数组 # 初始化 Milvus 客户端 # 参数 ./milvus_demo.db 指定了本地数据库文件的路径 client MilvusClient(./milvus_demo.db) # 创建集合Collection # 集合类似于关系型数据库中的表用于存储向量和其他字段 client.create_collection( collection_namedemo_collection, # 集合名称为 demo_collection dimension384 # 向量的维度为 384表示每个向量是一个长度为 384 的浮点数数组 ) # 准备数据文档、向量和其他字段 docs [ Artificial intelligence was founded as an academic discipline in 1956., # 文档 1 Alan Turing was the first person to conduct substantial research in AI., # 文档 2 Born in Maida Vale, London, Turing was raised in southern England., # 文档 3 ] # 为每段文本生成一个随机的 384 维向量 # 使用 NumPy 的 np.random.uniform 生成范围在 -1 到 1 之间的随机数 vectors [[np.random.uniform(-1, 1) for _ in range(384)] for _ in range(len(docs))] # 将文档、向量、ID 和主题打包成字典格式 # 每个字典包含以下字段 # - id: 唯一标识符 # - vector: 向量数据 # - text: 文本内容 # - subject: 主题标签这里是 history data [ {id: i, vector: vectors[i], text: docs[i], subject: history} for i in range(len(vectors)) ] # 将数据插入到集合中 res client.insert( collection_namedemo_collection, # 指定目标集合 datadata # 要插入的数据列表 ) # 输出插入结果通常返回成功状态或插入的记录数 print(Insert result:, res) # 执行相似性搜索 # 在集合中查找与查询向量最相似的记录 res client.search( collection_namedemo_collection, # 指定目标集合 data[vectors[0]], # 查询向量这里使用了第一个文档的向量 filtersubject history, # 筛选条件只返回主题为 history 的记录 limit2, # 返回的最大结果数量这里是 2 条 output_fields[text, subject], # 指定返回的字段这里返回 text 和 subject ) # 输出搜索结果 print(Search result:, res) # 执行查询操作 # 根据条件筛选记录类似于 SQL 查询 res client.query( collection_namedemo_collection, # 指定目标集合 filtersubject history, # 筛选条件只返回主题为 history 的记录 output_fields[text, subject], # 指定返回的字段这里返回 text 和 subject ) # 输出查询结果 print(Query result:, res) # 删除记录 # 根据条件删除记录 res client.delete( collection_namedemo_collection, # 指定目标集合 filtersubject history, # 删除条件删除主题为 history 的记录 ) # 输出删除结果 print(Delete result:, res)5、Milvus 单机版Milvus Standalone 是单机服务器部署。Milvus Standalone 的所有组件都打包到一个Docker 镜像中部署起来非常方便。如果你有生产工作负载但又不想使用 Kubernetes那么在内存充足的单机上运行 Milvus Standalone 是一个不错的选择。此外Milvus Standalone 通过主从复制支持高可用性我使用的是华为云服务器也可以使用优云智算相对便宜些。1、安装安装docker#安装必要支持 sudo apt install apt-transport-https ca-certificates curl software-properties-common gnupg lsb-release # 配置 阿里源推荐使用阿里的gpg KEY,不同厂商的加速器可能不同有问题请联系厂商支持 curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg echo deb [arch$(dpkg --print-architecture) signed-by/usr/share/keyrings/docker-archive-keyring.gpg] https://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable | sudo tee /etc/apt/sources.list.d/docker.list /dev/null #更新 源 sudo apt update sudo apt-get update #安装最新版本的Docker sudo apt install docker-ce docker-ce-cli containerd.io docker-compose-plugin #等待安装完成 #查看Docker版本 sudo docker version #查看Docker运行状态 sudo systemctl status docker在 Docker 中安装 MilvusMilvus 提供了一个安装脚本可将其安装为 docker 容器。该脚本可在Milvus 存储库中找到。要在 Docker 中安装 Milvus只需运行# 下载官方提供的安装脚本 curl -sfL https://raw.githubusercontent.com/milvus-io/milvus/master/scripts/standalone_embed.sh -o standalone_embed.sh # 安装Milvus 并且启动 bash standalone_embed.sh start # 停止Milvus服务 bash standalone_embed.sh stop # 删除Milvus的所有容器 bash standalone_embed.sh delete2、代码测试Milvus有两个端口9091195309091对应WebUI的端口运行Milvus后打开9091,打开http://127.0.0.1:9091/webui/,就可以打开其Web界面,如下图19530是数据库的连接端口XXXX为你的服务器外网IP地址client MilvusClient(urihttp://XXXX:19530测试代码from pymilvus import MilvusClient import numpy as np clientMilvusClient(urixxxx) client.drop_collection(collection_namexxxx) client.create_collection( collection_namexxxx, dimension384 ) docs[ Artificial intelligence was founded as an academic discipline in 1956., # 文档 1 Alan Turing was the first person to conduct substantial research in AI., # 文档 2 Born in Maida Vale, London, Turing was raised in southern England., # 文档 3 ] 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(docs)) ] client.insert( collection_namexxxx, datadata ) # client.release_collection(collection_namedemo_collection) # Milvus 会将索引文件和所有字段的原始数据加载到内存中以便快速响应搜索和查询。 # client.load_collection(collection_namedemo_collection) resclient.search( collection_namexxxx, datavectors[0], filtersubject history, limit2, output_fields[text,subject] ) print(search result:,res)