Skip to content

Commit 8a1f2f6

Browse files
authored
Revert "[Java]Binary and scalar quantization (#1104)" (#1274)
This reverts commit 989c994. The changes in #1104 were merged by accident, ahead of higher priority features. This change is to revert #1104, to reduce rework on the other PRs. Java support for Quantization will be revisited when prioritized. The changes in #1104 can be rebased then. Authors: - MithunR (https://github.com/mythrocks) Approvers: - Corey J. Nolet (https://github.com/cjnolet) URL: #1274
1 parent 3f95336 commit 8a1f2f6

17 files changed

Lines changed: 37 additions & 2053 deletions

File tree

cpp/include/cuvs/preprocessing/quantize/binary.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ extern "C" {
3030
* and sampling_median thresholds are calculated separately for each dimension.
3131
*
3232
*/
33-
typedef enum { ZERO, MEAN, SAMPLING_MEDIAN } cuvsBinaryQuantizerThreshold;
33+
enum cuvsBinaryQuantizerThreshold { ZERO, MEAN, SAMPLING_MEDIAN };
3434

3535
/**
3636
* @brief Binary quantizer parameters.
@@ -39,12 +39,12 @@ struct cuvsBinaryQuantizerParams {
3939
/*
4040
* specifies the threshold to set a bit in cuvsBinaryQuantizerTransform
4141
*/
42-
cuvsBinaryQuantizerThreshold threshold;
42+
cuvsBinaryQuantizerThreshold threshold = MEAN;
4343

4444
/*
4545
* specifies the sampling ratio
4646
*/
47-
float sampling_ratio;
47+
float sampling_ratio = 0.1;
4848
};
4949

5050
typedef struct cuvsBinaryQuantizerParams* cuvsBinaryQuantizerParams_t;

java/cuvs-java/src/main/java/com/nvidia/cuvs/BinaryQuantizer.java

Lines changed: 0 additions & 125 deletions
This file was deleted.

java/cuvs-java/src/main/java/com/nvidia/cuvs/CagraIndex.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -247,14 +247,6 @@ interface Builder {
247247
*/
248248
Builder withIndexParams(CagraIndexParams cagraIndexParameters);
249249

250-
/**
251-
* Sets the quantizer to use for building the index with quantized data.
252-
*
253-
* @param quantizer The quantizer to apply to the dataset during index construction
254-
* @return An instance of this Builder
255-
*/
256-
Builder withQuantizer(CuVSQuantizer quantizer);
257-
258250
/**
259251
* Builds and returns an instance of CagraIndex.
260252
*

java/cuvs-java/src/main/java/com/nvidia/cuvs/CagraQuery.java

Lines changed: 20 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,14 @@
1515
*/
1616
package com.nvidia.cuvs;
1717

18-
import com.nvidia.cuvs.CuVSMatrix.DataType;
1918
import java.util.Arrays;
2019
import java.util.BitSet;
2120
import java.util.Objects;
2221
import java.util.function.LongToIntFunction;
2322

2423
/**
25-
* CagraQuery holds the search parameters plus either raw float[][] vectors
26-
* or a quantized {@link CuVSMatrix} for querying a CAGRA index.
24+
* CagraQuery holds the CagraSearchParams and the query vectors to be used while
25+
* invoking search.
2726
*
2827
* <p><strong>Thread Safety:</strong> Each CagraQuery instance should use its own
2928
* CuVSResources object that is not shared with other threads. Sharing CuVSResources
@@ -34,9 +33,8 @@
3433
public class CagraQuery {
3534

3635
private final CagraSearchParams cagraSearchParameters;
37-
private final float[][] queryVectors;
38-
private final CuVSMatrix quantizedQueries;
3936
private final LongToIntFunction mapping;
37+
private final float[][] queryVectors;
4038
private final int topK;
4139
private final BitSet prefilter;
4240
private final int numDocs;
@@ -49,37 +47,30 @@ public class CagraQuery {
4947
* @param cagraSearchParameters an instance of {@link CagraSearchParams} holding
5048
* the search parameters
5149
* @param queryVectors 2D float query vector array
52-
* @param quantizedQueries 2D quantized query vector array
5350
* @param mapping a function mapping ordinals (neighbor IDs) to custom user IDs
5451
* @param topK the top k results to return
5552
* @param prefilter A single BitSet to use as filter while searching the CAGRA index
5653
* @param numDocs Total number of dataset vectors; used to align the prefilter correctly
5754
* @param resources CuVSResources instance to use for this query
5855
*/
59-
private CagraQuery(
56+
public CagraQuery(
6057
CagraSearchParams cagraSearchParameters,
6158
float[][] queryVectors,
62-
CuVSMatrix quantizedQueries,
6359
LongToIntFunction mapping,
6460
int topK,
6561
BitSet prefilter,
6662
int numDocs,
6763
CuVSResources resources) {
64+
super();
6865
this.cagraSearchParameters = cagraSearchParameters;
6966
this.queryVectors = queryVectors;
70-
this.quantizedQueries = quantizedQueries;
7167
this.mapping = mapping;
7268
this.topK = topK;
7369
this.prefilter = prefilter;
7470
this.numDocs = numDocs;
7571
this.resources = resources;
7672
}
7773

78-
/** Start building a new CagraQuery. */
79-
public static Builder newBuilder(CuVSResources resources) {
80-
return new Builder(resources);
81-
}
82-
8374
/**
8475
* Gets the instance of CagraSearchParams initially set.
8576
*
@@ -90,35 +81,14 @@ public CagraSearchParams getCagraSearchParameters() {
9081
}
9182

9283
/**
93-
* If this query was built without a quantizer, returns the original float vectors.
94-
* Otherwise returns null.
84+
* Gets the query vector 2D float array.
85+
*
86+
* @return 2D float array
9587
*/
9688
public float[][] getQueryVectors() {
9789
return queryVectors;
9890
}
9991

100-
/**
101-
* If this query was built with a quantizer, returns the quantized Dataset.
102-
* Otherwise returns null.
103-
*/
104-
public CuVSMatrix getQuantizedQueries() {
105-
return quantizedQueries;
106-
}
107-
108-
/** True if this query carries a quantized Dataset instead of float[][] */
109-
public boolean hasQuantizedQueries() {
110-
return quantizedQueries != null;
111-
}
112-
113-
/**
114-
* Returns the data type of the query payload:
115-
* - 32 for float32 queries
116-
* - 8 for quantized queries
117-
*/
118-
public DataType getQueryDataType() {
119-
return quantizedQueries != null ? quantizedQueries.dataType() : DataType.FLOAT;
120-
}
121-
12292
/**
12393
* Gets the function mapping ordinals (neighbor IDs) to custom user IDs
12494
*/
@@ -164,13 +134,10 @@ public CuVSResources getResources() {
164134

165135
@Override
166136
public String toString() {
167-
return "CagraQuery["
168-
+ "params="
137+
return "CuVSQuery [cagraSearchParameters="
169138
+ cagraSearchParameters
170-
+ ", floatVectors="
171-
+ (queryVectors != null ? Arrays.toString(queryVectors) : "null")
172-
+ ", quantized="
173-
+ (quantizedQueries != null ? ("Dataset@" + quantizedQueries.dataType() + "-bit") : "false")
139+
+ ", queryVectors="
140+
+ Arrays.toString(queryVectors)
174141
+ ", mapping="
175142
+ mapping
176143
+ ", topK="
@@ -189,7 +156,6 @@ public static class Builder {
189156
private int topK = 2;
190157
private BitSet prefilter;
191158
private int numDocs;
192-
private CuVSQuantizer quantizer;
193159
private final CuVSResources resources;
194160

195161
/**
@@ -208,12 +174,12 @@ public Builder(CuVSResources resources) {
208174
/**
209175
* Sets the instance of configured CagraSearchParams to be passed for search.
210176
*
211-
* @param params an instance of the configured CagraSearchParams to
212-
* be used for this query
177+
* @param cagraSearchParams an instance of the configured CagraSearchParams to
178+
* be used for this query
213179
* @return an instance of this Builder
214180
*/
215-
public Builder withSearchParams(CagraSearchParams params) {
216-
this.cagraSearchParams = params;
181+
public Builder withSearchParams(CagraSearchParams cagraSearchParams) {
182+
this.cagraSearchParams = cagraSearchParams;
217183
return this;
218184
}
219185

@@ -267,47 +233,13 @@ public Builder withPrefilter(BitSet prefilter, int numDocs) {
267233
}
268234

269235
/**
270-
* Specify a quantizer to automatically transform the float[][] queryVectors
271-
* into a quantized {@link CuVSMatrix} using the same quantizer used for training.
272-
*/
273-
public Builder withQuantizer(CuVSQuantizer quantizer) {
274-
this.quantizer = quantizer;
275-
return this;
276-
}
277-
278-
/**
279-
* Builds the CagraQuery. If a quantizer was provided, queryVectors is ignored
280-
* and a quantized Dataset is produced instead.
236+
* Builds an instance of CuVSQuery.
237+
*
238+
* @return an instance of CuVSQuery
281239
*/
282-
public CagraQuery build() throws Throwable {
283-
if (queryVectors == null) {
284-
throw new IllegalArgumentException("Query vectors must be provided");
285-
}
286-
287-
CuVSMatrix quantized = null;
288-
float[][] floatsForQuery = queryVectors;
289-
290-
if (quantizer != null) {
291-
// wrap float[][] in a CuVSMatrix and quantize
292-
try (CuVSMatrix tmp = CuVSMatrix.ofArray(queryVectors)) {
293-
if (tmp.dataType() != DataType.FLOAT) {
294-
throw new IllegalArgumentException(
295-
"Query quantization requires FLOAT input, got " + tmp.dataType());
296-
}
297-
quantized = quantizer.transform(tmp);
298-
}
299-
floatsForQuery = null;
300-
}
301-
240+
public CagraQuery build() {
302241
return new CagraQuery(
303-
cagraSearchParams,
304-
floatsForQuery,
305-
quantized,
306-
mapping,
307-
topK,
308-
prefilter,
309-
numDocs,
310-
resources);
242+
cagraSearchParams, queryVectors, mapping, topK, prefilter, numDocs, resources);
311243
}
312244
}
313245
}

java/cuvs-java/src/main/java/com/nvidia/cuvs/CuVSMatrix.java

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -69,17 +69,6 @@ static CuVSMatrix ofArray(byte[][] vectors) {
6969
return CuVSProvider.provider().newMatrixFromArray(vectors);
7070
}
7171

72-
/**
73-
* Returns the data type of this matrix.
74-
*
75-
* <p>DataType provides the fundamental type information needed for all operations.
76-
* FLOAT represents 32-bit floating point data, INT represents 32-bit integer data,
77-
* and BYTE represents 8-bit data (used for quantized values).
78-
*
79-
* @return The DataType of this matrix
80-
*/
81-
DataType dataType();
82-
8372
interface Builder {
8473
/**
8574
* Add a single vector to the dataset.
@@ -163,13 +152,6 @@ static CuVSMatrix.Builder builder(int size, int columns, DataType dataType) {
163152
*/
164153
void toArray(byte[][] array);
165154

166-
/**
167-
* Gets where the content is stored
168-
*
169-
* @return MemoryKind whether HOST or DEVICE
170-
*/
171-
CuVSMatrix.MemoryKind memoryKind();
172-
173155
@Override
174156
void close();
175157
}

0 commit comments

Comments
 (0)