アナライザーの概要
テキスト処理において、アナライザーは生のテキストを構造化された検索可能な形式に変換するための重要なコンポーネントです。各アナライザーは通常、トークナイザーとフィルターという2つのコア要素で構成されています。これらが協調して入力テキストをトークンに変換し、それらのトークンを洗練させて、効率的なインデックス作成および検索の準備を行います。
Zilliz Cloudでは、コレクションスキーマにVARCHARフィールドを追加する際に、コレクション作成時にアナライザーを設定します。アナライザーによって生成されたトークンは、キーワードマッチング用のインデックス構築に使用することも、全文検索用のスパース埋め込みに変換することもできます。詳細については、Full Text Search または Text Match を参照してください。
アナライザーの使用はパフォーマンスに影響を与える可能性があります:
全文検索: 全文検索の場合、データNodeおよびQueryNodeチャネルはトークン化が完了するまで待機しなければならないため、データの消費速度が遅くなります。その結果、新しく取り込まれたデータが検索可能になるまでに時間がかかります。
キーワードマッチ: キーワードマッチの場合も、トークン化が完了してからでないとインデックスを作成できないため、インデックス作成が遅くなります。
アナライザーの構成
Zilliz Cloudにおけるアナライザーは、ちょうど1つのトークナイザーとゼロ個以上のフィルターで構成されます。
-
トークナイザー: トークナイザーは入力テキストを「トークン」と呼ばれる個別の単位に分割します。これらのトークンは、トークナイザーの種類に応じて単語やフレーズになります。
-
フィルター: フィルターはトークンに適用され、小文字化や一般的な単語の除去など、トークンをさらに洗練させるために使用されます。
トークナイザーはUTF-8形式のみをサポートしています。他の形式のサポートは今後のリリースで追加される予定です。
以下のワークフローは、アナライザーがテキストを処理する方法を示しています。

アナライザーの種類
Zilliz Cloudでは、さまざまなテキスト処理ニーズに対応するために、次の2種類のアナライザーを提供しています。
-
組み込みアナライザー: これらは事前定義された設定で、最小限のセットアップで一般的なテキスト処理タスクをカバーします。組み込みアナライザーは汎用的な検索に最適で、複雑な設定が不要です。
-
カスタムアナライザー: より高度な要件に対しては、カスタムアナライザーを使用することで、トークナイザーとゼロ個以上のフィルターを自分で指定した独自の設定を定義できます。このレベルのカスタマイズは、テキスト処理をきめ細かく制御する必要がある特殊なユースケースに特に役立ちます。
コレクション作成時にアナライザーの設定を省略した場合、Zilliz Cloudはすべてのテキスト処理にデフォルトで
standardアナライザーを使用します。詳細については、Standardを参照してください。検索およびクエリのパフォーマンスを最適化するには、テキストデータの言語に合ったアナライザーを選択してください。たとえば、
standardアナライザーは汎用性が高いものの、中国語、日本語、韓国語など、独自の文法構造を持つ言語には必ずしも最適ではありません。このような場合には、chineseのような言語固有のアナライザーや、linderaやicuなどの特殊なトークナイザーとフィルターを組み合わせたカスタムアナライザーを使用することを強く推奨します。これにより、正確なトークン化とより良い検索結果が得られます。
組み込みアナライザー
Zilliz Cloudクラスター内の組み込みアナライザーは、特定のトークナイザーとフィルターが事前設定されており、これらのコンポーネントを自分で定義せずにすぐに使用できます。各組み込みアナライザーはテンプレートとして機能し、プリセットされたトークナイザーとフィルターを含み、必要に応じてカスタマイズ可能なオプションのパラメーターも備えています。
たとえば、standard組み込みアナライザーを使用するには、その名前standardをtypeとして指定し、必要に応じてこのアナライザー固有の追加設定(例: stop_words)を含めるだけです。
- Python
- Java
- NodeJS
- Go
- cURL
analyzer_params = {
"type": "standard", # Uses the standard built-in analyzer
"stop_words": ["a", "an", "for"] # Defines a list of common words (stop words) to exclude from tokenization
}
Map<String, Object> analyzerParams = new HashMap<>();
analyzerParams.put("type", "standard");
analyzerParams.put("stop_words", Arrays.asList("a", "an", "for"));
const analyzer_params = {
"type": "standard", // Uses the standard built-in analyzer
"stop_words": ["a", "an", "for"] // Defines a list of common words (stop words) to exclude from tokenization
};
analyzerParams := map[string]any{"type": "standard", "stop_words": []string{"a", "an", "for"}}
export analyzerParams='{
"type": "standard",
"stop_words": ["a", "an", "for"]
}'
アナライザーの実行結果を確認するには、run_analyzer メソッドを使用します:
- Python
- Java
- NodeJS
- Go
- cURL
# Sample text to analyze
text = "An efficient system relies on a robust analyzer to correctly process text for various applications."
# Run analyzer
result = client.run_analyzer(
text,
analyzer_params
)
import io.milvus.v2.service.vector.request.RunAnalyzerReq;
import io.milvus.v2.service.vector.response.RunAnalyzerResp;
List<String> texts = new ArrayList<>();
texts.add("An efficient system relies on a robust analyzer to correctly process text for various applications.");
RunAnalyzerResp resp = client.runAnalyzer(RunAnalyzerReq.builder()
.texts(texts)
.analyzerParams(analyzerParams)
.build());
List<RunAnalyzerResp.AnalyzerResult> results = resp.getResults();
// javascrip# Sample text to analyze
const text = "An efficient system relies on a robust analyzer to correctly process text for various applications."
// Run analyzer
const result = await client.run_analyzer({
text,
analyzer_params
});
import (
"context"
"encoding/json"
"fmt"
"github.com/milvus-io/milvus/client/v2/milvusclient"
)
bs, _ := json.Marshal(analyzerParams)
texts := []string{"An efficient system relies on a robust analyzer to correctly process text for various applications."}
option := milvusclient.NewRunAnalyzerOption(texts).
WithAnalyzerParams(string(bs))
result, err := client.RunAnalyzer(ctx, option)
if err != nil {
fmt.Println(err.Error())
// handle error
}
# restful
export MILVUS_HOST="YOUR_CLUSTER_ENDPOINT"
export TEXT_TO_ANALYZE="An efficient system relies on a robust analyzer to correctly process text for various applications."
curl -X POST "http://${MILVUS_HOST}/v2/vectordb/common/run_analyzer" \
-H "Content-Type: application/json" \
-d '{
"text": ["'"${TEXT_TO_ANALYZE}"'"],
"analyzerParams": "{\"type\":\"standard\",\"stop_words\":[\"a\",\"an\",\"for\"]}"
}'
出力は次のようになります。
['efficient', 'system', 'relies', 'on', 'robust', 'analyzer', 'to', 'correctly', 'process', 'text', 'various', 'applications']
これは、アナライザーが入力テキストを適切にトークン化し、ストップワード "a"、"an"、および "for" をフィルタリングしつつ、残りの意味のあるトークンを返すことを示しています。
上記の組み込みアナライザー standard の設定は、以下のパラメータでカスタムアナライザーを設定することと同等です。この場合、同様の機能を実現するために tokenizer および filter オプションが明示的に定義されています:
- Python
- Java
- NodeJS
- Go
- cURL
analyzer_params = {
"tokenizer": "standard",
"filter": [
"lowercase",
{
"type": "stop",
"stop_words": ["a", "an", "for"]
}
]
}
Map<String, Object> analyzerParams = new HashMap<>();
analyzerParams.put("tokenizer", "standard");
analyzerParams.put("filter",
Arrays.asList("lowercase",
new HashMap<String, Object>() {{
put("type", "stop");
put("stop_words", Arrays.asList("a", "an", "for"));
}}));
const analyzer_params = {
"tokenizer": "standard",
"filter": [
"lowercase",
{
"type": "stop",
"stop_words": ["a", "an", "for"]
}
]
};
analyzerParams = map[string]any{"tokenizer": "standard",
"filter": []any{"lowercase", map[string]any{
"type": "stop",
"stop_words": []string{"a", "an", "for"},
}}}
export analyzerParams='{
"type": "standard",
"filter": [
"lowercase",
{
"type": "stop",
"stop_words": ["a", "an", "for"]
}
]
}'
Zilliz Cloud には、特定のテキスト処理ニーズに合わせて設計された以下の組み込みアナライザーが用意されています。
-
standard: 汎用的なテキスト処理に適しており、標準的なトークン化と小文字フィルタリングを適用します。 -
english: 英語テキスト向けに最適化されており、英語のストップワードに対応しています。 -
chinese: 中国語テキストの処理に特化しており、中国語の言語構造に合わせたトークン化を含みます。
カスタムアナライザー
より高度なテキスト処理を行うには、Zilliz Cloud のカスタムアナライザーを使用して、トークナイザーとフィルターを指定することで、用途に合わせたテキスト処理パイプラインを構築できます。この設定は、細やかな制御が必要な特殊なユースケースに最適です。
トークナイザー
トークナイザーはカスタムアナライザーに必須のコンポーネントであり、入力テキストを個別の単位(トークン)に分割することでアナライザーパイプラインを開始します。トークン化は、ホワイトスペースや句読点による分割など、トークナイザーの種類に応じた特定のルールに従って行われます。これにより、各単語やフレーズをより正確かつ独立的に処理できます。
例えば、トークナイザーはテキスト "Vector データベース Built for Scale" を以下のような個別のトークンに変換します:
["Vector", "Database", "Built", "for", "Scale"]
トークナイザーを指定する例:
- Python
- Java
- NodeJS
- Go
- cURL
analyzer_params = {
"tokenizer": "whitespace",
}
Map<String, Object> analyzerParams = new HashMap<>();
analyzerParams.put("tokenizer", "whitespace");
const analyzer_params = {
"tokenizer": "whitespace",
};
analyzerParams = map[string]any{"tokenizer": "whitespace"}
export analyzerParams='{
"type": "whitespace"
}'
Filter
フィルターはトークナイザーによって生成されたトークンに対して機能するオプションのコンポーネントであり、必要に応じてそれらを変換または精製します。たとえば、トークン化された語 ["Vector", "データベース", "Built", "for", "Scale"] に lowercase フィルターを適用すると、結果は次のようになります:
["vector", "database", "built", "for", "scale"]
カスタムアナライザーのフィルターは、設定の必要に応じて組み込みまたはカスタムのいずれかになります。
-
組み込みフィルター: Zilliz Cloud によって事前設定されており、最小限のセットアップで使用できます。これらのフィルターは名前を指定するだけでそのまま利用可能です。以下のフィルターは組み込みフィルターとして直接使用できます:
-
lowercase: テキストを小文字に変換し、大文字・小文字を区別しないマッチングを実現します。詳細については、Lowercase を参照してください。 -
asciifolding: 非 ASCII 文字を ASCII の同等文字に変換し、多言語テキストの処理を簡素化します。詳細については、ASCII folding を参照してください。 -
alphanumonly: 英数字以外の文字を削除し、英数字のみを保持します。詳細については、アルファnumonly を参照してください。 -
cnalphanumonly: 中国語文字、英字、数字以外の文字を含むトークンを削除します。詳細については、Cnalphanumonly を参照してください。 -
cncharonly: 非中国語文字を含むトークンを削除します。詳細については、Cncharonly を参照してください。
組み込みフィルターの使用例:
- Python
- Java
- NodeJS
- Go
- cURL
analyzer_params = {
"tokenizer": "standard", # Mandatory: Specifies tokenizer
"filter": ["lowercase"], # Optional: Built-in filter that converts text to lowercase
}Map<String, Object> analyzerParams = new HashMap<>();
analyzerParams.put("tokenizer", "standard");
analyzerParams.put("filter", Collections.singletonList("lowercase"));const analyzer_params = {
"tokenizer": "standard", // Mandatory: Specifies tokenizer
"filter": ["lowercase"], // Optional: Built-in filter that converts text to lowercase
}analyzerParams = map[string]any{"tokenizer": "standard",
"filter": []any{"lowercase"}}export analyzerParams='{
"type": "standard",
"filter": ["lowercase"]
}' -
-
カスタムフィルター: カスタムフィルターを使用すると、特殊な設定が可能になります。有効なフィルターの種別(
filter.type)を選択し、各フィルターの種別に応じた具体的な設定を追加することで、カスタムフィルターを定義できます。カスタマイズをサポートするフィルターの種別の例を以下に示します。-
stop: ストップワードのリストを指定して、特定の一般的な単語を削除します(例:"stop_words": ["of", "to"])。詳細については、Stop を参照してください。 -
length: トークンの長さに基づいて除外を行います(例: 最大トークン長を設定するなど)。詳細については、Length を参照してください。 -
stemmer: 単語をその語幹(ルート形)に還元することで、より柔軟なマッチングを実現します。詳細については、Stemmer を参照してください。
カスタムフィルターの設定例:
- Python
- Java
- NodeJS
- Go
- cURL
analyzer_params = {
"tokenizer": "standard", # Mandatory: Specifies tokenizer
"filter": [
{
"type": "stop", # Specifies 'stop' as the filter type
"stop_words": ["of", "to"], # Customizes stop words for this filter type
}
]
}Map<String, Object> analyzerParams = new HashMap<>();
analyzerParams.put("tokenizer", "standard");
analyzerParams.put("filter",
Collections.singletonList(new HashMap<String, Object>() {{
put("type", "stop");
put("stop_words", Arrays.asList("a", "an", "for"));
}}));const analyzer_params = {
"tokenizer": "standard", // Mandatory: Specifies tokenizer
"filter": [
{
"type": "stop", // Specifies 'stop' as the filter type
"stop_words": ["of", "to"], // Customizes stop words for this filter type
}
]
};analyzerParams = map[string]any{"tokenizer": "standard",
"filter": []any{map[string]any{
"type": "stop",
"stop_words": []string{"of", "to"},
}}}export analyzerParams='{
"type": "standard",
"filter": [
{
"type": "stop",
"stop_words": ["a", "an", "for"]
}
]
}' -
nlohmann::json analyzer_params = {
{"type", "standard"},
{"filter", {{{"type", "stop"}, {"stop_words", {"a", "an", "for"}}}}},
};
使用例
この例では、以下の要素を含むコレクションスキーマを作成します。
- 埋め込み(embeddings)用のベクトルフィールド。
- テキスト処理用の2つの
VARCHARフィールド:- 1つのフィールドは組み込みアナライザーを使用します。
- もう1つのフィールドはカスタムアナライザーを使用します。
これらの設定をコレクションに組み込む前に、run_analyzer メソッドを使って各アナライザーを検証します。
ステップ 1: MilvusClient の初期化とスキーマの作成
まず、Milvus クライアントをセットアップし、新しいスキーマを作成します。
- Python
- Java
- NodeJS
- Go
- cURL
from pymilvus import MilvusClient, DataType
# Set up a Milvus client
client = MilvusClient(
uri="YOUR_CLUSTER_ENDPOINT",
token="YOUR_CLUSTER_TOKEN"
)
# Create a new schema
schema = client.create_schema(auto_id=True, enable_dynamic_field=False)
import io.milvus.v2.client.ConnectConfig;
import io.milvus.v2.client.MilvusClientV2;
import io.milvus.v2.common.DataType;
import io.milvus.v2.common.IndexParam;
import io.milvus.v2.service.collection.request.AddFieldReq;
import io.milvus.v2.service.collection.request.CreateCollectionReq;
// Set up a Milvus client
ConnectConfig config = ConnectConfig.builder()
.uri("YOUR_CLUSTER_ENDPOINT")
.token("YOUR_CLUSTER_TOKEN")
.build();
MilvusClientV2 client = new MilvusClientV2(config);
// Create schema
CreateCollectionReq.CollectionSchema schema = CreateCollectionReq.CollectionSchema.builder()
.enableDynamicField(false)
.build();
import { MilvusClient, DataType } from "@zilliz/milvus2-sdk-node";
// Set up a Milvus client
const client = new MilvusClient({
address: "YOUR_CLUSTER_ENDPOINT",
token: "YOUR_CLUSTER_TOKEN"
);
import (
"context"
"fmt"
"github.com/milvus-io/milvus/client/v2/column"
"github.com/milvus-io/milvus/client/v2/entity"
"github.com/milvus-io/milvus/client/v2/index"
"github.com/milvus-io/milvus/client/v2/milvusclient"
)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
cli, err := milvusclient.New(ctx, &milvusclient.ClientConfig{
Address: "YOUR_CLUSTER_ENDPOINT",
token: "YOUR_CLUSTER_TOKEN"
})
if err != nil {
fmt.Println(err.Error())
// handle err
}
defer client.Close(ctx)
schema := entity.NewSchema().WithAutoID(true).WithDynamicFieldEnabled(false)
# restful
export MILVUS_HOST="YOUR_CLUSTER_ENDPOINT"
export MILVUS_TOKEN="YOUR_CLUSTER_TOKEN"
curl -X POST "http://${MILVUS_HOST}/v2/vectordb/collections/create" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${MILVUS_TOKEN}" \
-d '{
"collectionName": "my_collection",
"dimension": 768,
"schema": {
"autoId": true,
"enableDynamicField": false
}
}'
ステップ 2: アナライザーの設定を定義および検証する
-
組み込みアナライザー(
english)の設定と検証:-
設定: 組み込みの英語アナライザー用にアナライザーのパラメータを定義します。
-
検証:
run_analyzerを使用して、設定が期待されるトークン化を生成することを確認します。
- Python
- Java
- NodeJS
- Go
- cURL
# Built-in analyzer configuration for English text processing
analyzer_params_built_in = {
"type": "english"
}
# Verify built-in analyzer configuration
sample_text = "Milvus simplifies text analysis for search."
result = client.run_analyzer(sample_text, analyzer_params_built_in)
print("Built-in analyzer output:", result)
# Expected output:
# Built-in analyzer output: ['milvus', 'simplifi', 'text', 'analysi', 'search']Map<String, Object> analyzerParamsBuiltin = new HashMap<>();
analyzerParamsBuiltin.put("type", "english");
List<String> texts = new ArrayList<>();
texts.add("Milvus simplifies text analysis for search.");
RunAnalyzerResp resp = client.runAnalyzer(RunAnalyzerReq.builder()
.texts(texts)
.analyzerParams(analyzerParamsBuiltin)
.build());
List<RunAnalyzerResp.AnalyzerResult> results = resp.getResults();// Use a built-in analyzer for VARCHAR field `title_en`
const analyzer_params_built_in = {
type: "english",
};
const sample_text = "Milvus simplifies text analysis for search.";
const result = await client.run_analyzer({
text: sample_text,
analyzer_params: analyzer_params_built_in
});analyzerParamsBuiltin := map[string]any{"type": "english"}
bs, _ := json.Marshal(analyzerParamsBuiltin)
texts := []string{"Milvus simplifies text analysis for search."}
option := milvusclient.NewRunAnalyzerOption(texts).
WithAnalyzerParams(string(bs))
result, err := client.RunAnalyzer(ctx, option)
if err != nil {
fmt.Println(err.Error())
// handle error
}# restful
export MILVUS_HOST="YOUR_CLUSTER_ENDPOINT"
export SAMPLE_TEXT="Milvus simplifies text analysis for search."
curl -X POST "http://${MILVUS_HOST}/v2/vectordb/common/run_analyzer" \
-H "Content-Type: application/json" \
-d '{
"text": ["'"${SAMPLE_TEXT}"'"],
"analyzerParams": "{\"type\":\"english\"}"
}' -
-
カスタムアナライザーの設定と検証:
-
設定: 標準のトークナイザーと組み込みの lowercase フィルター、およびトークン長とストップワード用のカスタムフィルターを使用するカスタムアナライザーを定義します。
-
検証:
run_analyzerを使用して、カスタム設定が意図通りにテキストを処理することを確認します。
- Python
- Java
- NodeJS
- Go
- cURL
# Custom analyzer configuration with a standard tokenizer and custom filters
analyzer_params_custom = {
"tokenizer": "standard",
"filter": [
"lowercase", # Built-in filter: convert tokens to lowercase
{
"type": "length", # Custom filter: restrict token length
"max": 40
},
{
"type": "stop", # Custom filter: remove specified stop words
"stop_words": ["of", "for"]
}
]
}
# Verify custom analyzer configuration
sample_text = "Milvus provides flexible, customizable analyzers for robust text processing."
result = client.run_analyzer(sample_text, analyzer_params_custom)
print("Custom analyzer output:", result)
# Expected output:
# Custom analyzer output: ['milvus', 'provides', 'flexible', 'customizable', 'analyzers', 'robust', 'text', 'processing']// Configure a custom analyzer
Map<String, Object> analyzerParamsCustom = new HashMap<>();
analyzerParamsCustom.put("tokenizer", "standard");
analyzerParamsCustom.put("filter",
Arrays.asList("lowercase",
new HashMap<String, Object>() {{
put("type", "length");
put("max", 40);
}},
new HashMap<String, Object>() {{
put("type", "stop");
put("stop_words", Arrays.asList("of", "for"));
}}
)
);
List<String> texts = new ArrayList<>();
texts.add("Milvus provides flexible, customizable analyzers for robust text processing.");
RunAnalyzerResp resp = client.runAnalyzer(RunAnalyzerReq.builder()
.texts(texts)
.analyzerParams(analyzerParamsCustom)
.build());
List<RunAnalyzerResp.AnalyzerResult> results = resp.getResults();// Configure a custom analyzer for VARCHAR field `title`
const analyzer_params_custom = {
tokenizer: "standard",
filter: [
"lowercase",
{
type: "length",
max: 40,
},
{
type: "stop",
stop_words: ["of", "to"],
},
],
};
const sample_text = "Milvus provides flexible, customizable analyzers for robust text processing.";
const result = await client.run_analyzer({
text: sample_text,
analyzer_params: analyzer_params_custom
});analyzerParamsCustom = map[string]any{"tokenizer": "standard",
"filter": []any{"lowercase",
map[string]any{
"type": "length",
"max": 40,
map[string]any{
"type": "stop",
"stop_words": []string{"of", "to"},
}}}
bs, _ := json.Marshal(analyzerParamsCustom)
texts := []string{"Milvus provides flexible, customizable analyzers for robust text processing."}
option := milvusclient.NewRunAnalyzerOption(texts).
WithAnalyzerParams(string(bs))
result, err := client.RunAnalyzer(ctx, option)
if err != nil {
fmt.Println(err.Error())
// handle error
}# curl
export MILVUS_HOST="YOUR_CLUSTER_ENDPOINT"
export SAMPLE_TEXT="Milvus provides flexible, customizable analyzers for robust text processing."
# 使用自定义分析器配置
curl -X POST "http://${MILVUS_HOST}/v2/vectordb/common/run_analyzer" \
-H "Content-Type: application/json" \
-d '{
"text": ["'"${SAMPLE_TEXT}"'"],
"analyzerParams": "{\"tokenizer\":\"standard\",\"filter\":[\"lowercase\",{\"type\":\"length\",\"max\":40},{\"type\":\"stop\",\"stop_words\":[\"of\",\"for\"]}]}"
}' -
ステップ 3: スキーマフィールドにアナライザーを追加する
アナライザーの設定を確認できたので、スキーマフィールドにそれらを追加します:
- Python
- Java
- NodeJS
- Go
- cURL
# Add VARCHAR field 'title_en' using the built-in analyzer configuration
schema.add_field(
field_name='title_en',
datatype=DataType.VARCHAR,
max_length=1000,
enable_analyzer=True,
analyzer_params=analyzer_params_built_in,
enable_match=True,
)
# Add VARCHAR field 'title' using the custom analyzer configuration
schema.add_field(
field_name='title',
datatype=DataType.VARCHAR,
max_length=1000,
enable_analyzer=True,
analyzer_params=analyzer_params_custom,
enable_match=True,
)
# Add a vector field for embeddings
schema.add_field(field_name="embedding", datatype=DataType.FLOAT_VECTOR, dim=3)
# Add a primary key field
schema.add_field(field_name="id", datatype=DataType.INT64, is_primary=True)
schema.addField(AddFieldReq.builder()
.fieldName("title_en")
.dataType(DataType.VarChar)
.maxLength(1000)
.enableAnalyzer(true)
.analyzerParams(analyzerParamsBuiltin)
.enableMatch(true) // must enable this if you use TextMatch
.build());
schema.addField(AddFieldReq.builder()
.fieldName("title")
.dataType(DataType.VarChar)
.maxLength(1000)
.enableAnalyzer(true)
.analyzerParams(analyzerParamsCustom)
.enableMatch(true) // must enable this if you use TextMatch
.build());
// Add vector field
schema.addField(AddFieldReq.builder()
.fieldName("embedding")
.dataType(DataType.FloatVector)
.dimension(3)
.build());
// Add primary field
schema.addField(AddFieldReq.builder()
.fieldName("id")
.dataType(DataType.Int64)
.isPrimaryKey(true)
.autoID(true)
.build());
// Create schema
const schema = {
auto_id: true,
fields: [
{
name: "id",
type: DataType.INT64,
is_primary: true,
},
{
name: "title_en",
data_type: DataType.VARCHAR,
max_length: 1000,
enable_analyzer: true,
analyzer_params: analyzerParamsBuiltIn,
enable_match: true,
},
{
name: "title",
data_type: DataType.VARCHAR,
max_length: 1000,
enable_analyzer: true,
analyzer_params: analyzerParamsCustom,
enable_match: true,
},
{
name: "embedding",
data_type: DataType.FLOAT_VECTOR,
dim: 4,
},
],
};
schema.WithField(entity.NewField().
WithName("id").
WithDataType(entity.FieldTypeInt64).
WithIsPrimaryKey(true).
WithIsAutoID(true),
).WithField(entity.NewField().
WithName("embedding").
WithDataType(entity.FieldTypeFloatVector).
WithDim(3),
).WithField(entity.NewField().
WithName("title_en").
WithDataType(entity.FieldTypeVarChar).
WithMaxLength(1000).
WithEnableAnalyzer(true).
WithAnalyzerParams(analyzerParamsBuiltin).
WithEnableMatch(true),
).WithField(entity.NewField().
WithName("title").
WithDataType(entity.FieldTypeVarChar).
WithMaxLength(1000).
WithEnableAnalyzer(true).
WithAnalyzerParams(analyzerParamsCustom).
WithEnableMatch(true),
)
# restful
export SCHEMA_CONFIG='{
"autoId": false,
"enableDynamicField": false,
"fields": [
{
"fieldName": "id",
"dataType": "Int64",
"isPrimary": true
},
{
"fieldName": "title_en",
"dataType": "VarChar",
"elementTypeParams": {
"max_length": "1000",
"enable_analyzer": true,
"analyzer_params": "{\"type\":\"english\"}",
"enable_match": true
}
},
{
"fieldName": "title",
"dataType": "VarChar",
"elementTypeParams": {
"max_length": "1000",
"enable_analyzer": true,
"analyzer_params": "{\"tokenizer\":\"standard\",\"filter\":[\"lowercase\",{\"type\":\"length\",\"max\":40},{\"type\":\"stop\",\"stop_words\":[\"of\",\"for\"]}]}",
"enable_match": true
}
},
{
"fieldName": "embedding",
"dataType": "FloatVector",
"elementTypeParams": {
"dim": "3"
}
}
]
}'
ステップ 4: インデックスパラメータを準備してコレクションを作成する
- Python
- Java
- NodeJS
- Go
- cURL
# Set up index parameters for the vector field
index_params = client.prepare_index_params()
index_params.add_index(field_name="embedding", metric_type="COSINE", index_type="AUTOINDEX")
# Create the collection with the defined schema and index parameters
client.create_collection(
collection_name="my_collection",
schema=schema,
index_params=index_params
)
// Set up index params for vector field
List<IndexParam> indexes = new ArrayList<>();
indexes.add(IndexParam.builder()
.fieldName("embedding")
.indexType(IndexParam.IndexType.AUTOINDEX)
.metricType(IndexParam.MetricType.COSINE)
.build());
// Create collection with defined schema
CreateCollectionReq requestCreate = CreateCollectionReq.builder()
.collectionName("my_collection")
.collectionSchema(schema)
.indexParams(indexes)
.build();
client.createCollection(requestCreate);
// Set up index params for vector field
const indexParams = [
{
name: "embedding",
metric_type: "COSINE",
index_type: "AUTOINDEX",
},
];
// Create collection with defined schema
await client.createCollection({
collection_name: "my_collection",
schema: schema,
index_params: indexParams,
});
console.log("Collection created successfully!");
idx := index.NewAutoIndex(index.MetricType(entity.COSINE))
indexOption := milvusclient.NewCreateIndexOption("my_collection", "embedding", idx)
err = client.CreateCollection(ctx,
milvusclient.NewCreateCollectionOption("my_collection", schema).
WithIndexOptions(indexOption))
if err != nil {
fmt.Println(err.Error())
// handle error
}
export INDEX_PARAMS='[{"fieldName": "embedding", "metricType": "COSINE", "indexType": "AUTOINDEX"}]'
# restful
curl -X POST "YOUR_CLUSTER_ENDPOINT/v2/vectordb/collections/create" \
-H "Content-Type: application/json" \
-d "{
\"collectionName\": \"my_collection\",
\"schema\": ${SCHEMA_CONFIG},
\"indexParams\": ${INDEX_PARAMS}
}"
Zilliz Cloud コンソールでの使用例
上記の操作は、Zilliz Cloud コンソールからも実行できます。詳細については、以下のデモをご覧ください。
次のステップ
アナライザーを設定する際には、ユースケースに最も適した設定を決定するために、以下のベストプラクティス記事をお読みいただくことをおすすめします。
アナライザーの設定後は、Zilliz Cloud が提供するテキスト検索機能と統合できます。詳細については、以下をご参照ください。