• Home
  • Categories
  • Tags
  • Pricing
  • Submit
    Decorative pattern
    1. Home
    2. Concepts & Definitions
    3. Hamming Distance

    Hamming Distance

    Distance metric for binary vectors counting the number of positions at which corresponding bits differ, computed efficiently using XOR and popcount operations for ultra-fast similarity search.

    🌐Visit Website

    About this tool

    Overview

    Hamming Distance is a distance metric for binary vectors that counts the number of positions at which the corresponding bits are different. It's the primary distance metric used with binary quantized embeddings.

    How Hamming Distance Works

    For two binary vectors:

    1. Perform XOR operation (bits differ where XOR = 1)
    2. Count the number of 1s (popcount)
    3. This count is the Hamming distance

    Example

    Vector A: 10110
    Vector B: 10011
    XOR:      00101  (2 bits differ)
    Hamming Distance = 2
    

    Computational Efficiency

    Hardware Acceleration

    Modern CPUs have hardware instructions for:

    • XOR: Single cycle operation
    • popcount: Dedicated hardware instruction
    • Can process 64 or 128 bits at once

    Performance Benefits

    • 10-100x faster than float vector comparisons
    • Enables real-time search on billions of vectors
    • Minimal memory bandwidth requirements

    Use with Binary Quantization

    Hamming distance is the natural metric for binary quantized embeddings:

    • Convert embeddings to binary (1 bit per dimension)
    • Store compactly (32x compression)
    • Search using Hamming distance
    • Optionally rescore top results with full precision

    Properties

    Metric Properties

    • Non-negativity: d(a,b) ≥ 0
    • Identity: d(a,b) = 0 iff a = b
    • Symmetry: d(a,b) = d(b,a)
    • Triangle inequality: d(a,c) ≤ d(a,b) + d(b,c)

    Comparison with Other Metrics

    vs Euclidean Distance:

    • Much faster to compute
    • Only works with binary vectors
    • Lower precision

    vs Cosine Similarity:

    • Simpler calculation
    • Binary only
    • Used in different contexts

    Use Cases

    • Binary quantized vector search
    • First-stage retrieval (before rescoring)
    • Massive-scale similarity search
    • Real-time search applications
    • Error detection and correction

    Implementations

    Available in:

    • Most vector databases (Qdrant, Milvus, Weaviate)
    • NumPy: np.count_nonzero(a != b)
    • SciPy: scipy.spatial.distance.hamming
    • Custom SIMD implementations

    Pricing

    Free - algorithmic concept widely implemented.

    Surveys

    Loading more......

    Information

    Websiteen.wikipedia.org
    PublishedMar 13, 2026

    Categories

    1 Item
    Concepts & Definitions

    Tags

    3 Items
    #Distance Metric#Binary#Similarity

    Similar Products

    6 result(s)
    Dot Product

    Vector similarity metric measuring both directional similarity and magnitude of vectors. Used by many LLMs for training and equivalent to cosine similarity for normalized data. Reports both angle and magnitude information.

    Manhattan Distance

    Vector distance metric calculating the sum of absolute differences between vector components. Measures grid-like distance and is robust to outliers, with faster calculation as data dimensionality increases.

    Cosine Similarity

    Fundamental similarity metric for vector search measuring the cosine of the angle between vectors. Range from -1 to 1, with 1 indicating identical direction regardless of magnitude.

    Dot Product (Inner Product)

    Similarity metric computing sum of element-wise products between vectors. Efficient for normalized vectors, equivalent to cosine similarity when vectors are unit length.

    Euclidean Distance (L2 Distance)

    Distance metric measuring straight-line distance between vectors in multi-dimensional space. Lower values indicate higher similarity, with 0 meaning identical vectors.

    Vector Similarity Metrics

    Mathematical measures for comparing vector similarity including cosine similarity (directional), Euclidean distance (geometric), dot product (magnitude+direction), and Manhattan distance (grid-based) for AI and search applications.

    Decorative pattern
    Built with
    Ever Works
    Ever Works

    Connect with us

    Stay Updated

    Get the latest updates and exclusive content delivered to your inbox.

    Product

    • Categories
    • Tags
    • Pricing
    • Help

    Clients

    • Sign In
    • Register
    • Forgot password?

    Company

    • About Us
    • Admin
    • Sitemap

    Resources

    • Blog
    • Submit
    • API Documentation
    All product names, logos, and brands are the property of their respective owners. All company, product, and service names used in this repository, related repositories, and associated websites are for identification purposes only. The use of these names, logos, and brands does not imply endorsement, affiliation, or sponsorship. This directory may include content generated by artificial intelligence.
    Copyright © 2025 Awesome Vector Databases. All rights reserved.·Terms of Service·Privacy Policy·Cookies