diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/knn/index/codec/KNNCodecUtil.java b/src/main/java/com/amazon/opendistroforelasticsearch/knn/index/codec/KNNCodecUtil.java index 39eeaccc..c374ac97 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/knn/index/codec/KNNCodecUtil.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/knn/index/codec/KNNCodecUtil.java @@ -34,25 +34,16 @@ public static final class Pair { public Pair(int[] docs, float[][] vectors) { this.docs = docs; this.vectors = vectors; - this.vectorsStr = new String[0]; this.vectorsInt = new int[0][0]; } public Pair(int[] docs, int[][] vectorsInt) { this.docs = docs; this.vectorsInt = vectorsInt; this.vectors = new float[0][0]; - this.vectorsStr = new String[0]; - } - public Pair(int[] docs, String[] vectorsStr) { - this.docs = docs; - this.vectorsStr = vectorsStr; - this.vectors = new float[0][0]; - this.vectorsInt = new int[0][0]; } public int[] docs; public float[][] vectors; public int[][] vectorsInt; - public String[] vectorsStr; } public static KNNCodecUtil.Pair getFloats(BinaryDocValues values) throws IOException { @@ -91,27 +82,4 @@ public static KNNCodecUtil.Pair getInts(BinaryDocValues values) throws IOExcepti } return new KNNCodecUtil.Pair(docIdList.stream().mapToInt(Integer::intValue).toArray(), vectorList.toArray(new int[][]{})); } - public static KNNCodecUtil.Pair getStrings(BinaryDocValues values) throws IOException { - ArrayList vectorList = new ArrayList<>(); - ArrayList docIdList = new ArrayList<>(); - for (int doc = values.nextDoc(); doc != DocIdSetIterator.NO_MORE_DOCS; doc = values.nextDoc()) { - BytesRef bytesref = values.binaryValue(); - try (ByteArrayInputStream byteStream = new ByteArrayInputStream(bytesref.bytes, bytesref.offset, bytesref.length); - ObjectInputStream objectStream = new ObjectInputStream(byteStream)) { - float[] vector = (float[]) objectStream.readObject(); - //[1,0,1,0,1] --> "1 0 1 0 1" - char[] charArray = new char[vector.length*2]; - for (int bit = 0; bit < vector.length; ++bit) { - int oneBit = ((int)(vector[bit]))%2; - charArray[bit*2] = (char) ('0' + oneBit); - charArray[bit*2+1] = ' '; - } - vectorList.add(String.valueOf(charArray)); - } catch (ClassNotFoundException e) { - throw new RuntimeException(e); - } - docIdList.add(doc); - } - return new KNNCodecUtil.Pair(docIdList.stream().mapToInt(Integer::intValue).toArray(), vectorList.toArray(new String[]{})); - } } diff --git a/src/test/java/com/amazon/opendistroforelasticsearch/knn/index/KNNJNITests.java b/src/test/java/com/amazon/opendistroforelasticsearch/knn/index/KNNJNITests.java index d1f0d824..0b52c1a2 100644 --- a/src/test/java/com/amazon/opendistroforelasticsearch/knn/index/KNNJNITests.java +++ b/src/test/java/com/amazon/opendistroforelasticsearch/knn/index/KNNJNITests.java @@ -284,7 +284,7 @@ public void testAddAndQueryHnswIndexBitHammingWithString() throws Exception { AccessController.doPrivileged( new PrivilegedAction() { public Void run() { - KNNIndex.saveIndexB(docs, vectors, indexPath, algoParams, "bit_hamming", true); + KNNIndex.saveIndex(docs, vectors, indexPath, algoParams, "bit_hamming"); return null; } }