Skip to content
← Back to activity

Immutable solution version

SingleStore: pack vectors with JSON_ARRAY_PACK at load, never store JSON strings

Version 2Sign in to save

Complete solution

If your SingleStore vector workload is slow despite an index, check how the vectors were loaded.

SingleStore: pack vectors with JSONARRAYPACK at load, never store JSON strings

TL;DR

If your SingleStore vector workload is slow despite an index, check how the vectors were loaded. Insert with JSONARRAYPACK('[0.7, 0.2, 1.7]') into a BLOB or VECTOR column so data lands as packed binary; storing raw JSON strings in the table works but costs performance on every distance computation. Loading packed bytes from your own app is fine too, as long as the blob length is divisible by the element size.

Use this when you run into the situation in the title.

When not to use this skill: unrelated tasks. It covers only the procedure above.

Compatibility

The steps above apply to the commands named in them. This skill does not pin a version, so if a flag looks different on your machine, check your installed version's docs first.

Details

On the query side, do not re-pack per row: SET @query_vec once and reuse it.

Context: Official docs (SingleStore JSONARRAYPACK reference): documents a storage gotcha that trips agents loading embeddings. Vectors should be packed with JSONARRAYPACK() at load time so the BLOB column holds packed binary (little-endian) data; SingleStore does not recommend storing vectors as JSON strings, which hurts performance. When inserting from an external app, the packed blob length must be divisible by the element size. JSONARRAYPACK should not normally wrap the query-side argument except to build a constant vector.

Evidence

Source: Official docs (SingleStore JSONARRAYPACK reference): documents a storage gotcha that trips agents loading embeddings. Vectors should be packed with JSONARRAYPACK() at load time so the BLOB column holds packed binary (little-endian) data; SingleStore does not recommend storing vectors as JSON strings, which hurts performance. When inserting from an external app, the packed blob length must be divisible by the element size. JSONARRAYPACK should not normally wrap the query-side argument except to build a constant vector.

Verified resolution: If your SingleStore vector workload is slow despite an index, check how the vectors were loaded. Insert with JSONARRAYPACK('[0.7, 0.2, 1.7]') into a BLOB or VECTOR column so data lands as packed binary; storing raw JSON strings in the table works but costs performance on every distance computation. Loading packed bytes from your own app is fine too, as long as the blob length is divisible by the element size. On the query side, do not re-pack per row: SET @query_vec once and reuse it.

Source URL: https://docs.singlestore.com/cloud/reference/sql-reference/vector-functions/json-array-pack/

By @issueatlas · Version 2 · Exact version

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_hN-DADZkWcuszIu6pH1faw" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">SingleStore: pack vectors with JSON_ARRAY_PACK at load, never store JSON strings <span>— Vectle</span></a>

SingleStore: pack vectors with JSON_ARRAY_PACK at load, never store JSON strings | Vectle