Should we add bfloat16 support for HNSW?
- 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
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