Fix undercounting of RAM used by vectors buffered in in-memory segments#15982
Open
iprithv wants to merge 2 commits intoapache:mainfrom
Open
Fix undercounting of RAM used by vectors buffered in in-memory segments#15982iprithv wants to merge 2 commits intoapache:mainfrom
iprithv wants to merge 2 commits intoapache:mainfrom
Conversation
f97d7cf to
918fa44
Compare
Contributor
Author
|
@mikemccand could you please take a look at this when you get a chance? Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Vector RAM accounting in
ramBytesUsed()had three bugs causing IndexWriter to undercount memory usage for buffered vectors, leading to delayed flush decisions and higher than expected memory consumption.Bugs Fixed
Fixes #15901
1.
BufferingKnnVectorsWriterhardcodedFloat.BYTESfor all encodingsByte vectors (
VectorEncoding.BYTE) were reported as 4x their actual size becauseramBytesUsed()always multiplied byFloat.BYTES(4) instead ofByte.BYTES(1). This is technically an overcount for byte vectors, but it's wrong in the opposite direction, it masks the undercounting elsewhere and produces incorrect flush thresholds.2. Quantized writers never counted
rawVectorDelegateRAMLucene104ScalarQuantizedVectorsWriter,Lucene99ScalarQuantizedVectorsWriter, andLucene102BinaryQuantizedVectorsWriterall wrap arawVectorDelegate(Lucene99FlatVectorsWriter). For FLOAT32 fields, the delegate's field-level data was counted indirectly throughFieldWriter.flatFieldVectorsWriter.ramBytesUsed(). But for BYTE fields, which bypass the quantizedFieldWriterentirely, the delegate was never queried, making byte vector RAM completely invisible (48 bytes reported for hundreds of KB of actual data).Refactored all three writers to call
rawVectorDelegate.ramBytesUsed()at the writer level for all flat vector data, andquantizationOverheadBytesUsed()for quantization-specific state (magnitudes, dimensionSums) to avoid double-counting.3.
dimensionSumsarray not countedThe
float[dimension]array used for centroid calculation during flush was not included inramBytesUsed()forLucene104ScalarQuantizedVectorsWriterandLucene102BinaryQuantizedVectorsWriter.