オンデマンド検索のための接続
オンデマンド検索やクエリのワークロードを、オンデマンドクラスターのコンピュートで実行する場合は、プロジェクトエンドポイントを使用します。
このページは、オンデマンド検索用にプロジェクトエンドポイントへ接続するためのものです。Free、Serverless、または Dedicated のサービングクラスターに接続する場合は、サービングクラスターへの接続 を参照してください。
エンドポイント形式
| エンドポイントタイプ | エンドポイントのパターン | 用途 |
|---|---|---|
| プロジェクトエンドポイント | https://{project-id}.{region}.api.zillizcloud.com | オンデマンドクラスターを介したデータインポート、バッチ検索、クエリ、get、検索、ハイブリッド検索。 |
事前準備
-
Zilliz Cloud コンソールからプロジェクトエンドポイントを取得すること。
-
検索ワークロードにコンピュートリソースを提供するオンデマンドクラスターの ID を取得すること。
-
プロジェクトおよび対象データに対して十分な権限を持つ API キーを作成すること。
-
用途に応じた Milvus SDK をインストールすること。詳細については、SDK のインストール を参照してください。
プロジェクトエンドポイントへの接続
プロジェクトエンドポイントを使用して MilvusClient を作成し、リクエストを処理するオンデマンドクラスターを指定します。
- Python
- Java
- Go
- Rust
- C++
- NodeJS
- cURL
from pymilvus import MilvusClient
client = MilvusClient(
uri="https://{project-id}.{region}.api.zillizcloud.com",
token="YOUR_API_KEY",
)
import io.milvus.v2.client.ConnectConfig;
import io.milvus.v2.client.MilvusClientV2;
ConnectConfig connectConfig = ConnectConfig.builder()
.uri("https://{project-id}.{region}.api.zillizcloud.com")
.token("YOUR_API_KEY")
.build();
MilvusClientV2 client = new MilvusClientV2(connectConfig);
// Note: The Go SDK does not support project-endpoint connections with
// on-demand cluster routing as of client/v3.0.0. Use a serving-cluster
// endpoint with the Go SDK instead.
use milvus::v2::prelude::*;
let config = ConnectConfig::new()
.uri("https://{project-id}.{region}.api.zillizcloud.com")
.token("YOUR_API_KEY");
let client = ClientV2::new(&config).await?;
#include <iostream>
#include "milvus/MilvusClientV2.h"
auto client = milvus::MilvusClientV2::Create();
auto status = client->Connect(milvus::ConnectParam("https://{project-id}.{region}.api.zillizcloud.com").WithToken("YOUR_API_KEY"));
if (!status.IsOk()) {
std::cout << status.Message() << std::endl;
}
import { MilvusClient } from "@zilliz/milvus2-sdk-node";
const client = new MilvusClient({
address: "https://{project-id}.{region}.api.zillizcloud.com",
token: "YOUR_API_KEY",
});
# Note: The RESTful API does not expose on-demand cluster routing.
# Connect to the project endpoint with the /v2/vectordb/* endpoints directly.
検索セッションの作成
セッションオブジェクトを使用して、操作をオンデマンドクラスターに関連付けます。
- Python
- Java
- Go
- Rust
- C++
- NodeJS
- cURL
session = client.session(cluster_id="inxx-xxxxxxxxxxxxxxx")
import io.milvus.v2.client.MilvusClientV2Session;
MilvusClientV2Session session = client.session("inxx-xxxxxxxxxxxxxxx");
// Note: Not yet supported in the Go SDK as of client/v3.0.0.
let session = client.session("inxx-xxxxxxxxxxxxxxx")?;
milvus::MilvusClientV2SessionPtr session;
status = client->Session("inxx-xxxxxxxxxxxxxxx", session);
if (!status.IsOk()) {
std::cout << status.Message() << std::endl;
}
const session = client.session("inxx-xxxxxxxxxxxxxxx");
# Note: REST does not expose session objects or on-demand cluster routing.
次に、セッションを使用して query、get、search、hybrid_search などの DQL 操作を実行します。
- Python
- Java
- Go
- Rust
- C++
- NodeJS
- cURL
results = session.search(
collection_name="my_collection",
data=[[0.1, 0.2, 0.3, 0.4]],
anns_field="vector",
limit=10,
)
print(results)
import io.milvus.v2.service.vector.request.SearchReq;
import io.milvus.v2.service.vector.request.data.FloatVec;
import io.milvus.v2.service.vector.response.SearchResp;
import java.util.Arrays;
import java.util.Collections;
SearchReq searchReq = SearchReq.builder()
.collectionName("my_collection")
.data(Collections.singletonList(new FloatVec(Arrays.asList(0.1f, 0.2f, 0.3f, 0.4f))))
.annsField("vector")
.topK(10)
.build();
SearchResp results = session.search(searchReq);
System.out.println(results.getSearchResults());
// Note: Not yet supported in the Go SDK as of client/v3.0.0.
use milvus::v2::prelude::*;
let results = session
.search(SearchRequest::builder()
.collection_name("my_collection")
.vector_field("vector")
.vectors(SearchVectors::Float(vec![vec![0.1, 0.2, 0.3, 0.4]]))
.limit(10)
.build()?)
.await?;
println!("{results:?}");
#include <vector>
milvus::SearchRequest request;
request.WithCollectionName("my_collection").WithLimit(10).WithAnnsField("vector");
request.AddFloatVector(std::vector<float>{0.1f, 0.2f, 0.3f, 0.4f});
milvus::SearchResponse response;
status = session->Search(request, response);
if (!status.IsOk()) {
std::cout << status.Message() << std::endl;
}
const results = await session.search({
collection_name: "my_collection",
vector: [0.1, 0.2, 0.3, 0.4],
anns_field: "vector",
limit: 10,
});
console.log(results);
# Note: REST does not expose session objects or on-demand cluster routing.
# Search an on-demand cluster via the /v2/vectordb/search endpoint on the project endpoint.
認証
プロジェクトエンドポイントに接続する場合は、有効な API キーを認証トークンとして使用します。
username:password 形式のクラスター認証情報は、サービングクラスターエンドポイント用です。プロジェクトエンドポイントを介したオンデマンド検索では、必要なプロジェクト権限を持つ API キーを使用します。
この接続を使用する場合
バッチ処理、探索、検証、実験など、常時稼働のサービングよりもオンデマンドコンピュートの方が適しているワークロードには、プロジェクトエンドポイントを使用します。
完全なコレクション API と常時稼働の低レイテンシサービングを必要とする本番アプリケーションでは、代わりに Free、Serverless、または Dedicated のサービングクラスターに接続してください。サービングクラスターのエンドポイント形式と接続例については、サービングクラスターへの接続 を参照してください。