Index binary vectors for vector search

Azure AI Search supports the Collection(Edm.Byte) packed binary type to further reduce the storage and memory footprint of vector data. You can use this data type for the output of models such as Cohere's Embed v3 binary embedding models or any other embedding model or process that outputs vectors as binary bytes.

There are three steps to configuring an index for binary vectors:

  • Add a vector search algorithm that specifies Hamming distance for binary vector comparison
  • Add a vector profile that points to the algorithm
  • Add a vector field of type Collection(Edm.Byte) and assign the Hamming distance

This article uses the REST APIs for illustration, but you can also use an Azure SDK or the Azure portal to add a binary field to an index. You assign the binary data type to fields by using the Indexes - Create or Indexes - Create Or Update REST APIs.

Tip

If you're investigating binary vector support for its smaller footprint, you might also consider the vector quantization and storage reduction features in Azure AI Search. Inputs are float32 or float16 embeddings. Output is stored data in a much smaller format. For more information, see Compress using binary or scalar quantization and Assign narrow data types.

Prerequisites

  • Familiarity with creating an index and adding vector fields.

  • Binary vectors, with one bit per dimension, packaged in uint8 values with eight bits per value. You can get these vectors by using models that directly generate packaged binary vectors or by quantizing vectors into binary vectors in your client application during indexing and retrieval.

Limitations

  • No Azure portal support in the Import data (new) wizard.
  • No support for binary fields in the AML skill that's used for integrated vectorization of models in the Azure AI Studio model catalog.

Add a vector search algorithm and vector profile

Vector search algorithms create the query navigation structures during indexing. For binary vector fields, the system uses the Hamming distance metric to perform vector comparisons.

To configure vector search for binary vectors:

  1. Set up an Indexes - Create or Update (REST API) request.

  2. In the index schema, add a vectorSearch section that specifies profiles and algorithms.

  3. Add one or more vector search algorithms that use a similarity metric of hamming. The Hierarchical Navigable Small Worlds (HNSW) algorithm is common, but you can also use Hamming distance with exhaustive K-Nearest Neighbors (KNN).

  4. Add one or more vector profiles that specify the algorithm.

The following example shows a basic vectorSearch configuration.

  "vectorSearch": { 
    "profiles": [ 
      { 
        "name": "myHnswProfile", 
        "algorithm": "myHnsw", 
        "compression": null, 
        "vectorizer": null 
      } 
    ], 
    "algorithms": [ 
      { 
        "name": "myHnsw", 
        "kind": "hnsw", 
        "hnswParameters": { 
          "metric": "hamming" 
        } 
      }, 
      { 
        "name": "myExhaustiveKnn", 
        "kind": "exhaustiveKnn", 
        "exhaustiveKnnParameters": { 
          "metric": "hamming" 
        } 
      } 
    ] 
  }

Add a binary field to an index

The fields collection of an index must include a field for the document key, vector fields, and any other fields you need for hybrid search scenarios.

Binary fields use the Collection(Edm.Byte) type and contain embeddings in packed form. For example, if the original embedding dimension is 1024, the packed binary vector length is ceiling(1024 / 8) = 128. You get the packed form by setting the vectorEncoding property on the field.

To add a binary vector field to an index:

  1. Add a field to the fields collection and give it a name.

  2. Set the data type to Collection(Edm.Byte).

  3. Set vectorEncoding to packedBit for binary encoding.

  4. Set dimensions to 1024. Specify the original (unpacked) vector dimension.

  5. Set vectorSearchProfile to a profile you defined in the previous step.

  6. Set searchable to true.

The following field definition is an example of a binary vector field in an index schema.

  "fields": [ 
    . . . 
    { 
      "name": "my-binary-vector-field", 
      "type": "Collection(Edm.Byte)", 
      "vectorEncoding": "packedBit", 
      "dimensions": 1024, 
      "vectorSearchProfile": "myHnswProfile",
      "searchable": true
    },
   . . . 
  ]