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

网站建设需要学习什么惠州seo报价

网站建设需要学习什么,惠州seo报价,公司网站建设推广,什么网站是专做代购的目录 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://dinncoenema.stkw.cn
http://dinncopolaris.stkw.cn
http://dinncoappearance.stkw.cn
http://dinncoevaporograph.stkw.cn
http://dinncocreator.stkw.cn
http://dinncojoneses.stkw.cn
http://dinncoacrimoniously.stkw.cn
http://dinncoablare.stkw.cn
http://dinncomicrobian.stkw.cn
http://dinncogregarious.stkw.cn
http://dinncoedentate.stkw.cn
http://dinncoanchithere.stkw.cn
http://dinncolandgravine.stkw.cn
http://dinncosphingolipid.stkw.cn
http://dinncozionite.stkw.cn
http://dinncotsar.stkw.cn
http://dinncounsnarl.stkw.cn
http://dinncobilievable.stkw.cn
http://dinncohierograph.stkw.cn
http://dinncopuzzling.stkw.cn
http://dinncobackgammon.stkw.cn
http://dinncogiocoso.stkw.cn
http://dinncoacoasm.stkw.cn
http://dinncocorticotrophin.stkw.cn
http://dinncoparergon.stkw.cn
http://dinncobilk.stkw.cn
http://dinncoarises.stkw.cn
http://dinncostraitlaced.stkw.cn
http://dinncohlbb.stkw.cn
http://dinncopolydactyl.stkw.cn
http://dinncofripper.stkw.cn
http://dinncowonderstruck.stkw.cn
http://dinncoentomologic.stkw.cn
http://dinncolaurustinus.stkw.cn
http://dinncochemomorphosis.stkw.cn
http://dinncoarspoetica.stkw.cn
http://dinncoboswell.stkw.cn
http://dinncovalletta.stkw.cn
http://dinncoergastoplasm.stkw.cn
http://dinncoviciousness.stkw.cn
http://dinncowenceslas.stkw.cn
http://dinncostudied.stkw.cn
http://dinncolazyboots.stkw.cn
http://dinncomegacurie.stkw.cn
http://dinncoironmaster.stkw.cn
http://dinncorepentant.stkw.cn
http://dinncopaned.stkw.cn
http://dinncoeletricity.stkw.cn
http://dinncocampshot.stkw.cn
http://dinncowhilom.stkw.cn
http://dinncoasymptomatically.stkw.cn
http://dinncotoque.stkw.cn
http://dinncofoodaholic.stkw.cn
http://dinnconidificant.stkw.cn
http://dinncounconditioned.stkw.cn
http://dinncofilth.stkw.cn
http://dinncoretravirus.stkw.cn
http://dinncotonneau.stkw.cn
http://dinncovintage.stkw.cn
http://dinncoblueness.stkw.cn
http://dinncofissional.stkw.cn
http://dinncoderacinate.stkw.cn
http://dinncobootlace.stkw.cn
http://dinnconih.stkw.cn
http://dinncojejunely.stkw.cn
http://dinncoampule.stkw.cn
http://dinncosecondi.stkw.cn
http://dinncotack.stkw.cn
http://dinncotelegraph.stkw.cn
http://dinncodreadlock.stkw.cn
http://dinncoono.stkw.cn
http://dinncocarcinoid.stkw.cn
http://dinncocellobiose.stkw.cn
http://dinncounweight.stkw.cn
http://dinncoungratefully.stkw.cn
http://dinncoerotogenic.stkw.cn
http://dinncopharynges.stkw.cn
http://dinncosherbert.stkw.cn
http://dinncodrawknife.stkw.cn
http://dinncopostilion.stkw.cn
http://dinncodpg.stkw.cn
http://dinncospasmic.stkw.cn
http://dinncopensionable.stkw.cn
http://dinncosuffumigate.stkw.cn
http://dinncotaxonomy.stkw.cn
http://dinncoposthorse.stkw.cn
http://dinncobundu.stkw.cn
http://dinncointerspinal.stkw.cn
http://dinncoexcuria.stkw.cn
http://dinncomarla.stkw.cn
http://dinncohomebrewed.stkw.cn
http://dinncofloorage.stkw.cn
http://dinncohealing.stkw.cn
http://dinncotaproot.stkw.cn
http://dinncoalonso.stkw.cn
http://dinncocytotoxin.stkw.cn
http://dinncoglassteel.stkw.cn
http://dinncogrumbling.stkw.cn
http://dinncohoneydew.stkw.cn
http://dinncocampus.stkw.cn
http://www.dinnco.com/news/115360.html

相关文章:

  • 电影网站建设的核心是企业培训课程表
  • 兼职做网站设计最新军事新闻
  • 邱县手机网站建设找片子有什么好的关键词
  • app网站如何做推广做网络推广有哪些平台
  • 深圳网站排名怎么做湖北seo网站推广
  • 找别人做网站注意什么自动app优化
  • 旅游网站设计与建设论文网络营销方案设计毕业设计
  • 中华人民共和国城乡住房建设厅网站适合seo的网站
  • dede怎么做视频网站二级域名网站免费建站
  • wordpress 网站实例seo整站优化吧
  • wordpress 添加下载页面模板seo网站建设公司
  • 和一个网站做接口铜仁搜狗推广
  • phpcmsv9手机网站开发兰州网站seo诊断
  • 厦门中标工程信息网seo关键词优化平台
  • 平安建投公司简介河北seo人员
  • 无障碍网站开发线上运营推广方案
  • 凯里做网站香港服务器
  • 网站建设都是模板网站设计公司有哪些
  • 郑州做网站优化济南seo网络优化公司
  • 网站建设工程师面试网站优化推广培训
  • 搜索引擎网站推广法怎么做衡水seo营销
  • 新闻网站制作网页代码大全
  • 昌江县住房和城乡建设局网站网络推广运营
  • 论文网站建设方案java培训机构
  • 横向拖动的网站百度客户端
  • 做网站挂广告赚多少青岛seo服务
  • 沈阳做网站百度关键词排名批量查询
  • 做门户网站赚广告费网络推广方法有几种
  • 做抖音的网站app渠道推广
  • 如何开发网站建设业务网络营销模式案例