ICUCompatible with Milvus 2.5.11+
icu 토큰화기는 소프트웨어 국제화를 위한 핵심 도구를 제공하는 오픈소스 프로젝트 인 유니코드 국제화 구성 요소 (ICU) 를 기반으로 구축되었습니다. ICU의 단어 분할 알고리즘을 사용하여, 이 토큰화기는 전 세계 대부분의 언어에서 텍스트를 단어로 정확하게 분할할 수 있습니다.
icu 토큰화기는 출력 결과에서 구두점과 공백을 별도의 토큰으로 유지합니다. 예를 들어, “ "Привет! Как дела?" ”는 “ ["Привет", "!", " ", "Как", " ", "дела", "?"] ”로 변환됩니다. 이러한 독립된 구두점 토큰을 제거하려면 removepunct 필터를 사용하십시오.
구성
icu 토큰화기를 사용하여 분석기를 구성하려면, analyzer_params 에서 tokenizer 를 icu 로 설정하십시오.
analyzer_params = {
"tokenizer": "icu",
}
Map<String, Object> analyzerParams = new HashMap<>();
analyzerParams.put("tokenizer", "icu");
analyzerParams := map[string]any{"tokenizer": "icu"}
use milvus::v2::prelude::*;
use serde_json::json;
let analyzer_params = json!({ "tokenizer": "icu" });
nlohmann::json analyzer_params = {
{"tokenizer", "icu"}
};
const analyzer_params = {
tokenizer: "icu",
};
# restful
analyzerParams='{
"tokenizer": "icu"
}'
icu 토큰화기는 하나 이상의 필터와 함께 작동할 수 있습니다. 예를 들어, 다음 코드는 icu 토큰화기와 remove punct 필터를 사용하는 분석기를 정의합니다:
analyzer_params = {
"tokenizer": "icu",
"filter": ["removepunct"]
}
Map<String, Object> analyzerParams = new HashMap<>();
analyzerParams.put("tokenizer", "icu");
analyzerParams.put("filter", Collections.singletonList("removepunct"));
analyzerParams := map[string]any{"tokenizer": "icu", "filter": []string{"removepunct"}}
use milvus::v2::prelude::*;
use serde_json::json;
let analyzer_params = json!({
"tokenizer": "icu",
"filter": ["removepunct"]
});
nlohmann::json analyzer_params = {
{"tokenizer", "icu"},
{"filter", {"removepunct"}}
};
const analyzer_params = {
tokenizer: "icu",
filter: ["removepunct"],
};
# restful
analyzerParams='{
"tokenizer": "icu",
"filter": ["removepunct"]
}'
analyzer_params 를 정의한 후에는 컬렉션 스키마를 정의할 때 VARCHAR 필드에 이를 적용할 수 있습니다. 이를 통해 Milvus는 지정된 분석기를 사용하여 해당 필드의 텍스트를 처리함으로써 효율적인 토큰화 및 필터링을 수행할 수 있습니다. 자세한 내용은 사용 예제를 참조하십시오.
예시
분석기 구성을 컬렉션 스키마에 적용하기 전에, ` run_analyzer ` 메서드를 사용하여 동작을 확인해 보십시오.
분석기 구성
analyzer_params = {
"tokenizer": "icu",
}
Map<String, Object> analyzerParams = new HashMap<>();
analyzerParams.put("tokenizer", "icu");
analyzerParams := map[string]any{"tokenizer": "icu"}
use milvus::v2::prelude::*;
use serde_json::json;
let analyzer_params = json!({ "tokenizer": "icu" });
nlohmann::json analyzer_params = {
{"tokenizer", "icu"}
};
const analyzer_params = {
tokenizer: "icu",
};
# restful
analyzerParams='{
"tokenizer": "icu"
}'
다음 방법을 사용한 검증 run_analyzer
from pymilvus import (
MilvusClient,
)
client = MilvusClient(
uri="http://localhost:19530",
token="root:Milvus"
)
# Sample text to analyze
sample_text = "Привет! Как дела?"
# Run the icu analyzer with the defined configuration
result = client.run_analyzer(sample_text, analyzer_params)
print("ICU analyzer output:", result)
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("http://localhost:19530")
.token("root:Milvus")
.build();
MilvusClientV2 client = new MilvusClientV2(config);
List<String> texts = new ArrayList<>();
texts.add("Привет! Как дела?");
RunAnalyzerResp resp = client.runAnalyzer(RunAnalyzerReq.builder()
.texts(texts)
.analyzerParams(analyzerParams)
.build());
List<RunAnalyzerResp.AnalyzerResult> results = resp.getResults();
import (
"context"
"fmt"
"github.com/milvus-io/milvus/client/v3/milvusclient"
)
ctx := context.Background()
client, err := milvusclient.New(ctx, &milvusclient.ClientConfig{
Address: "http://localhost:19530",
APIKey: "root:Milvus",
})
if err != nil {
fmt.Println(err.Error())
// handle error
}
texts := []string{"Привет! Как дела?"}
option := milvusclient.NewRunAnalyzerOption(texts...).
WithAnalyzerParams(analyzerParams)
result, err := client.RunAnalyzer(ctx, option)
if err != nil {
fmt.Println(err.Error())
// handle error
}
use milvus::v2::prelude::*;
use serde_json::json;
let config = ConnectConfig::new().uri("http://localhost:19530").token("root:Milvus");
let client = ClientV2::new(&config).await?;
let analyzer_params = json!({ "tokenizer": "icu" });
let result = client
.run_analyzer(
RunAnalyzerRequest::builder()
.texts(vec!["Привет! Как дела?"])
.analyzer_params(analyzer_params)
.build()?,
)
.await?;
println!("ICU analyzer output: {:?}", result.results());
#include "milvus/MilvusClientV2.h"
#include <iostream>
auto client = milvus::MilvusClientV2::Create();
milvus::ConnectParam connect_param{"http://localhost:19530", "root:Milvus"};
auto status = client->Connect(connect_param);
if (!status.IsOk()) {
std::cout << status.Message() << std::endl;
}
std::string text = "Привет! Как дела?";
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;
}
import { MilvusClient } from "@zilliz/milvus2-sdk-node";
const client = new MilvusClient({
address: "http://localhost:19530",
token: "root:Milvus",
});
const sample_text = "Привет! Как дела?";
// Run the icu analyzer with the defined configuration
const result = await client.runAnalyzer({
text: sample_text,
analyzer_params,
});
console.log("ICU analyzer output:", result);
# restful
curl --request POST \
--url "http://localhost:19530/v2/vectordb/common/run_analyzer" \
--header "Authorization: Bearer root:Milvus" \
--header "Content-Type: application/json" \
-d '{
"text": ["Привет! Как дела?"],
"analyzerParams": "{\"tokenizer\": \"icu\"}"
}'
예상 출력
['Привет', '!', ' ', 'Как', ' ', 'дела', '?']