Yandex Cloud
本主题介绍如何在 Milvus 中配置和使用 Yandex Cloud embedding functions。
Choose an embedding model
Milvus 通过 yc provider 支持 Yandex Cloud AI Studio 文本向量化模型。在 Function 参数中,将 model_name 设置为 Milvus 应调用的 Yandex Cloud model URI。
例如,用于文档的 Yandex Text Embedding 使用类似 emb://<folder_ID>/text-search-doc/latest 的 model URI,并返回 256 维向量。如需了解可用的 model URI 和维度,请参阅 Text vectorization models。
Configure credentials
Milvus 必须先知道你的 Yandex Cloud API key,才能请求 Embedding。你可以在 milvus.yaml 中配置该 API key,也可以通过环境变量配置。
Option 1: Configuration file
将你的 API key 存储在 milvus.yaml 中,并将 Yandex Cloud provider 指向对应的 credential label。
# 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
Option 2: Environment variable
如果 milvus.yaml 中未配置匹配的凭据,Milvus 可以从以下环境变量读取 Yandex Cloud API key:
变量 | 是否必需? | 说明 |
|---|---|---|
| 是 | Milvus 服务用于调用 Yandex Cloud AI Studio 的 Yandex Cloud API key。 |
Use embedding function
配置好凭据后,定义一个包含输入文本字段和输出向量字段的 Schema,然后将 Yandex Cloud embedding Function 添加到该 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-specific parameters
参数 | 是否必需 | 描述 | 取值 / 示例 |
|---|---|---|---|
| 是 | 要使用的 embedding model provider。 |
|
| 是 | 要调用的 Yandex Cloud model URI。 |
|
| 否 | 在 |
|
| 否 | 输出向量维度。如果设置,该值必须与输出向量字段的维度一致。 |
|
Next steps
配置 embedding function 后,请参阅 Embedding Function Overview,了解如何创建索引、插入数据并执行语义搜索。