Alphanumonly
alphanumonly フィルターは、非 ASCII 文字を含むトークンを削除し、英数字の用語のみを保持します。このフィルターは、基本的な文字と数字のみが関連するテキストを扱う際に、特殊文字や記号を除外するのに役立ちます。
設定
alphanumonly フィルターは Zilliz Cloud に組み込まれています。これを使用するには、analyzer_params 内の filter セクションでその名前を指定するだけです。
- Python
- Java
- Go
- Rust
- C++
- NodeJS
- cURL
python
analyzer_params = {
"tokenizer": "standard",
"filter": ["alphanumonly"],
}
java
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
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++
nlohmann::json analyzer_params = {
{"tokenizer", "standard"},
{"filter", {"alphanumonly"}}
};
javascript
const analyzer_params = {
"tokenizer": "standard",
"filter": ["alphanumonly"],
};
bash
# restful
analyzerParams='{
"tokenizer": "standard",
"filter": [
"alphanumonly"
]
}'
alphanumonly フィルターは tokenizer によって生成された用語に対して動作するため、tokenizer と組み合わせて使用する必要があります。Zilliz Cloud で利用可能な tokenizer の一覧については、Standard Tokenizer およびその関連ページを参照してください。
analyzer_params を定義した後は、コレクションスキーマを定義する際にそれらを VARCHAR フィールドへ適用できます。これにより、Zilliz Cloud は効率的なトークン化とフィルタリングのために、そのフィールド内のテキストを指定されたアナライザーを使用して処理できます。詳細については、使用例 を参照してください。
例
アナライザー設定をコレクションスキーマに適用する前に、run_analyzer メソッドを使用してその動作を確認してください。
アナライザー設定
- Python
- Java
- Go
- Rust
- C++
- NodeJS
- cURL
python
analyzer_params = {
"tokenizer": "standard",
"filter": ["alphanumonly"],
}
java
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
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++
nlohmann::json analyzer_params = {
{"tokenizer", "standard"},
{"filter", {"alphanumonly"}}
};
javascript
const analyzer_params = {
"tokenizer": "standard",
"filter": ["alphanumonly"],
};
bash
# restful
analyzerParams='{
"tokenizer": "standard",
"filter": [
"alphanumonly"
]
}'
run_analyzer を使用した検証
- Python
- Java
- Go
- Rust
- C++
- NodeJS
- 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 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;
import java.util.ArrayList;
import java.util.List;
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("Standard analyzer output:", token.Text)
}
}
rust
use milvus::v2::error::Result;
use milvus::v2::prelude::*;
#[tokio::main]
async fn main() -> Result<()> {
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());
Ok(())
}
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);
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']