[Bug]: REST API returns wrong values for large integers (>2^53) in dynamic fields
Is there an existing issue for this?
- I have searched the existing issues
Environment
Milvus version: v2.6.21 (also reproduced on v2.6.20; v2.6.21 re-verified on 2026-07-24)
- Deployment mode(standalone or cluster): standalone
- MQ type(rocksmq, pulsar or kafka): rocksmq (standalone default)
- SDK version(e.g. pymilvus v2.0.0rc2): REST API v2 (RESTful HTTP via curl; no SDK)
- OS(Ubuntu or CentOS): macOS host / Linux container (Docker Desktop)
- CPU/Memory: 16 GB
- GPU: N/A
- Others: dynamic schema (auto-created collection)Current Behavior
When a dynamic field stores an integer larger than 2^53 (9007199254740992), the REST API response returns a different, incorrect value. The data is stored correctly internally (filter expressions can match the exact value), but the JSON response serializes the integer through float64, losing precision.
Stored: {"x": 9007199254740993} (2^53 + 1)
Filter: x == 9007199254740993 → matches correctly ✓
Output: {"x": 9007199254740992} → WRONG! Lost last bit
Stored: {"x": 9223372036854775807} (INT64_MAX)
Filter: x == 9223372036854775807 → matches correctly ✓
Output: {"x": 9223372036854776000} → WRONG! Off by 193Typed Int64 schema fields are NOT affected — only dynamic fields have this issue.
Actual output from the reproduction below:
{"code":0,"data":[
{"id":1,"big_val":9007199254740992},
{"id":2,"big_val":9223372036854776000},
{"id":3,"big_val":1234567890123456800}
]}Expected Behavior
The REST API should return the exact integer value that was stored. Int64 values up to 9223372036854775807 should be serialized as exact integers in the JSON response, not rounded through float64:
{"code":0,"data":[
{"id":1,"big_val":9007199254740993},
{"id":2,"big_val":9223372036854775807},
{"id":3,"big_val":1234567890123456789}
]}Steps To Reproduce
# Create collection with dynamic schema
curl -s -X POST http://localhost:19530/v2/vectordb/collections/create \
-H "Content-Type: application/json" \
-d '{"collectionName": "repro_h12", "dimension": 4}'
sleep 1
# Insert integer > 2^53
curl -s -X POST http://localhost:19530/v2/vectordb/entities/insert \
-H "Content-Type: application/json" \
-d '{
"collectionName": "repro_h12",
"data": [
{"id": 1, "vector": [0.1,0.2,0.3,0.4], "big_val": 9007199254740993},
{"id": 2, "vector": [0.2,0.3,0.4,0.5], "big_val": 9223372036854775807},
{"id": 3, "vector": [0.3,0.4,0.5,0.6], "big_val": 1234567890123456789}
]
}'
sleep 2
# Query — response shows WRONG values
curl -s -X POST http://localhost:19530/v2/vectordb/entities/query \
-H "Content-Type: application/json" \
-d '{"collectionName": "repro_h12", "filter": "id > 0", "outputFields": ["id","big_val"], "limit": 10}'
# Proof storage is correct: exact-match filters still return the right rows
curl -s -X POST http://localhost:19530/v2/vectordb/entities/query \
-H "Content-Type: application/json" \
-d '{"collectionName": "repro_h12", "filter": "big_val == 9223372036854775807", "outputFields": ["id"], "limit": 10}'
# → id=2 ✓ (the value is stored exactly; only the response serialization is wrong)Milvus Log
No server-side error is produced — the request returns code: 0 with a successful (but numerically corrupted) response, so there is no relevant error log. The defect is observable purely from the REST response body shown above.
Anything else?
Root cause (suspected). Dynamic field values are stored internally as JSON. When constructing the REST API response, the server appears to deserialize the stored JSON into Go's interface{} type, which defaults to float64 for numbers (standard encoding/json behavior). float64 has only 53 bits of mantissa, so integers > 2^53 lose precision. Typed Int64 schema fields bypass this path — they're stored as native int64 and serialized directly, so they retain full precision.
Precision loss matrix (10/10 values tested, deterministic):
| Stored Value | Returned Value | Difference | Note |
|---|---|---|---|
| 9007199254740992 (2^53) | 9007199254740992 | 0 | Exact (boundary) |
| 9007199254740993 (2^53+1) | 9007199254740992 | -1 | Last bit lost |
| 9007199254740995 (2^53+3) | 9007199254740996 | +1 | Rounded up |
| 72057594037927936 (2^56) | 72057594037927940 | +4 | Larger error |
| 72057594037927937 (2^56+1) | 72057594037927940 | +3 | Larger error |
| 123456789012345678 | 123456789012345680 | +2 | General large int |
| 1234567890123456789 | 1234567890123456800 | +11 | 19-digit int |
| 9223372036854775807 (MAX) | 9223372036854776000 | +193 | INT64_MAX |
| -9223372036854775808 (MIN) | -9223372036854776000 | -192 | INT64_MIN |
Same value, both field types (proves the divergence is serialization-path specific):
// Insert: {"typed_int": 9007199254740993, "dyn_int": 9007199254740993}
// REST response: {"typed_int": 9007199254740993, "dyn_int": 9007199254740992}
// ^ correct ^ WRONGImpact.
- Values read back from the API cannot be trusted — Snowflake/Twitter IDs, nanosecond timestamps, and any 64-bit identifier stored in a dynamic field are corrupted on read, with the error growing with magnitude.
- Inconsistent behavior between typed Int64 and dynamic fields makes dynamic schema unreliable for large integers.
- Silent corruption — no error or warning; the only way to detect it is to compare every stored value after reading.
Related issues. #47495 reports the same float64-precision root-cause family on the request side (the ids parameter of RESTful search decoded through float64, causing "duplicate IDs" errors). The present issue is the response side: dynamic field values corrupted during REST response serialization. Both likely share the encoding/json → float64 path in the httpserver layer, but fixing one does not fix the other.
Workaround. Store integers larger than 2^53 in a typed Int64 field (unaffected) or as a VarChar string, rather than in a dynamic field. Client-side JSON parsing cannot recover the value because precision is already lost during server-side serialization. Exact-match filter expressions still match the original value, so lookups by exact value continue to work.
Source: milvus-io/milvus