Repository navigation
GEODE-vector-pr1: Add KnnFloatVectorField, SQ8 Scalar Quantization Codec, Zero-Copy PDX Vector Mapping, and Bounded Segment Compaction - #8154
Conversation
…d zero-copy PDX vector mapping
…paction for vector indexes
|
Welcome, @gouthamaenugu, and thank you for this contribution! Vector indexing is an exciting direction for I've approved the CI workflows so you can get test signal while this is still a draft. Since this adds public API and touches serialization and wire compatibility, a few steps will help it move smoothly:
One small question: a commit message refers to "critic findings PR1-B1 through PR1-B5". Could you share where that review lives, so the context is available to everyone? Once the dev@ thread has settled and this is marked ready for review, I'll be glad to go through it in detail. Thanks again, and welcome to the community! |
|
Thank you for the warm welcome and for approving the CI workflows, @JinwooHwang! Here's where each of those items stands:
On
When squashing the branch to reference the JIRA ticket before marking ready for review, I'll make sure the final commit message is completely self-contained without internal checklist labels. I'm also looking into the |
….txt for VectorIndexMetadata
|
Thanks for the thorough update, @gouthamaenugu, and for clarifying the PR1-B1 through B5 labels. Let's settle the JIRA structure on the dev@ thread, and take your time with the integrationTest failure. |
PR 1: Add
KnnFloatVectorField, SQ8 Scalar Quantization Codec, Zero-Copy PDX Vector Mapping, and Bounded Segment Compactiongouthamaenugu:feature/GEODE-vector-pr1-knn-fieldapache:develop(46643af515)be90eff48bf290dab051686b08e0202000efa67b(27 files changed, +3026 / -39)geode-lucene(Apache Geode 2.1, bundled Apache Lucene9.12.3)For all changes, please confirm:
GEODE-*JIRA ticket assignment and commit prefix update.)develop)?VectorIndexMetadatano-arg deserialization +assembly_content.txtJavadoc entry — ready to squash on upstream submission.)gradlew buildrun cleanly? (Verified:geode-lucene:spotlessCheck,:geode-lucene:checkPom,:geode-lucene:javadoc,:geode-lucene:test --rerun, andAnalyzeLuceneSerializablesIntegrationTest.testSerializables.)9.12.3.)Summary / Motivation
Apache Geode 2.1 ships with Apache Lucene
9.12.3, which natively supports HNSW approximate nearest-neighbor indexing (KnnFloatVectorField) and 8-bit scalar quantization (Lucene99ScalarQuantizedVectorsFormat), yetgeode-lucenecurrently exposes only lexical text indexing.This PR introduces the foundational vector indexing layer in
geode-lucene:VectorIndexMetadata) with cluster-wide profile consistency checks.float[],List<Float>,double[], andNumber[]embeddings from bothPdxInstance(viaPdxInstance.getField(...)without ever triggeringPdxInstance.getObject()) and POJOs (viaClassValue-cached reflection).9.12.3KnnFloatVectorFieldemission acrossPdxLuceneSerializer,ReflectionLuceneSerializer,HeterogeneousLuceneSerializer, andFlatFormatSerializer, plus optional SQ8 quantization via aLucene912Codecoverride wrappingLucene99HnswScalarQuantizedVectorsFormatandLucene99HnswVectorsFormat.TieredMergePolicy+RAMBufferSizeMBtuning and an internalmaybeCompactSegments(int maxSegments)helper to prevent tiny HNSW segment proliferation under frequent AEQ commits (while leaving non-vector Lucene indexes completely untouched).Key Changes
Public & Internal API Additions
VectorIndexMetadata(org.apache.geode.cache.lucene): Immutable descriptor holdingfieldName,dimension,VectorSimilarityFunction(COSINE,DOT_PRODUCT,EUCLIDEAN), HNSW graph parameters (maxConnectionsM,beamWidthefConstruction), andquantizeSQ8flag. Rejects invalid dimensions, non-positiveM/efConstruction, and null/blank names.LuceneIndexFactory&LuceneIndex(org.apache.geode.cache.lucene):defaultfluent methods.addVectorField(String name, int dimension, VectorSimilarityFunction similarity, boolean quantizeSQ8)and.addVectorField(String name, int dimension, VectorSimilarityFunction similarity, int maxConnections, int beamWidth, boolean quantizeSQ8).default Map<String, VectorIndexMetadata> getVectorFields()onLuceneIndex.LuceneIndexFactoryImpl,LuceneIndexImpl,LuceneServiceImpl,LuceneRegionListener,LuceneIndexCreation:fieldNameswhen at least one vector field is configured).Vector Extraction, Codec Integration & Bounded Segment Compaction
VectorFieldMapper(org.apache.geode.cache.lucene.internal.repository.serializer):PdxInstance(including dot-separated nested paths) usinggetField(...)only — zero domain-class deserialization.ClassValue<ConcurrentHashMap<String, Field>>for classloader-safe, leak-free POJO field caching.float[]arrays, validates exact dimension match and finite values, and checks float32COSINEsquared-norm overflow/underflow before Lucene ingestion (!Float.isFinite(normSqFloat32) || normSqFloat32 <= 0.0f).9.12.3KnnVectorsFormat(Lucene99HnswScalarQuantizedVectorsFormatwhenquantizeSQ8=true, otherwiseLucene99HnswVectorsFormat).configureVectorIndexWriterConfig(IndexWriterConfig, Map<String, VectorIndexMetadata>)settingRAMBufferSizeMB=64.0,ConcurrentMergeScheduler, and a boundedTieredMergePolicy(segmentsPerTier=4.0,maxMergeAtOnce=8,floorSegmentMB=16.0,maxMergedSegmentMB=1024.0) for vector indexes only.IndexRepositoryFactory,IndexRepository,IndexRepositoryImpl,PartitionedRepositoryManager,LuceneIndexForPartitionedRegion:createIndexWriterConfigto apply vector merge/RAM tuning exclusively whenvectorFieldsis non-empty (leaving lexical-onlyIndexWriterConfigdefaults 100% unchanged).maybeCompactSegments(int maxSegments)(default method onIndexRepository, synchronized two-phase merge/sync + boundedforceMergefallback inIndexRepositoryImpl, and bucket-wide helpers onPartitionedRepositoryManager/LuceneIndexForPartitionedRegion) that returnsfalsewith zero write amplification when already within budget.PdxLuceneSerializer,ReflectionLuceneSerializer,HeterogeneousLuceneSerializer,FlatFormatSerializer):KnnFloatVectorFieldalongside existing lexical fields while leaving non-vector indexing behavior unchanged.New Unit Test Suites (46 Tests)
VectorIndexMetadataJUnitTest(10 tests): metadata validation, immutability, Java serialization round-trip, and strictreadObjectinvariant checks.VectorIndexProfileAndFactoryJUnitTest(13 tests): fluent factory API, duplicate/collision rejection, cluster profile compatibility checks, andVersion.GEODE_1_4_0/GEODE_2_1_0serialization wire compatibility.VectorFieldMapperJUnitTest(14 tests): zero-copyPdxInstanceextraction (assertinggetObject()is never invoked), nested paths,FlatFormatSerializercoverage, float32 norm overflow/underflow rejection, and defensive array copying.VectorCodecRecallJUnitTest(4 tests): end-to-end Lucene9.12.3HNSW FP32 and SQ8 codec indexing and synthetic clustered top-k recall verification.VectorSegmentCompactionJUnitTest(5 tests): verifies vector-indexTieredMergePolicy/RAMBufferSizeMB/ConcurrentMergeSchedulerconfig, non-vector default preservation, natural<= 4segment consolidation across 5,000 docs / 50 commits withoutforceMerge(1)with preserved FP32 & SQ8 Recall@10, andIndexRepositoryImpl/PartitionedRepositoryManagermaybeCompactSegmentsbehavior.Backward Compatibility & Serialization Notes
LuceneIndexFactory,LuceneIndex) and internalIndexRepository(maybeCompactSegments) are declareddefault. Existing callers using lexical-only indexes hit unchanged code paths (including preserving legacy 8-argumentLuceneRegionListenerdelegation and default LuceneIndexWriterConfigwhenvectorFieldsis empty).LuceneIndexCreationProfileadds versionedtoDataPre_GEODE_2_1_0_0/fromDataPre_GEODE_2_1_0_0methods and null-guardsgetFieldNames()/getFieldAnalyzers()for legacy pre-1.4 profiles.sanctionedDataSerializables.txtis updated with exact bytecode lengths.ObjectInputFilterSafety:VectorIndexMetadataserializessimilarityFunctionName(String) rather than the third-party LuceneVectorSimilarityFunctionenum (which is held in atransient volatilecache and re-validated inreadObject), avoiding Geode P2PInvalidClassExceptionrejections.org/apache/geode/cache/lucene/VectorIndexMetadatainsanctioned-geode-lucene-serializables.txt(with a private no-arg constructor populating valid defaults forAnalyzeLuceneSerializablesIntegrationTestdeserialization checks) and addedjavadoc/org/apache/geode/cache/lucene/VectorIndexMetadata.htmltogeode-assembly/src/integrationTest/resources/assembly_content.txt.Exact Gradle Verification Commands & Pass Counts
(Baseline counts captured on
8b51aa312a; follow-up commitbe90eff48badds the private no-argVectorIndexMetadataconstructor andassembly_content.txtentry.)./gradlew --no-daemon --max-workers=2 \ :geode-lucene:spotlessCheck \ :geode-lucene:checkPom \ :geode-lucene:javadoc \ :geode-lucene:test --rerun ./gradlew --no-daemon --max-workers=2 \ :geode-lucene:integrationTest \ --tests "org.apache.geode.codeAnalysis.AnalyzeLuceneSerializablesIntegrationTest.testSerializables":geode-lucene:test --rerunAnalyzeLuceneSerializablesIntegrationTest.testSerializables:geode-lucene:spotlessCheck,:checkPom,:javadocPer-Suite Vector Test Breakdown