apache / apache/lucene

Should we add bfloat16 support for HNSW?

Open
#12,403 8 comments 0 reactions 0 assignees View on GitHub
type:enhancement vector-based-search
Dominant language
Java
Stars
3.6k
Forks
1.4k
Avg merge
2d 11h
Merged PRs (30d)
88

Description

### 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`.

Contributor guide

Open the contributing guide

Research direction

The issue discusses HNSW vector storage, byte streams, and bfloat16 decoding but names no files or tests. Start by locating the HNSW storage and decoding entry points, then investigate memory savings and decoding performance. Done would require an agreed design and measured trade-offs before implementation can be scoped.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
search
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.