HAMMING_SIMILARITY

Applies to: ✅ Data 360 SQL ✅ Tableau Hyper API

Calculates the similarity between two quantized (binary) embeddings using the normalized Hamming distance.

Syntax 

1HAMMING_SIMILARITY(<bytea1>, <bytea2>)

Arguments 

Required 

  • <bytea1>: The first binary-quantized vector.
  • <bytea2>: The second binary-quantized vector.

Returns 

Returns a double-precision value between 0 and 1, where 1 indicates identical binary vectors.

Considerations 

  • Both inputs must be bytea values of the same length.
  • This function provides fast, approximate similarity. Use exact methods when precision is critical.

Examples 

Calculate Hamming Similarity 

Compare two binary-quantized vectors.

1SELECT HAMMING_SIMILARITY('\x0a'::bytea, '\x03'::bytea) AS result;

Returns 0.75, indicating 3 out of 4 bits match between the two vectors.

Related Documentation 

DID THIS ARTICLE SOLVE YOUR ISSUE?
Let us know so we can improve!