Whitespace
The whitespace tokenizer splits text at five ASCII whitespace characters: tab, line feed, form feed, carriage return, and space.
Tokenization rules
The whitespace tokenizer splits text only at the following five ASCII whitespace characters:
| Character | Name | Unicode code point |
|---|---|---|
\t | Horizontal tab | U+0009 |
\n | Line feed | U+000A |
\x0C or \f | Form feed | U+000C |
\r | Carriage return | U+000D |
' ' | Space | U+0020 |
These separators are discarded, and consecutive separators do not produce empty tokens. Punctuation and other characters remain in the tokens. In particular, vertical tab (\x0B, U+000B), no-break space (\u00A0), and ideographic space (\u3000) do not trigger splitting.
This set follows Rust's char::is_ascii_whitespace(), which excludes other Unicode whitespace characters.
The following examples use {"tokenizer": "whitespace"} with no filters. Inputs and outputs use Python string notation: escape sequences such as \t and \u00A0 represent the actual characters.
| Input | Output tokens |
|---|---|
"a\tb\nc\x0Cd\re f" | ["a", "b", "c", "d", "e", "f"] |
"Hello,World! foo_bar" | ["Hello,World!", "foo_bar"] |
"a\x0Bb" | ["a\x0Bb"] |
"a\u00A0b" | ["a\u00A0b"] |
"a\u3000b" | ["a\u3000b"] |
"\x20a\x20\x20b\x20" | ["a", "b"] |
Configuration
To configure an analyzer using the whitespace tokenizer, set tokenizer to whitespace in analyzer_params.
- Python
- Java
- Go
- Rust
- C++
- NodeJS
- cURL
analyzer_params = {
"tokenizer": "whitespace",
}
Map<String, Object> analyzerParams = new HashMap<>();
analyzerParams.put("tokenizer", "whitespace");
analyzerParams := map[string]any{"tokenizer": "whitespace"}
let analyzer_params = serde_json::json!({"tokenizer": "whitespace"});
nlohmann::json analyzer_params = {
{"tokenizer", "whitespace"}
};
const analyzer_params = {
"tokenizer": "whitespace"
};
# restful
analyzerParams='{
"tokenizer": "whitespace"
}'
The whitespace tokenizer can work in conjunction with one or more filters. For example, the following code defines an analyzer that uses the whitespace tokenizer and lowercase filter:
- Python
- Java
- Go
- Rust
- C++
- NodeJS
- cURL
analyzer_params = {
"tokenizer": "whitespace",
"filter": ["lowercase"]
}
Map<String, Object> analyzerParams = new HashMap<>();
analyzerParams.put("tokenizer", "whitespace");
analyzerParams.put("filter", Collections.singletonList("lowercase"));
analyzerParams = map[string]any{"tokenizer": "whitespace", "filter": []any{"lowercase"}}
let analyzer_params = serde_json::json!({"tokenizer": "whitespace", "filter": ["lowercase"]});
nlohmann::json analyzer_params = {
{"tokenizer", "whitespace"},
{"filter", {"lowercase"}}
};
const analyzer_params = {
"tokenizer": "whitespace",
"filter": ["lowercase"]
};
# restful
analyzerParams='{
"tokenizer": "whitespace",
"filter": [
"lowercase"
]
}'
After defining analyzer_params, you can apply them to a VARCHAR field when defining a collection schema. This allows Zilliz Cloud to process the text in that field using the specified analyzer for efficient tokenization and filtering. For details, refer to Example use.
Examples
Before applying the analyzer configuration to your collection schema, verify its behavior using the run_analyzer method.
Analyzer configuration
- Python
- Java
- Go
- Rust
- C++
- NodeJS
- cURL
analyzer_params = {
"tokenizer": "whitespace",
"filter": ["lowercase"]
}
Map<String, Object> analyzerParams = new HashMap<>();
analyzerParams.put("tokenizer", "whitespace");
analyzerParams.put("filter", Collections.singletonList("lowercase"));
analyzerParams = map[string]any{"tokenizer": "whitespace", "filter": []any{"lowercase"}}
let analyzer_params = serde_json::json!({"tokenizer": "whitespace", "filter": ["lowercase"]});
nlohmann::json analyzer_params = {
{"tokenizer", "whitespace"},
{"filter", {"lowercase"}}
};
const analyzer_params = {
"tokenizer": "whitespace",
"filter": ["lowercase"]
};
# restful
analyzerParams='{
"tokenizer": "whitespace",
"filter": [
"lowercase"
]
}'
Verification using run_analyzer
- Python
- Java
- Go
- Rust
- C++
- NodeJS
- cURL
from pymilvus import (
MilvusClient,
)
client = MilvusClient(
uri="YOUR_CLUSTER_ENDPOINT",
token="YOUR_CLUSTER_TOKEN"
)
# Sample text to analyze
sample_text = "The Milvus vector database is built for scale!"
# Run the whitespace analyzer with the defined configuration
result = client.run_analyzer(sample_text, analyzer_params)
print("Whitespace 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;
import java.util.*;
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("The Milvus vector database is built for scale!");
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: "YOUR_CLUSTER_ENDPOINT",
APIKey: "YOUR_CLUSTER_TOKEN",
})
if err != nil {
fmt.Println(err.Error())
// handle error
}
texts := []string{"The Milvus vector database is built for scale!"}
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::*;
let client = ClientV2::new(&ConnectConfig::new().uri("YOUR_CLUSTER_ENDPOINT").token("YOUR_CLUSTER_TOKEN")).await?;
let sample_text = "The Milvus vector database is built for scale!";
client
.run_analyzer(
RunAnalyzerRequest::builder()
.texts([sample_text])
.analyzer_params(analyzer_params.clone())
.build()?,
)
.await?;
#include <iostream>
#include "milvus/MilvusClientV2.h"
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 = "The Milvus vector database is built for scale!";
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: "YOUR_CLUSTER_ENDPOINT",
token: "YOUR_CLUSTER_TOKEN"
});
// Sample text to analyze
const sample_text = "The Milvus vector database is built for scale!";
// Run the whitespace analyzer with the defined configuration
const result = await client.runAnalyzer({
text: sample_text,
analyzer_params: analyzer_params
});
# restful
export MILVUS_HOST="YOUR_CLUSTER_ENDPOINT"
export SAMPLE_TEXT="The Milvus vector database is built for scale!"
curl -X POST "http://${MILVUS_HOST}/v2/vectordb/common/run_analyzer" \
-H "Content-Type: application/json" \
-H "Request-Timeout: 10" \
-d '{
"text": ["'"${SAMPLE_TEXT}"'"],
"analyzerParams": "{\"tokenizer\":\"whitespace\",\"filter\":[\"lowercase\"]}"
}'
Expected output
['the', 'milvus', 'vector', 'database', 'is', 'built', 'for', 'scale!']