Highlight not working properly with field-level token_separators
Author: Zenor27Created Sep 24, 2026Updated Sep 24, 2026
Labelspre-triage
Bug Description
When a field defines its own token_separators, highlight response marks wrong words. Field-level token_separators seems to break some offset computation.
Reproduction Steps
Minimal reproduction script:
### Run Typesense via Docker ########################################
set -x
export TYPESENSE_API_KEY=xyz
export TYPESENSE_HOST=http://localhost:8108
docker stop typesense-repro 2>/dev/null
docker rm typesense-repro 2>/dev/null
rm -rf "$(pwd)"/typesense-data-dir-repro
mkdir "$(pwd)"/typesense-data-dir-repro
# Wait for Typesense to be ready
docker run -d -p 8108:8108 --name typesense-repro \
-v"$(pwd)"/typesense-data-dir-repro:/data \
typesense/typesense:29.0.rc31 \
--data-dir /data \
--api-key=$TYPESENSE_API_KEY \
--enable-cors
# Wait till typesense is ready.
until curl -s -o /dev/null -w "%{http_code}" "$TYPESENSE_HOST/health" -H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}" | grep -q "200"; do
sleep 2
done
curl -s "$TYPESENSE_HOST/debug" \
-H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}" | jq
curl -s "$TYPESENSE_HOST/collections" \
-X POST \
-H "Content-Type: application/json" \
-H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}" \
-d @- <<'EOF' | jq
{
"name": "foo",
"fields": [
{"name": "description", "type": "string", "token_separators": ["'", ","]}
]
}
EOF
curl -s "$TYPESENSE_HOST/collections/foo/documents/import?action=create" \
-H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}" \
-H "Content-Type: text/plain" \
-X POST \
-d '{"id": "124", "description": "J'"'"'adore la Supply Chain, entre autres choses"}' | jq
curl -s "$TYPESENSE_HOST/multi_search" \
-X POST \
-H "Content-Type: application/json" \
-H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}" \
-d '
{
"searches": [
{
"collection": "foo",
"q": "supply cHaIn",
"query_by": "description"
}
]
}' | jq '.results[0].hits[0].highlight.description.matched_tokens'
docker stop typesense-repro
docker rm typesense-reproExpected vs Actual
Expected behavior
We expect to have only ["Supply", "Chain"] in the matched_tokens
Actual behavior
We have an extra token "entre" in the matched_tokens: ["Supply", "Chain", "entre"]
This is likely due to an offset issue due to the field-level token_separators.
When defining token_separators at the collection-level, everything works fine!
Environment
- Typesense version: 29.0.rc31
- Operating system: `Mac OS 26.5.2
Schema / Configuration
{
"name": "foo",
"fields": [
{ "name": "description", "type": "string", "token_separators": ["'", ","] },
]
}Source: typesense/typesense