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

wordpress如何装修seo教程培训班

wordpress如何装修,seo教程培训班,宝安做棋牌网站建设哪家便宜,七里港网站建设本文档演示如何从Milvus将Collection数据全量导出,并适配迁移至DashVector。方案的主要流程包括: 首先,升级Milvus版本,目前Milvus只有在最新版本(v.2.3.x)中支持全量导出其次,将Milvus Collection的Schema信息和数据…

本文档演示如何从Milvus将Collection数据全量导出,并适配迁移至DashVector。方案的主要流程包括:

  1. 首先,升级Milvus版本,目前Milvus只有在最新版本(v.2.3.x)中支持全量导出
  2. 其次,将Milvus Collection的Schema信息和数据信息导出到具体的文件中
  3. 最后,以导出的文件作为输入来构建DashVector Collection并数据导入

下面,将详细阐述迁移方案的具体操作细节。

1. Milvus升级2.3.x版本

本文中,我们将借助Milvus的query_iterator来全量导出数据(query接口无法导出完整数据),由于该接口目前只在v2.3.x版本中支持,所以在导出数据前,需要先将Milvus版本升级到该版本。Milvus版本升级的详细操作参考Milvus用户文档。

注意:在进行Milvus Upgrade时需要注意数据的备份安全问题。

2. Milvus全量数据导出

数据的导出包含Schema以及数据记录,Schema主要用于完备地定义Collection,数据记录对应于每个Partition下的全量数据,这两部分涵盖了需要导出的全部数据。下文展示如何将单个Milvus Collection全量导出。

2.1. Schema导出

DashVector和Milvus在Schema的设计上有一些区别,DashVector向用户透出的接口非常简单,Milvus则更加详尽。从Milvus迁移DashVector时会涉及到部分Schema参数的删除(例如Collection的index_param参数),只会保留DashVector构建Collection的必要参数,以下为一个Schema转换的简单示例(其中,Collection已有的数据参考Milvus示例代码写入)。

python示例:

from pymilvus import (connections,utility,Collection,DataType
)
import os
import json
from pathlib import Pathfmt = "\n=== {:30} ===\n"print(fmt.format("start connecting to Milvus"))
host = os.environ.get('MILVUS_HOST', "localhost")
print(fmt.format(f"Milvus host: {host}"))
connections.connect("default", host=host, port="19530")metrics_map = {'COSINE': 'cosine','L2': 'euclidean','IP': 'dotproduct',
}dtype_map = {DataType.BOOL: 'bool',DataType.INT8: 'int',DataType.INT16: 'int',DataType.INT32: 'int',DataType.INT64: 'int',DataType.FLOAT: 'float',DataType.DOUBLE: 'float',DataType.STRING: 'str',DataType.VARCHAR: 'str',
}def load_collection(collection_name: str) -> Collection:has = utility.has_collection(collection_name)print(f"Does collection hello_milvus exist in Milvus: {has}")if not has:return Nonecollection = Collection(collection_name)      collection.load()return collectiondef export_collection_schema(collection, file: str):schema = collection.schema.to_dict()index = collection.indexes[0].to_dict()export_schema = dict()milvus_metric_type = index['index_param']['metric_type']try:export_schema['metrics'] = metrics_map[milvus_metric_type]except:raise Exception(f"milvus metrics_type{milvus_metric_type} not supported")export_schema['fields_schema'] = {}for field in schema['fields']:if 'is_primary' in field and field['is_primary']:continueif field['name'] == index['field']:# vectorif field['type'] == DataType.FLOAT_VECTOR:export_schema['dtype'] = 'float'export_schema['dimension'] = field['params']['dim']else:raise Exception(f"milvus dtype{field['type']} not supported yet")else:try:# non-vectorexport_schema['fields_schema'][field['name']] = dtype_map[field['type']]except:raise Exception(f"milvus dtype{field['type']} not supported yet")with open(file, 'w') as file:json.dump(export_schema, file, indent=4)  if __name__ == "__main__":collection_name = "YOUR_MILVUS_COLLECTION_NAME"collection = load_collection(collection_name)dump_path_str = collection_name+'.dump'dump_path = Path(dump_path_str)dump_path.mkdir(parents=True, exist_ok=True)schema_file = dump_path_str + "/schema.json"export_collection_schema(collection, schema_file)

JSON示例:

{"metrics": "euclidean","fields_schema": {"random": "float","var": "str"},"dtype": "float","dimension": 8
}

2.2. Data导出

DashVector和Milvus在设计上都有Partition的概念,所以向量以及其他数据进行导出时,需要注意按照Partition粒度进行导出。此外,DashVector的主键类型为str,而Milvus设计其为自定义类型,所以在导出时需要考虑主键类型的转换。以下为一个基于query_iterator接口导出的简单代码示例:

from pymilvus import (connections,utility,Collection,DataType
)
import os
import json
import numpy as np
from pathlib import Pathfmt = "\n=== {:30} ===\n"print(fmt.format("start connecting to Milvus"))
host = os.environ.get('MILVUS_HOST', "localhost")
print(fmt.format(f"Milvus host: {host}"))
connections.connect("default", host=host, port="19530")
pk = "pk"
vector_field_name = "vector"def load_collection(collection_name: str) -> Collection:has = utility.has_collection(collection_name)print(f"Does collection hello_milvus exist in Milvus: {has}")if not has:return Nonecollection = Collection(collection_name)      collection.load()return collectiondef export_partition_data(collection, partition_name, file: str):batch_size = 10output_fields=["pk", "random", "var", "embeddings"]query_iter = collection.query_iterator(batch_size=batch_size,output_fields = output_fields,partition_names=[partition_name])export_file = open(file, 'w')while True:docs = query_iter.next()if len(docs) == 0:# close the iteratorquery_iter.close()breakfor doc in docs:new_doc = {}new_doc_fields = {}for k, v in doc.items():if k == pk:# primary keynew_doc['pk'] = str(v)elif k == vector_field_name:new_doc['vector'] = [float(k) for k in v]else:new_doc_fields[k] = vnew_doc['fields'] = new_doc_fieldsjson.dump(new_doc, export_file)export_file.write('\n')export_file.close()if __name__ == "__main__":collection_name = "YOUR_MILVUS_COLLECTION_NAME"collection = load_collection(collection_name)pk = collection.schema.primary_field.namevector_field_name = collection.indexes[0].field_namedump_path_str = collection_name+'.dump'dump_path = Path(dump_path_str)dump_path.mkdir(parents=True, exist_ok=True)for partition in collection.partitions:partition_name = partition.nameif partition_name == '_default':export_path = dump_path_str + '/default.txt'else:export_path = dump_path_str + '/' + partition_name + ".txt"export_partition_data(collection, partition_name, export_path)

3. 将数据导入DashVector

3.1. 创建Cluster

参考DashVector官方用户手册构建Cluster。

3.2. 创建Collection

根据2.1章节中导出的Schema信息以及参考Dashvector官方用户手册来创建Collection。下面的示例代码会根据2.1章节中导出的schema.json来创建一个DashVector的Collection。

from dashvector import Client, DashVectorExceptionfrom pydantic import BaseModel
from typing import Dict, Type
import jsondtype_convert = {'int': int,'float': float,'bool': bool,'str': str
}class Schema(BaseModel):metrics: strdtype: Typedimension: intfields_schema: Dict[str, Type]@classmethoddef from_dict(cls, json_data):metrics = json_data['metrics']dtype = dtype_convert[json_data['dtype']]dimension = json_data['dimension']fields_schema = {k: dtype_convert[v] for k, v in json_data['fields_schema'].items()}return cls(metrics=metrics, dtype=dtype, dimension=dimension, fields_schema=fields_schema)def read_schema(schema_path) -> Schema:with open(schema_path) as file:json_data = json.loads(file.read())return Schema.from_dict(json_data)if __name__ == "__main__":milvus_dump_path = f"{YOUR_MILVUS_COLLECTION_NAME}.dump"milvus_dump_scheme_path = milvus_dump_path + "/schema.json"schema = read_schema(milvus_dump_scheme_path)client = dashvector.Client(api_key='YOUR_API_KEY',endpoint='YOUR_CLUSTER_ENDPOINT')# create collectionrsp = client.create(name="YOUR_DASHVECTOR_COLLECTION_NAME", dimension=schema.dimension, metric=schema.metrics, dtype=schema.dtype,fields_schema=schema.fields_schema)if not rsp:raise DashVectorException(rsp.code, reason=rsp.message)

3.3. 导入Data

根据2.2章节中导出的数据以及参考DashVector官方用户手册来批量插入Doc。下面的示例代码会依次解析各个Partition导出的数据,然后依次创建DashVector下的Partition并导入数据。

from dashvector import Client, DashVectorException, Docfrom pydantic import BaseModel
from typing import Dict, Type
import json
import glob
from pathlib import Pathdef insert_data(collection, partition_name, partition_file):if partition_name != 'default':rsp = collection.create_partition(partition_name)if not rsp:raise DashVectorException(rsp.code, reason=rsp.message)with open(partition_file) as f:for line in f:if line.strip():json_data = json.loads(line)rsp = collection.insert([Doc(id=json_data['pk'], vector=json_data['vector'], fields=json_data['fields'])])if not rsp:raise DashVectorException(rsp.code, reason=rsp.message)  if __name__ == "__main__":milvus_dump_path = f"{YOUR_MILVUS_COLLECTION_NAME}.dump"client = dashvector.Client(api_key='YOUR_API_KEY',endpoint='YOUR_CLUSTER_ENDPOINT')# create collectioncollection = client.get("YOUR_DASHVECTOR_COLLECTION_NAME")partition_files = glob.glob(milvus_dump_path+'/*.txt', recursive=False)for partition_file in partition_files:# create partitionpartition_name = Path(partition_file).steminsert_data(collection, partition_name, partition_file)


文章转载自:
http://bedclothing.c7622.cn
http://advice.c7622.cn
http://gruff.c7622.cn
http://kauai.c7622.cn
http://fax.c7622.cn
http://chansonnette.c7622.cn
http://compress.c7622.cn
http://vasotomy.c7622.cn
http://mailing.c7622.cn
http://erythroblastotic.c7622.cn
http://divinity.c7622.cn
http://lentitude.c7622.cn
http://soreness.c7622.cn
http://unforgettable.c7622.cn
http://embossment.c7622.cn
http://samlo.c7622.cn
http://altai.c7622.cn
http://pronounce.c7622.cn
http://itching.c7622.cn
http://mammary.c7622.cn
http://greenheart.c7622.cn
http://electrocautery.c7622.cn
http://including.c7622.cn
http://turbidly.c7622.cn
http://fortitude.c7622.cn
http://parachuter.c7622.cn
http://bizarre.c7622.cn
http://hoary.c7622.cn
http://halfhearted.c7622.cn
http://swastika.c7622.cn
http://dishabituate.c7622.cn
http://inculcation.c7622.cn
http://phat.c7622.cn
http://execration.c7622.cn
http://heterogamous.c7622.cn
http://unspiritual.c7622.cn
http://untidy.c7622.cn
http://conclusion.c7622.cn
http://owllight.c7622.cn
http://hemodilution.c7622.cn
http://creasy.c7622.cn
http://huntington.c7622.cn
http://thalassic.c7622.cn
http://indivisibility.c7622.cn
http://stotinka.c7622.cn
http://reimport.c7622.cn
http://beatify.c7622.cn
http://maranatha.c7622.cn
http://quadrilingual.c7622.cn
http://crossbill.c7622.cn
http://spiculate.c7622.cn
http://palatial.c7622.cn
http://indevout.c7622.cn
http://erythropia.c7622.cn
http://imitated.c7622.cn
http://maths.c7622.cn
http://saline.c7622.cn
http://aru.c7622.cn
http://escapable.c7622.cn
http://transketolase.c7622.cn
http://chrysanthemum.c7622.cn
http://barefaced.c7622.cn
http://bestially.c7622.cn
http://languishment.c7622.cn
http://washstand.c7622.cn
http://guidable.c7622.cn
http://impasto.c7622.cn
http://subsurface.c7622.cn
http://doncher.c7622.cn
http://infest.c7622.cn
http://denatant.c7622.cn
http://whey.c7622.cn
http://woorali.c7622.cn
http://lurch.c7622.cn
http://damper.c7622.cn
http://geocarpy.c7622.cn
http://multipolar.c7622.cn
http://poetics.c7622.cn
http://truncheon.c7622.cn
http://hydroxid.c7622.cn
http://mimicker.c7622.cn
http://ol.c7622.cn
http://uncovered.c7622.cn
http://expunction.c7622.cn
http://fetch.c7622.cn
http://bioethics.c7622.cn
http://board.c7622.cn
http://topless.c7622.cn
http://trucker.c7622.cn
http://thingummy.c7622.cn
http://caddice.c7622.cn
http://insubstantial.c7622.cn
http://chronologist.c7622.cn
http://monoatomic.c7622.cn
http://terotechnology.c7622.cn
http://environ.c7622.cn
http://kennel.c7622.cn
http://dyeworks.c7622.cn
http://dicentric.c7622.cn
http://nonverbal.c7622.cn
http://www.zhongyajixie.com/news/52991.html

相关文章:

  • 好多网站没排名了东莞网站建设推广公司
  • 网站备案类型推广公司
  • 郑州软件开发公司网站互联网营销推广公司
  • 腾讯企业邮箱登录页面湖南网站seo
  • 牡丹江最新通知今天湖南网站建设推广优化
  • 盱眙在仕德伟做网站的有几家十大网络营销经典案例
  • wordpress首页无法看到后台登录在线排名优化
  • 酒业网站模板下载百度竞价怎么操作
  • wordpress扫码付费可见插件zac博客seo
  • 落实网站建设培训班精神青岛网站seo公司
  • 手机网站 模板关键词歌曲免费听
  • 情侣做记录网站源码中国十大门户网站排行
  • 新疆做网站seo人工智能
  • 网站页面自动还原代码超级外链工具源码
  • 比较好的高端网站制作公司百度2020新版下载
  • 免费商城版网站制作引流推广网站平台
  • 百度网站免费电话全国疫情高峰感染高峰进度
  • wordpress后台中文站长之家seo概况查询
  • 展览公司网站建设全球搜索引擎
  • 胶州家园网站建设山西seo优化
  • 个人网站必须备案吗中国疫情最新消息
  • 西安手机网站建站商品关键词怎么优化
  • 做美食介绍的网站外贸网站搭建
  • 胶州哪家公司做网站外贸网站有哪些
  • 哪些做海报比较好的网站日本积分榜最新排名
  • wordpress友链页面福州seo按天付费
  • 做个网站得投入多少营销推广网站推广方案
  • 如何建立一个外贸公司网站网站开发流程的8个步骤
  • 做网站好平台化郑州千锋教育培训机构怎么样
  • 重庆视频制作公司排名山东关键词优化联系电话