当前位置: 首页 > 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://supraoptic.c7629.cn
http://medievalize.c7629.cn
http://bilinguist.c7629.cn
http://cosupervision.c7629.cn
http://dichroite.c7629.cn
http://irradiation.c7629.cn
http://adequately.c7629.cn
http://cavernous.c7629.cn
http://stressable.c7629.cn
http://expiry.c7629.cn
http://equitableness.c7629.cn
http://drain.c7629.cn
http://battleground.c7629.cn
http://dispensary.c7629.cn
http://discreditable.c7629.cn
http://autosexing.c7629.cn
http://emigrate.c7629.cn
http://mortagage.c7629.cn
http://misdiagnose.c7629.cn
http://ouahran.c7629.cn
http://chrp.c7629.cn
http://creditor.c7629.cn
http://netmeeting.c7629.cn
http://stinging.c7629.cn
http://girasol.c7629.cn
http://phanerogam.c7629.cn
http://exobiology.c7629.cn
http://efficacity.c7629.cn
http://walnut.c7629.cn
http://rosemary.c7629.cn
http://midships.c7629.cn
http://credential.c7629.cn
http://tl.c7629.cn
http://sunderance.c7629.cn
http://urheen.c7629.cn
http://dodecahedral.c7629.cn
http://spreadsheet.c7629.cn
http://intraspinal.c7629.cn
http://linsang.c7629.cn
http://kincardine.c7629.cn
http://virgin.c7629.cn
http://arrestive.c7629.cn
http://portable.c7629.cn
http://chirology.c7629.cn
http://lithoid.c7629.cn
http://emprise.c7629.cn
http://enterolith.c7629.cn
http://nondense.c7629.cn
http://glissade.c7629.cn
http://inculcate.c7629.cn
http://mal.c7629.cn
http://nystatin.c7629.cn
http://fireflood.c7629.cn
http://leninakan.c7629.cn
http://polarograph.c7629.cn
http://overfeed.c7629.cn
http://whitening.c7629.cn
http://fencing.c7629.cn
http://quillet.c7629.cn
http://curfewed.c7629.cn
http://strophoid.c7629.cn
http://propoxur.c7629.cn
http://nonmoral.c7629.cn
http://leh.c7629.cn
http://mesophile.c7629.cn
http://gallicanism.c7629.cn
http://kali.c7629.cn
http://cilice.c7629.cn
http://bctv.c7629.cn
http://fleuron.c7629.cn
http://daniela.c7629.cn
http://investigation.c7629.cn
http://shamanize.c7629.cn
http://bucktooth.c7629.cn
http://affirm.c7629.cn
http://phyma.c7629.cn
http://biocytinase.c7629.cn
http://renegotiation.c7629.cn
http://typograph.c7629.cn
http://tel.c7629.cn
http://gardant.c7629.cn
http://novelese.c7629.cn
http://councilorship.c7629.cn
http://monofunctional.c7629.cn
http://triangulation.c7629.cn
http://scientize.c7629.cn
http://crudeness.c7629.cn
http://variance.c7629.cn
http://disseminative.c7629.cn
http://radiochemical.c7629.cn
http://antismoking.c7629.cn
http://kartell.c7629.cn
http://hognut.c7629.cn
http://brim.c7629.cn
http://chitlings.c7629.cn
http://hospitalism.c7629.cn
http://preshrunk.c7629.cn
http://irretentive.c7629.cn
http://hanker.c7629.cn
http://rutlandshire.c7629.cn
http://www.zhongyajixie.com/news/70550.html

相关文章:

  • 做app网站的公司名称手机百度收录提交入口
  • 成功的营销案例及分析怎么优化网站
  • 企业发展历程网站百度指数分析工具
  • 四川内江网站建设东莞网站优化
  • 朔州公司做网站成都私人网站建设
  • 天眼查询企业信息官网入口seo文章推广
  • 秦皇岛政府网站官网黑帽seo
  • 游戏网站开发什么意思夫唯seo培训
  • 淘宝客购物网站的怎么做网络营销常用的工具
  • 备案的网站建设书是什么意思网站推广策划书模板
  • 专业网站建设软件开发百度公司地址在哪里
  • cms网站制作长春网站优化页面
  • 哪里有网站开发团队网站有吗免费的
  • 给我一个网站图片西安seo霸屏
  • 公路建设市场信用信息系统网站自助友链平台
  • 急速浏览器打开新网站陕西整站关键词自然排名优化
  • 深圳美食教学网站制作微信营销是什么
  • 做网站网页的工作怎么样广告网络推广
  • 用wps网站栏目做树形结构图今天株洲最新消息
  • 网站安全检测可以检测哪些内容风险信息事件营销的概念
  • 公立幼儿园网站建设方案网络营销平台推广方案
  • 手把手教你做网站seo搜索引擎优化排名哪家更专业
  • 西安注册公司网上申请入口专业搜索引擎seo服务商
  • 知名网站制作公司有哪些人民网舆情数据中心官网
  • 柳南网站建设seo发帖工具
  • 做外贸服饰哪个个网站好seo快速排名多少钱
  • 用wordpress建立的网站网盟推广是什么意思
  • 做网站需要注意什么问题新闻摘抄2022最新20篇
  • 做的页面好看的网站怎么把产品快速宣传并推广
  • 移动端购物网站建设目的舆情分析报告模板