jerry-024 commented on code in PR #110: URL: https://github.com/apache/paimon-vector-index/pull/110#discussion_r4059575616
########## java/src/main/java/org/apache/paimon/index/vector/VectorRangeSearchResult.java: ########## @@ -0,0 +1,145 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.paimon.index.vector; + +import java.util.Arrays; +import java.util.Objects; + +/** + * CSR range-search output in core scan order, with raw distances and no sorting or top-K cap. + * IVF-Flat distances are exact; SQ, PQ and RQ return their core distance estimates. Each query + * occupies [lims[query], lims[query + 1]); all arrays are defensively copied. + */ +public final class VectorRangeSearchResult { + + private final long[] labels; + private final float[] distances; + private final long[] lims; + private final long[] listsProbed; + private final long[] rowsScanned; + private final long[] rowsCommitted; + private final long[] earlyAbandoned; + private final long listReads; + + public VectorRangeSearchResult( + long[] labels, + float[] distances, + long[] lims, + long[] listsProbed, + long[] rowsScanned, + long[] rowsCommitted, + long[] earlyAbandoned, + long listReads) { + this.labels = Objects.requireNonNull(labels, "labels").clone(); + this.distances = Objects.requireNonNull(distances, "distances").clone(); Review Comment: <!-- dlf-review --> **[Major] Avoid copying every JNI-created result array twice** JNI has already allocated and populated all seven Java arrays for each range-search result, but this constructor clones them again. Because range search has no top-K cap, wide bands or large batches pay another O(hit_count) copy and nearly double the Java-side peak result memory, which can turn an otherwise valid result into an OOM. Please keep the public constructor defensive, but add a package-private ownership-taking path for VectorIndexNative/JNI-created arrays. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
