Skip to content

Should we add bfloat16 support for HNSW? #12403

@benwtrent

Description

@benwtrent

Description

One of the biggest pain points of HNSW is that the graph and vectors must be in memory.

Since the vectors are stored off heap and read in via byte streams, it seems like we could reduce the memory requirements by half for a typical use case if we stored the vector dimensions in 2 bytes instead of 4.

When the bytes are read into heap for comparison, we would still be required to use float (until the JVM supports a native float16 type).

I guess the open questions are:

  • Do we think this is worth it? It seems like users could get 2x memory savings with almost no configuration change.
  • How big a hit on performance is this. I am assuming decoding a bfloat16 bytes will take longer than decoding a float as float decoding can use intrinsics.

I recognize that in the future Lucene will likely support a separate vector codec that uses less memory and is more disk-friendly, but I would argue even such a structure could benefit from only storing bfloat16 instead of float32.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions