Inglese

L'analizzatore english di Milvus è progettato per elaborare testi in inglese, applicando regole specifiche per la lingua per la tokenizzazione e il filtraggio.

Definizione

L'analizzatore english utilizza i seguenti componenti:

  • Tokenizzatore: Utilizza il tokenizer di standard per suddividere il testo in unità di parole discrete.

  • Filtri: Include diversi filtri per un'elaborazione completa del testo:

    • lowercase: Converte tutti i token in minuscolo, consentendo ricerche senza distinzione tra maiuscole e minuscole.

    • stemmer: Riduce le parole alla loro forma radicale per supportare una corrispondenza più ampia (ad esempio, "running" diventa "run").

    • stop_words: Rimuove le comuni stop words inglesi per concentrarsi sui termini chiave del testo.

La funzionalità dell'analizzatore english è equivalente alla seguente configurazione personalizzata dell'analizzatore:

analyzer_params = {
        "tokenizer": "standard",
        "filter": [
                "lowercase",
                {
                        "type": "stemmer",
                        "language": "english"
                }, {
                        "type": "stop",
                        "stop_words": "_english_"
                }
        ]
}
Map<String, Object> analyzerParams = new HashMap<>();
analyzerParams.put("tokenizer", "standard");
analyzerParams.put("filter",
        Arrays.asList("lowercase",
                new HashMap<String, Object>() {{
                    put("type", "stemmer");
                    put("language", "english");
                }},
                new HashMap<String, Object>() {{
                    put("type", "stop");
                    put("stop_words", Collections.singletonList("_english_"));
                }}
        )
);
const analyzer_params = {
    "type": "standard", // Specifies the standard analyzer type
    "stop_words", ["of"] // Optional: List of words to exclude from tokenization
}
analyzerParams = map[string]any{"tokenizer": "standard",
        "filter": []any{"lowercase", map[string]any{
            "type":     "stemmer",
            "language": "english",
        }, map[string]any{
            "type":       "stop",
            "stop_words": "_english_",
        }}}
# restful
analyzerParams='{
  "tokenizer": "standard",
  "filter": [
    "lowercase",
    {
      "type": "stemmer",
      "language": "english"
    },
    {
      "type": "stop",
      "stop_words": "_english_"
    }
  ]
}'

Configurazione

Per applicare l'analizzatore english a un campo, è sufficiente impostare type su english in analyzer_params e includere i parametri opzionali necessari.

analyzer_params = {
    "type": "english",
}
Map<String, Object> analyzerParams = new HashMap<>();
analyzerParams.put("type", "english");
const analyzer_params = {
    "type": "english",
}
analyzerParams = map[string]any{"type": "english"}
# restful
analyzerParams='{
  "type": "english"
}'

L'analizzatore english accetta i seguenti parametri opzionali:

Parametro

Descrizione

stop_words

Un array contenente un elenco di stop words, che saranno rimosse dalla tokenizzazione. L'impostazione predefinita è _english_, un insieme di stop word inglesi comuni.

Esempio di configurazione con stop word personalizzate:

analyzer_params = {
    "type": "english",
    "stop_words": ["a", "an", "the"]
}
Map<String, Object> analyzerParams = new HashMap<>();
analyzerParams.put("type", "english");
analyzerParams.put("stop_words", Arrays.asList("a", "an", "the"));
const analyzer_params = {
    "type": "english",
    "stop_words": ["a", "an", "the"]
}
analyzerParams = map[string]any{"type": "english", "stop_words": []string{"a", "an", "the"}}
# restful
analyzerParams='{
  "type": "english",
  "stop_words": [
    "a",
    "an",
    "the"
  ]
}'

Dopo aver definito analyzer_params, è possibile applicarle a un campo VARCHAR quando si definisce uno schema di raccolta. Ciò consente a Milvus di elaborare il testo in quel campo utilizzando l'analizzatore specificato per una tokenizzazione e un filtraggio efficienti. Per i dettagli, si veda l'esempio di utilizzo.

Esempi

Prima di applicare la configurazione dell'analizzatore allo schema di raccolta, verificarne il comportamento con il metodo run_analyzer.

Configurazione dell'analizzatore

analyzer_params = {
    "type": "english",
    "stop_words": ["a", "an", "the"]
}
Map<String, Object> analyzerParams = new HashMap<>();
analyzerParams.put("type", "english");
analyzerParams.put("stop_words", Arrays.asList("a", "an", "the"));
// javascript
analyzerParams = map[string]any{"type": "english", "stop_words": []string{"a", "an", "the"}}
# restful
analyzerParams='{
  "type": "english",
  "stop_words": [
    "a",
    "an",
    "the"
  ]
}'

Verifica con run_analyzerCompatible with Milvus 2.5.11+

from pymilvus import (
    MilvusClient,
)

client = MilvusClient(uri="http://localhost:19530")

# Sample text to analyze
sample_text = "Milvus is a vector database built for scale!"

# Run the standard analyzer with the defined configuration
result = client.run_analyzer(sample_text, analyzer_params)
print("English 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")
        .build();
MilvusClientV2 client = new MilvusClientV2(config);

List<String> texts = new ArrayList<>();
texts.add("Milvus is a vector database built for scale!");

RunAnalyzerResp resp = client.runAnalyzer(RunAnalyzerReq.builder()
        .texts(texts)
        .analyzerParams(analyzerParams)
        .build());
List<RunAnalyzerResp.AnalyzerResult> results = resp.getResults();
// javascript
import (
    "context"
    "encoding/json"
    "fmt"

    "github.com/milvus-io/milvus/client/v2/milvusclient"
)

client, err := milvusclient.New(ctx, &milvusclient.ClientConfig{
    Address: "localhost:19530",
    APIKey:  "root:Milvus",
})
if err != nil {
    fmt.Println(err.Error())
    // handle error
}

bs, _ := json.Marshal(analyzerParams)
texts := []string{"Milvus is a vector database built for scale!"}
option := milvusclient.NewRunAnalyzerOption(texts).
    WithAnalyzerParams(string(bs))

result, err := client.RunAnalyzer(ctx, option)
if err != nil {
    fmt.Println(err.Error())
    // handle error
}
# restful

Risultato atteso

English analyzer output: ['milvus', 'vector', 'databas', 'built', 'scale']

Try Managed Milvus for Free

Zilliz Cloud is hassle-free, powered by Milvus and 10x faster.

Get Started
Feedback

Questa pagina è stata utile?