Skip to content

Commit

Permalink
Change VectorReaderListener to expect number array (#416)
Browse files Browse the repository at this point in the history
Refactors VectorReaderListener onResponse to expect arrays of Number
type from search result instead of Double type. Adds test case to
confirm that it can handle Integer type. Cleans up tests in
VectorReaderTest class.

Signed-off-by: John Mazanec <[email protected]>
(cherry picked from commit 7735351)
  • Loading branch information
jmazanec15 committed Jun 3, 2022
1 parent b83c88f commit 60f50eb
Show file tree
Hide file tree
Showing 2 changed files with 195 additions and 97 deletions.
6 changes: 3 additions & 3 deletions src/main/java/org/opensearch/knn/training/VectorReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,9 @@ public void onResponse(SearchResponse searchResponse) {
List<Float[]> trainingData = new ArrayList<>();

for (int i = 0; i < vectorsToAdd; i++) {
trainingData.add(((List<Double>) hits[i].getSourceAsMap().get(fieldName)).stream()
.map(Double::floatValue)
.toArray(Float[]::new));
trainingData.add(
((List<Number>) hits[i].getSourceAsMap().get(fieldName)).stream().map(Number::floatValue).toArray(Float[]::new)
);
}

this.collectedVectorCount += trainingData.size();
Expand Down
Loading

0 comments on commit 60f50eb

Please sign in to comment.