New Tool Radar

AI Concepts

How to Shorten Embedding Vectors to 512 Dimensions to Save Storage

Shorten embedding vectors to 512 dimensions with the dimensions parameter when a smaller index is worth a small quality trade.

Schematic illustration of shorten embedding vectors to 512 dimensions to save storage: step one count the storage now, step two set dimensions to 512, step three re-embed and compare.

Third-generation OpenAI embedding models support a dimensions parameter that shortens the output vector: text-embedding-3-small returns 1536 numbers by default, and you can ask for fewer. Shortening trades a small amount of retrieval quality for large savings in vector storage, memory and search time. The catch is that the dimension count becomes part of your index: documents and queries must use the same value.

Prerequisites

  • An embedding model that supports the dimensions parameter, such as text-embedding-3-small.
  • A count of how many vectors you store.
  • A small set of test questions to compare full and shortened vectors.

Steps

Step 1: Count the storage now

Work out the storage at full size: vectors times dimensions times 4 bytes per float. For 10,000 vectors at 1536 dimensions that is 61,440,000 bytes, about 61 MB.

Step 2: Set dimensions to 512

Send the same embedding calls with dimensions set to 512. The API returns a truncated and renormalised vector. Store it in a collection whose vector size is also 512.

Step 3: Re-embed and compare

Embed the same documents at 512 dimensions and run your test questions. Compare the top results with the full-size results; if the same documents rank first, the shorter vectors are good enough for your job.

Worked example: Harbor Light library catalogue index

The fictional Harbor Light library stores 10,000 catalogue vectors and tests 512 dimensions against the full 1536.

Dimensions Bytes per vector Storage for 10,000 vectors Top result match
1536 6144 61,440,000 Baseline
512 2048 20,480,000 Same top result

At 512 dimensions the index is 20,480,000 bytes, one third of the 61,440,000 bytes at full size, and the top result for the test questions is unchanged.

Expected result. The shortened index uses a third of the storage and returns the same top results on your test questions. UNTESTED: this guide was not run against a live model or API. The worked example below is fictional practice material, and its result is the expected result, not a measured one.

Limits

  • Shortening loses some quality; the trade is only worth it if your test questions confirm the results hold.
  • Once a corpus is embedded at one dimension count, changing it means re-embedding everything.
  • The dimensions parameter is only supported on text-embedding-3 models and later.

Sources

See all