Alphanumonly
alphanumonly フィルターは、ASCII 以外の文字を含むトークンを削除し、英数字の用語のみを保持します。このフィルターは、基本的な英字と数字のみが対象で、特殊文字や記号を除外するテキストの処理に役立ちます。
設定
alphanumonly フィルターは Zilliz Cloud に組み込まれています。使用するには、analyzer_params 内の filter セクションにその名前を指定するだけです。
- Python
- Java
- Go
- Rust
- C++
- NodeJS
- CSharp
- cURL
python
analyzer_params = {
"tokenizer": "standard",
"filter": ["alphanumonly"],
}
java
Map<String, Object> analyzerParams = new HashMap<>();
analyzerParams.put("tokenizer", "standard");
analyzerParams.put("filter", Collections.singletonList("alphanumonly"));
go
analyzerParams := map[string]any{"tokenizer": "standard", "filter": []any{"alphanumonly"}}
rust
let analyzer_params = serde_json::json!({
"tokenizer": "standard",
"filter": ["alphanumonly"]
});
c++
#include <milvus/thirdparty/nlohmann/json.hpp>
nlohmann::json analyzer_params = {
{"tokenizer", "standard"},
{"filter", {"alphanumonly"}}
};
javascript
const analyzer_params = {
"tokenizer": "standard",
"filter": ["alphanumonly"],
};
csharp
using System.Collections.Generic;
Dictionary<string, object> analyzerParams = new()
{
["tokenizer"] = "standard",
["filter"] = new List<object> { "alphanumonly" }
};
bash
# restful
analyzerParams='{
"tokenizer": "standard",
"filter": [
"alphanumonly"
]
}'
alphanumonly フィルターはトークナイザーによって生成された用語に対して動作するため、トークナイザーと組み合わせて使用する必要があります。Zilliz Cloud で使用可能なトークナイザーの一覧については、Standard Tokenizer とその関連ページを参照してください。
analyzer_params を定義したら、コレクションスキーマを定義するときに、それを VARCHAR フィールドに適用できます。これにより、Zilliz Cloud は指定されたアナライザーを使用してそのフィールド内のテキストを処理し、効率的なトークン化とフィルタリングを行えます。詳細は、Example use を参照してください。
例
アナライザーの構成をコレクションスキーマに適用する前に、run_analyzer メソッドを使用してその動作を検証してください。
アナライザーの構成
- Python
- Java
- Go
- Rust
- C++
- NodeJS
- CSharp
- cURL
python
analyzer_params = {
"tokenizer": "standard",
"filter": ["alphanumonly"],
}
java
Map<String, Object> analyzerParams = new HashMap<>();
analyzerParams.put("tokenizer", "standard");
analyzerParams.put("filter", Collections.singletonList("alphanumonly"));
go
analyzerParams := map[string]any{"tokenizer": "standard", "filter": []any{"alphanumonly"}}
rust
let analyzer_params = serde_json::json!({
"tokenizer": "standard",
"filter": ["alphanumonly"]
});
c++
#include <milvus/thirdparty/nlohmann/json.hpp>
nlohmann::json analyzer_params = {
{"tokenizer", "standard"},
{"filter", {"alphanumonly"}}
};
javascript
const analyzer_params = {
"tokenizer": "standard",
"filter": ["alphanumonly"],
};
csharp
using System.Collections.Generic;
Dictionary<string, object> analyzerParams = new()
{
["tokenizer"] = "standard",
["filter"] = new List<object> { "alphanumonly" }
};
bash
# restful
analyzerParams='{
"tokenizer": "standard",
"filter": [
"alphanumonly"
]
}'
run_analyzer を使用した検証
- Python
- Java
- Go
- Rust
- C++
- NodeJS
- CSharp
- cURL
python
from pymilvus import (
MilvusClient,
)
client = MilvusClient(
uri="YOUR_CLUSTER_ENDPOINT",
token="YOUR_CLUSTER_TOKEN"
)
# Sample text to analyze
sample_text = "Milvus 2.0 @ Scale! #AI #Vector_Databasé"
# Run the standard analyzer with the defined configuration
result = client.run_analyzer(sample_text, analyzer_params)
print("Standard analyzer output:", result)
java
import java.util.*;
import io.milvus.v2.client.ConnectConfig;
import io.milvus.v2.client.MilvusClientV2;
import io.milvus.v2.service.vector.request.RunAnalyzerReq;
import io.milvus.v2.service.vector.response.RunAnalyzerResp;
ConnectConfig config = ConnectConfig.builder()
.uri("YOUR_CLUSTER_ENDPOINT")
.token("YOUR_CLUSTER_TOKEN")
.build();
MilvusClientV2 client = new MilvusClientV2(config);
List<String> texts = new ArrayList<>();
texts.add("Milvus 2.0 @ Scale! #AI #Vector_Databasé");
RunAnalyzerResp resp = client.runAnalyzer(RunAnalyzerReq.builder()
.texts(texts)
.analyzerParams(analyzerParams)
.build());
List<RunAnalyzerResp.AnalyzerResult> results = resp.getResults();
go
import (
"context"
"fmt"
"github.com/milvus-io/milvus/client/v3/milvusclient"
)
ctx := context.Background()
client, err := milvusclient.New(ctx, &milvusclient.ClientConfig{
Address: "YOUR_CLUSTER_ENDPOINT",
APIKey: "YOUR_CLUSTER_TOKEN",
})
if err != nil {
fmt.Println(err.Error())
// handle error
}
texts := []string{"Milvus 2.0 @ Scale! #AI #Vector_Databasé"}
option := milvusclient.NewRunAnalyzerOption(texts...).
WithAnalyzerParams(analyzerParams)
result, err := client.RunAnalyzer(ctx, option)
if err != nil {
fmt.Println(err.Error())
// handle error
}
for _, r := range result {
for _, token := range r.Tokens {
fmt.Println(token.Text)
}
}
rust
use milvus::v2::error::Result;
use milvus::v2::prelude::*;
let config = ConnectConfig::new().uri("YOUR_CLUSTER_ENDPOINT").token("YOUR_CLUSTER_TOKEN");
let client = ClientV2::new(&config).await?;
let analyzer_params = serde_json::json!({
"tokenizer": "standard",
"filter": ["alphanumonly"]
});
let sample_text = "Milvus 2.0 @ Scale! #AI #Vector_Databasé";
let result = client
.run_analyzer(
RunAnalyzerRequest::builder()
.texts(vec![sample_text])
.analyzer_params(analyzer_params)
.build()?,
)
.await?;
println!("Standard analyzer output: {:?}", result.results());
c++
#include "milvus/MilvusClientV2.h"
#include <iostream>
#include <string>
auto client = milvus::MilvusClientV2::Create();
milvus::ConnectParam connect_param{"YOUR_CLUSTER_ENDPOINT", "YOUR_CLUSTER_TOKEN"};
auto status = client->Connect(connect_param);
if (!status.IsOk()) {
std::cout << status.Message() << std::endl;
}
std::string text = "Milvus 2.0 @ Scale! #AI #Vector_Databasé";
auto request = milvus::RunAnalyzerRequest()
.AddText(text)
.WithAnalyzerParams(analyzer_params);
milvus::RunAnalyzerResponse response;
status = client->RunAnalyzer(request, response);
if (!status.IsOk()) {
std::cout << status.Message() << std::endl;
}
javascript
import { MilvusClient } from "@zilliz/milvus2-sdk-node";
const client = new MilvusClient({ address: "YOUR_CLUSTER_ENDPOINT", token: "YOUR_CLUSTER_TOKEN" });
const sampleText = "Milvus 2.0 @ Scale! #AI #Vector_Databasé";
const result = await client.runAnalyzer({
text: sampleText,
analyzer_params,
});
console.log("Standard analyzer output:", result);
csharp
using System;
using Milvus.Client.V2;
using Milvus.Client.V2.Requests.Utility;
using Milvus.Client.V2.Responses.Utility;
using Milvus.Client.V2.Types;
MilvusClientV2 client = new(new ConnectConfig
{
Uri = "YOUR_CLUSTER_ENDPOINT",
ApiKey = "YOUR_CLUSTER_TOKEN"
});
// Sample text to analyze
string sampleText = "Milvus 2.0 @ Scale! #AI #Vector_Databasé";
// Run the standard analyzer with the defined configuration
RunAnalyzerResp result = await client.RunAnalyzerAsync(new RunAnalyzerReq
{
AnalyzerParams = analyzerParams,
Texts = [sampleText]
});
foreach (AnalyzerResult r in result.Results)
{
foreach (AnalyzerToken t in r.Tokens)
{
Console.WriteLine($"Standard analyzer output: {t.Token}");
}
}
bash
export CLUSTER_ENDPOINT="YOUR_CLUSTER_ENDPOINT"
export TOKEN="YOUR_CLUSTER_TOKEN"
curl --request POST \
--url "${CLUSTER_ENDPOINT}/v2/vectordb/common/run_analyzer" \
--header "Authorization: Bearer ${TOKEN}" \
--header "Content-Type: application/json" \
--header "Request-Timeout: 10" \
-d '{
"text": ["Milvus 2.0 @ Scale! #AI #Vector_Databasé"],
"analyzerParams": "{\"tokenizer\": \"standard\", \"filter\": [\"alphanumonly\"]}"
}'
期待される出力
python
['Milvus', '2', '0', 'Scale', 'AI', 'Vector']