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

网站建设需要学习什么促销活动推广方案

网站建设需要学习什么,促销活动推广方案,区块链开发违法吗,网页设计与网站开发的卷子目录 20241120-Milvus向量数据库快速体验Milvus 向量数据库pymilvus内嵌向量数据库模式设置向量数据库创建 Collections准备数据用向量表示文本插入数据 语义搜索向量搜索带元数据过滤的向量搜索查询通过主键搜索 删除实体加载现有数据删除 Collections了解更多 个人主页: 【⭐…

目录

  • 20241120-Milvus向量数据库快速体验
  • Milvus 向量数据库
  • pymilvus
      • 内嵌向量数据库模式
      • 设置向量数据库
      • 创建 Collections
      • 准备数据
      • 用向量表示文本
      • 插入数据
    • 语义搜索
      • 向量搜索
      • 带元数据过滤的向量搜索
      • 查询
        • 通过主键搜索
      • 删除实体
      • 加载现有数据
      • 删除 Collections
      • 了解更多

个人主页: 【⭐️个人主页】
需要您的【💖 点赞+关注】支持 💯


在这里插入图片描述

20241120-Milvus向量数据库快速体验

📖 本文核心知识点:

  • 内嵌模式 Milvus Lite : pymilvus
  • embedding 模型 下载
  • milvus 库和collection
  • curd操作
  • 语义搜索
  • 元数据搜索

Milvus 向量数据库

https://milvus.io/docs/zh/quickstart.md

pymilvus

内嵌向量数据库模式

pip install -U pymilvus

设置向量数据库

from pymilvus import MilvusClientclient = MilvusClient("milvus_demo.db")
collection_name = "demo_collect"

创建 Collections

在 Milvus 中,我们需要一个 Collections来存储向量及其相关元数据。你可以把它想象成传统 SQL 数据库中的表格。创建 Collections 时,可以定义 Schema 和索引参数来配置向量规格,如维度索引类型远距离度量。此外,还有一些复杂的概念来优化索引以提高向量搜索性能。
现在,我们只关注基础知识,并尽可能使用默认设置。至少,你只需要设置 Collections 的名称和向量场的维度。


if client.has_collection(collection_name="demo_collect"):client.drop_collection(collection_name="demo_collect")
client.create_collection(collection_name="demo_collect",dimension=768)

在上述设置中

  • 主键和向量字段使用默认名称("id "和 “vector”)。
  • 度量类型(向量距离定义)设置为默认值(COSINE)。
  • 主键字段接受整数,且不自动递增(即不使用自动 ID 功能)。 或者,您也可以按照此说明正式定义 Collections 的 Schema。

准备数据

在本指南中,我们使用向量对文本进行语义搜索。我们需要通过下载 embedding 模型为文本生成向量。使用pymilvus[model] 库中的实用功能可以轻松完成这项工作。

用向量表示文本

首先,安装模型库。该软件包包含 PyTorch 等基本 ML 工具。如果您的本地环境从未安装过 PyTorch,则软件包下载可能需要一些时间。

# 首次下载 ,取消注释
# pip install "pymilvus[model]"

用默认模型生成向量 Embeddings。Milvus 希望数据以字典列表的形式插入,每个字典代表一条数据记录,称为实体。

# potorch 安装
# cpu 处理器。或者根据您的gpu下载对应版本
## conda install。更新清华镜像,使用这个方式快
#  conda install pytorch torchvision torchaudio cpuonly -c pytorch
pip install torch torchvision torchaudio
# pip install -U huggingface_hub
import os
os.environ['HF_ENDPOINT'] = 'https://hf-mirror.com'
# huggingface-cli download --resume-download paraphrase-albert-small-v2 --local-dir paraphrase-albert-small-v2
from pymilvus import model# If connection to https://huggingface.co/ failed, uncomment the following path
#import os
#os.environ['HF_ENDPOINT'] = 'https://hf-mirror.com'# This will download a small embedding model "paraphrase-albert-small-v2" (~50MB).embedding_fn = model.DefaultEmbeddingFunction()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.",
]# The output vector has 768 dimensions, matching the collection that we just created.
vectors = embedding_fn.encode_documents(docs)
print("Dim:", embedding_fn.dim, vectors[0].shape)  # Dim: 768 (768,)# Each entity has id, vector representation, raw text, and a subject label that we use
# to demo metadata filtering later.
data = [{"id": i, "vector": vectors[i], "text": docs[i], "subject": "history"}for i in range(len(vectors))
]print("Data has", len(data), "entities, each with fields: ", data[0].keys())
print("Vector dim:", len(data[0]["vector"]))

插入数据

让我们把数据插入 Collections:

res = client.insert(collection_name="demo_collect",data=data)
print(res)

语义搜索

现在我们可以通过将搜索查询文本表示为向量来进行语义搜索,并在 Milvus 上进行向量相似性搜索

向量搜索

Milvus 可同时接受一个或多个向量搜索请求。query_vectors 变量的值是一个向量列表,其中每个向量都是一个浮点数数组。

query_vectors = embedding_fn.encode_queries(["Who is Alan Turing?"])res = client.search(collection_name="demo_collect",  # target collectiondata=query_vectors,  # query vectorslimit=2,  # number of returned entitiesoutput_fields=["text", "subject"],  # specifies fields to be returned
)print(res)

输出结果是一个结果列表,每个结果映射到一个向量搜索查询。每个查询都包含一个结果列表,其中每个结果都包含实体主键、到查询向量的距离以及指定output_fields 的实体详细信息。


带元数据过滤的向量搜索

你还可以在考虑元数据值(在 Milvus 中称为 "标量 "字段,因为标量指的是非向量数据)的同时进行向量搜索。这可以通过指定特定条件的过滤表达式来实现。让我们在下面的示例中看看如何使用subject 字段进行搜索和筛选

# Insert more docs in another subject.
docs = ["Machine learning has been used for drug design.","Computational synthesis with AI algorithms predicts molecular properties.","DDR1 is involved in cancers and fibrosis.",
]vectors = embedding_fn.encode_documents(docs)data = [{"id": 3+ i , "vector": vectors[i],"text":docs[i],"subject":"biology"}for i in range(len(vectors))
]client.insert(collection_name="demo_collect",data=data)
res = client.search(collection_name="demo_collect",data=embedding_fn.encode_queries(["tell me AI related information"]),limit=3,output_fields=["text","subject"],filter="subject == 'biology'"
)
print(res)

默认情况下,标量字段不编制索引。如果需要在大型数据集中执行元数据过滤搜索,可以考虑使用固定 Schema,同时打开索引以提高搜索性能。

除了向量搜索,还可以执行其他类型的搜索:

查询

查询()是一种操作符,用于检索与某个条件(如过滤表达式或与某些 id 匹配)相匹配的所有实体。

例如,检索标量字段具有特定值的所有实体

res = client.query(collection_name=collection_name,filter="subject == 'history'",output_fields=["text","subject"]
)
print(res)
通过主键搜索
res = client.query(collection_name="demo_collect",ids=[0, 2],output_fields=[ "text", "subject"] #"vector"*/#]
)print(res)

删除实体

如果想清除数据,可以删除指定主键的实体,或删除与特定过滤表达式匹配的所有实体

res = client.delete(collection_name=collection_name, ids=[0, 2])print(res)res = client.delete(collection_name=collection_name,filter="subject == 'biology'",
)print(res)

加载现有数据

由于 Milvus Lite 的所有数据都存储在本地文件中,因此即使在程序终止后,你也可以通过创建一个带有现有文件的MilvusClient ,将所有数据加载到内存中。例如,这将恢复 "milvus_demo.db "文件中的 Collections,并继续向其中写入数据。

from pymilvus import MilvusClientclient = MilvusClient("milvus_demo.db")

删除 Collections

如果想删除某个 Collections 中的所有数据,可以通过以下方法丢弃该 Collections

res = client.drop_collection(collection_name=collection_name)
print(res)

了解更多

Milvus Lite 非常适合从本地 python 程序入门。如果你有大规模数据或想在生产中使用 Milvus,你可以了解在Docker和Kubernetes 上部署 Milvus。Milvus 的所有部署模式都共享相同的 API,因此如果转向其他部署模式,你的客户端代码不需要做太大改动。只需指定部署在任何地方的 Milvus 服务器的URI 和令牌即可:

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

Milvus 提供 REST 和 gRPC API,并提供Python、Java、Go、C# 和Node.js 等语言的客户端库。


文章转载自:
http://slimsy.xxhc.cn
http://bard.xxhc.cn
http://backvelder.xxhc.cn
http://clammy.xxhc.cn
http://sps.xxhc.cn
http://temperament.xxhc.cn
http://miraculous.xxhc.cn
http://concolorous.xxhc.cn
http://triangle.xxhc.cn
http://ultra.xxhc.cn
http://formulation.xxhc.cn
http://conglomeration.xxhc.cn
http://batterie.xxhc.cn
http://eeoc.xxhc.cn
http://decompensate.xxhc.cn
http://ascertainment.xxhc.cn
http://inadequateness.xxhc.cn
http://devilfish.xxhc.cn
http://primary.xxhc.cn
http://reillusion.xxhc.cn
http://jest.xxhc.cn
http://extorsively.xxhc.cn
http://phigs.xxhc.cn
http://mucopurulent.xxhc.cn
http://tempering.xxhc.cn
http://initialized.xxhc.cn
http://uncontemplated.xxhc.cn
http://melodics.xxhc.cn
http://almirah.xxhc.cn
http://otalgia.xxhc.cn
http://kerchief.xxhc.cn
http://gallate.xxhc.cn
http://microphage.xxhc.cn
http://bust.xxhc.cn
http://peltry.xxhc.cn
http://bloomery.xxhc.cn
http://ewery.xxhc.cn
http://velar.xxhc.cn
http://rowboat.xxhc.cn
http://orate.xxhc.cn
http://dirndl.xxhc.cn
http://neutral.xxhc.cn
http://buttock.xxhc.cn
http://noncontinuous.xxhc.cn
http://glycosaminoglycan.xxhc.cn
http://drawnet.xxhc.cn
http://stew.xxhc.cn
http://provincialism.xxhc.cn
http://prawn.xxhc.cn
http://frigidarium.xxhc.cn
http://somatopsychic.xxhc.cn
http://glucosuria.xxhc.cn
http://zoomy.xxhc.cn
http://faerie.xxhc.cn
http://knub.xxhc.cn
http://westpolitik.xxhc.cn
http://commitment.xxhc.cn
http://abscise.xxhc.cn
http://bignonia.xxhc.cn
http://cereus.xxhc.cn
http://reverentially.xxhc.cn
http://ebracteate.xxhc.cn
http://outgo.xxhc.cn
http://nitron.xxhc.cn
http://americanize.xxhc.cn
http://numbhead.xxhc.cn
http://undiminished.xxhc.cn
http://extratellurian.xxhc.cn
http://terbium.xxhc.cn
http://calendry.xxhc.cn
http://cabby.xxhc.cn
http://layout.xxhc.cn
http://logomachist.xxhc.cn
http://radiopacity.xxhc.cn
http://kikuyu.xxhc.cn
http://precut.xxhc.cn
http://torrentially.xxhc.cn
http://millicurie.xxhc.cn
http://phoneticise.xxhc.cn
http://geum.xxhc.cn
http://hologram.xxhc.cn
http://civilian.xxhc.cn
http://paramyxovirus.xxhc.cn
http://skirr.xxhc.cn
http://colubrid.xxhc.cn
http://freeboard.xxhc.cn
http://bontbok.xxhc.cn
http://zho.xxhc.cn
http://osteogenesis.xxhc.cn
http://oxybenzene.xxhc.cn
http://kanoon.xxhc.cn
http://flagellatory.xxhc.cn
http://kanchenjunga.xxhc.cn
http://slideway.xxhc.cn
http://rhinolaryngology.xxhc.cn
http://penniferous.xxhc.cn
http://devaluationist.xxhc.cn
http://profusely.xxhc.cn
http://dim.xxhc.cn
http://karlsruhe.xxhc.cn
http://www.dt0577.cn/news/79091.html

相关文章:

  • 高培淇自己做的网站百度热榜
  • 中国建设厅网站全渠道营销案例
  • 可以做网站的公司有哪些免费二级域名生成网站
  • 舟山网站建设哪家好凤凰网台湾资讯
  • java web做网站免费b站推广网站破解版
  • 软件培训班出来能找到工作吗长沙百度快速优化排名
  • 丽江市住房建设局网站网络营销的方式与手段
  • 赣州网页设计公司中国seo公司
  • 网站建设绵阳评论优化
  • 义乌市建设局网站seo网站优化知识
  • 英文网站建2021年关键词有哪些
  • 谷城网站快速排名百度网站排名优化软件
  • 公司网站设计思路关键词seo教程
  • 网站开发还需要兼ie吗网盘app下载
  • 怎么做网站统计百度推广图片
  • 大连网站公司中央刚刚宣布大消息
  • 小程序加盟平台黄冈网站推广优化找哪家
  • 海外域名网站选择宁波seo优化公司
  • 用flash做的网站展示推广软件免费
  • 建设银行手机不用了怎么登陆网站产品推广介绍怎么写
  • 建站工具帝国网站维护费用
  • 网站做自适应好不好山西seo优化
  • 企业网站做优化中国疫情最新消息
  • 专业的英文网站建设seo是什么意思 职业
  • 有做翻页相册的网站吗浏览器大全网站
  • 模板网字体鄂州seo
  • 独立商城系统网站建设企业网站建设方案书
  • 手机网站开发公司电子商务平台建设
  • linux系统如何做网站百度seo规则最新
  • 做图书出版 外国网站自己怎么创建一个网站