Arabic Normalization
The arabic_normalization filter is a built-in token filter for Arabic text. It normalizes Arabic-specific letter variants and removes optional marks that can make equivalent Arabic terms appear different during text analysis.
Configuration
For Arabic text, use the built-in Arabic analyzer in most cases. The built-in analyzer includes this filter together with standard tokenization, lowercasing, decimal digit normalization, Arabic stemming, and Arabic stop-word removal. Use arabic_normalization directly only when you need to build a custom analyzer pipeline.
To use the arabic_normalization filter in a custom analyzer, add it to the filter section in analyzer_params:
- Python
- Java
- Go
- Rust
- C++
- NodeJS
- cURL
analyzer_params = {
"tokenizer": "standard",
"filter": ["arabic_normalization"],
}
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("arabic_normalization"));
analyzerParams := map[string]any{"tokenizer": "standard", "filter": []any{"arabic_normalization"}}
let analyzer_params = serde_json::json!({
"tokenizer": "standard",
"filter": ["arabic_normalization"]
});
nlohmann::json analyzer_params = {
{"tokenizer", "standard"},
{"filter", {"arabic_normalization"}},
};
const analyzer_params = {
"tokenizer": "standard",
"filter": ["arabic_normalization"],
};
# restful
analyzerParams='{
"tokenizer": "standard",
"filter": [
"arabic_normalization"
]
}'
The arabic_normalization filter has no configurable parameters.
The filter applies the following transformations:
| Transformation | From | To |
|---|---|---|
| Hamza + Alef variants | آ, أ, إ | ا |
| Teh Marbuta | ة | ه |
| Alef Maksura | ى | ي |
| Harakat | U+064B through U+065F | Removed |
| Tatweel / Kashida | ـ | Removed |
The filter operates on tokens generated by the tokenizer. The configuration above is intentionally a custom analyzer example and does not include the complete Arabic processing pipeline.
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": "standard",
"filter": ["arabic_normalization"],
}
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("arabic_normalization"));
analyzerParams = map[string]any{"tokenizer": "standard", "filter": []any{"arabic_normalization"}}
let analyzer_params = serde_json::json!({
"tokenizer": "standard",
"filter": ["arabic_normalization"]
});
nlohmann::json analyzer_params = {
{"tokenizer", "standard"},
{"filter", {"arabic_normalization"}},
};
const analyzer_params = {
"tokenizer": "standard",
"filter": ["arabic_normalization"],
};
# restful
analyzerParams='{
"tokenizer": "standard",
"filter": [
"arabic_normalization"
]
}'
Verification using run_analyzer
- Python
- Java
- Go
- Rust
- C++
- NodeJS
- cURL
from pymilvus import MilvusClient
client = MilvusClient(uri="YOUR_CLUSTER_ENDPOINT")
sample_text = "آدم أحمد إسلام مدرسة كبرى كِتَابٌ عـــربي"
result = client.run_analyzer(sample_text, analyzer_params)
print(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.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("آدم أحمد إسلام مدرسة كبرى كِتَابٌ عـــربي");
RunAnalyzerResp resp = client.runAnalyzer(RunAnalyzerReq.builder()
.texts(texts)
.analyzerParams(analyzerParams)
.build());
List<RunAnalyzerResp.AnalyzerResult> results = resp.getResults();
import (
"context"
"encoding/json"
"fmt"
"github.com/milvus-io/milvus/client/v3/milvusclient"
)
client, err := milvusclient.New(ctx, &milvusclient.ClientConfig{
Address: "YOUR_CLUSTER_ENDPOINT",
APIKey: "YOUR_CLUSTER_TOKEN",
})
if err != nil {
fmt.Println(err.Error())
// handle error
}
bs, _ := json.Marshal(analyzerParams)
texts := []string{"آدم أحمد إسلام مدرسة كبرى كِتَابٌ عـــربي"}
option := milvusclient.NewRunAnalyzerOption(texts...).
WithAnalyzerParamsStr(string(bs))
result, err := client.RunAnalyzer(ctx, option)
if err != nil {
fmt.Println(err.Error())
// handle error
}
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 texts = ["آدم أحمد إسلام مدرسة كبرى كِتَابٌ عـــربي".to_string()];
let analyzer_params = serde_json::json!({
"tokenizer": "standard",
"filter": ["arabic_normalization"]
});
let result = client.run_analyzer(
RunAnalyzerRequest::builder()
.texts(texts)
.analyzer_params(analyzer_params)
.build()?,
).await?;
println!("{:?}", result.results());
Ok(())
}
#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 = "آدم أحمد إسلام مدرسة كبرى كِتَابٌ عـــربي";
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;
}
const res = await client.runAnalyzer({
text: 'آدم أحمد إسلام مدرسة كبرى كِتَابٌ عـــربي',
analyzer_params: analyzer_params
});
console.log(res);
# restful
curl --request POST \
--url "${CLUSTER_ENDPOINT}/v2/vectordb/common/run_analyzer" \
--header "Authorization: Bearer ${TOKEN}" \
--header "Content-Type: application/json" \
--data '{
"text": ["آدم أحمد إسلام مدرسة كبرى كِتَابٌ عـــربي"],
"analyzerParams": "{\"tokenizer\":\"standard\",\"filter\":[\"arabic_normalization\"]}"
}'
Expected output
['ادم', 'احمد', 'اسلام', 'مدرسه', 'كبري', 'كتاب', 'عربي']