Yandex CloudCompatible with Milvus 2.6.x
本主题介绍了如何在 Milvus 中配置和使用 Yandex Cloud 的 Embeddings 功能。
选择嵌入模型
Milvus 通过yc 提供商支持 Yandex Cloud AI Studio 的文本向量模型。在“函数参数”中,将 `model_name ` 设置为 Milvus 应调用的 Yandex Cloud 模型 URI。
例如,Yandex文档Text Embeddings模型使用的模型URI为emb://<folder_ID>/text-search-doc/latest ,并返回256维向量。有关可用模型URI和维度,请参阅“文本向量化模型”。
配置凭据
Milvus 必须先获取您的 Yandex Cloud API 密钥,才能请求 Embeddings。您可以在milvus.yaml 中配置 API 密钥,或通过环境变量进行配置。
选项 1:配置文件
将您的 API 密钥存储在milvus.yaml 中,并将 Yandex Cloud 提供商指向凭据标签。
# milvus.yaml
credential:
yandex_apikey:
apikey: <YOUR_YC_API_KEY>
function:
textEmbedding:
providers:
yc:
credential: yandex_apikey
# url: https://llm.api.cloud.yandex.net/foundationModels/v1/textEmbedding
选项 2:环境变量
如果milvus.yaml 中未配置匹配的凭据,Milvus 可以从以下环境变量中读取 Yandex Cloud API 密钥:
变量 |
必填? |
描述 |
|---|---|---|
|
是 |
Milvus 服务用于调用 Yandex Cloud AI Studio 的 Yandex Cloud API 密钥。 |
使用嵌入函数
配置好凭据后,请定义一个包含输入文本字段和输出向量字段的 Schema,然后将 Yandex Cloud 嵌入函数添加到该 Schema 中。
from pymilvus import MilvusClient, DataType, Function, FunctionType
client = MilvusClient(uri="http://localhost:19530")
schema = client.create_schema()
schema.add_field("id", DataType.INT64, is_primary=True, auto_id=False)
schema.add_field("document", DataType.VARCHAR, max_length=9000)
schema.add_field("dense", DataType.FLOAT_VECTOR, dim=256)
text_embedding_function = Function(
name="yandex_cloud_embedding",
function_type=FunctionType.TEXTEMBEDDING,
input_field_names=["document"],
output_field_names=["dense"],
params={
"provider": "yc",
"model_name": "emb://<folder_ID>/text-search-doc/latest",
"credential": "yandex_apikey",
"dim": "256",
},
)
schema.add_function(text_embedding_function)
Yandex Cloud 特定参数
参数 |
必填? |
描述 |
值 / 示例 |
|---|---|---|---|
|
是 |
要使用的嵌入模型提供程序。 |
|
|
是 |
要调用的 Yandex Cloud 模型 URI。 |
|
|
否 |
在 |
|
|
否 |
输出向量的维度。若设置此参数,其值必须与输出向量字段的维度一致。 |
|
后续步骤
配置好嵌入函数后,请参阅《嵌入函数概述》,了解如何创建索引、插入数据以及运行语义搜索。