Skip to content

Commit

Permalink
spotlessApply
Browse files Browse the repository at this point in the history
Signed-off-by: Sahil Buddharaju <[email protected]>
  • Loading branch information
Sahil Buddharaju committed Dec 12, 2024
1 parent e820d2c commit d96725b
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,7 @@
import static org.opensearch.knn.common.KNNConstants.METHOD_PARAMETER_M;
import static org.opensearch.knn.common.KNNConstants.METHOD_PARAMETER_SPACE_TYPE;
import static org.opensearch.knn.common.KNNConstants.METHOD_ENCODER_PARAMETER;
import static org.opensearch.knn.common.KNNConstants.VECTOR_DATA_TYPE_FIELD;
import static org.opensearch.knn.common.KNNConstants.ENCODER_SQ;
import static org.opensearch.knn.common.KNNConstants.LUCENE_SQ_BITS;
import static org.opensearch.knn.common.KNNConstants.LUCENE_SQ_CONFIDENCE_INTERVAL;
import static org.opensearch.knn.common.KNNConstants.NAME;
import static org.opensearch.knn.common.KNNConstants.PARAMETERS;

Expand Down Expand Up @@ -140,17 +137,9 @@ public void testKNNIndexLuceneByteVector() throws Exception {

if (isRunningAgainstOldCluster()) {
createKnnIndex(
testIndex,
getKNNDefaultIndexSettings(),
createKnnIndexMapping(
TEST_FIELD,
DIMENSIONS,
METHOD_HNSW,
LUCENE_NAME,
SpaceType.L2.getValue(),
true,
VectorDataType.BYTE
)
testIndex,
getKNNDefaultIndexSettings(),
createKnnIndexMapping(TEST_FIELD, DIMENSIONS, METHOD_HNSW, LUCENE_NAME, SpaceType.L2.getValue(), true, VectorDataType.BYTE)
);
addKNNByteDocs(testIndex, TEST_FIELD, DIMENSIONS, DOC_ID, 50);
// Flush to ensure that index is not re-indexed when node comes back up
Expand All @@ -164,35 +153,34 @@ public void testKNNIndexLuceneByteVector() throws Exception {
}
}


public void testKNNIndexLuceneQuantization() throws Exception {
waitForClusterHealthGreen(NODES_BWC_CLUSTER);
int k = 4;
int dimension = 2;

if (isRunningAgainstOldCluster()) {
String mapping = XContentFactory.jsonBuilder()
.startObject()
.startObject("properties")
.startObject(TEST_FIELD)
.field(VECTOR_TYPE, KNN_VECTOR)
.field(DIMENSION, dimension)
.startObject(KNN_METHOD)
.field(NAME, METHOD_HNSW)
.field(METHOD_PARAMETER_SPACE_TYPE, SpaceType.INNER_PRODUCT.getValue())
.field(KNN_ENGINE, LUCENE_NAME)
.startObject(PARAMETERS)
.startObject(METHOD_ENCODER_PARAMETER)
.field(NAME, ENCODER_SQ)
.endObject()
.field(METHOD_PARAMETER_EF_CONSTRUCTION, 256)
.field(METHOD_PARAMETER_M, 16)
.endObject()
.endObject()
.endObject()
.endObject()
.endObject()
.toString();
.startObject()
.startObject("properties")
.startObject(TEST_FIELD)
.field(VECTOR_TYPE, KNN_VECTOR)
.field(DIMENSION, dimension)
.startObject(KNN_METHOD)
.field(NAME, METHOD_HNSW)
.field(METHOD_PARAMETER_SPACE_TYPE, SpaceType.INNER_PRODUCT.getValue())
.field(KNN_ENGINE, LUCENE_NAME)
.startObject(PARAMETERS)
.startObject(METHOD_ENCODER_PARAMETER)
.field(NAME, ENCODER_SQ)
.endObject()
.field(METHOD_PARAMETER_EF_CONSTRUCTION, 256)
.field(METHOD_PARAMETER_M, 16)
.endObject()
.endObject()
.endObject()
.endObject()
.endObject()
.toString();
createKnnIndex(testIndex, getKNNDefaultIndexSettings(), mapping);

Float[] vector1 = { -10.6f, 25.48f };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ public class IndexingIT extends AbstractRollingUpgradeTestCase {
private static final String FAISS_NAME = "faiss";
private static final String LUCENE_NAME = "lucene";


public void testKNNDefaultIndexSettings() throws Exception {
waitForClusterHealthGreen(NODES_BWC_CLUSTER);
switch (getClusterType()) {
Expand Down Expand Up @@ -101,24 +100,28 @@ public void testKNNIndexCreation_withMethodMapper() throws Exception {
if (isFirstMixedRound()) {
docIdOld = 0;
createKnnIndex(
firstMixRoundIndex,
getKNNDefaultIndexSettings(),
createKnnIndexMapping(TEST_FIELD, DIMENSIONS, ALGO, FAISS_NAME)
firstMixRoundIndex,
getKNNDefaultIndexSettings(),
createKnnIndexMapping(TEST_FIELD, DIMENSIONS, ALGO, FAISS_NAME)
);
addKNNDocs(firstMixRoundIndex, TEST_FIELD, DIMENSIONS, docIdOld, NUM_DOCS);
} else {
docIdOld = 0;
createKnnIndex(
otherMixRoundIndex,
getKNNDefaultIndexSettings(),
createKnnIndexMapping(TEST_FIELD, DIMENSIONS, ALGO, FAISS_NAME)
otherMixRoundIndex,
getKNNDefaultIndexSettings(),
createKnnIndexMapping(TEST_FIELD, DIMENSIONS, ALGO, FAISS_NAME)
);
addKNNDocs(otherMixRoundIndex, TEST_FIELD, DIMENSIONS, docIdOld, NUM_DOCS);
}
break;
case UPGRADED:
docIdOld = 0;
createKnnIndex(upgradedIndex, getKNNDefaultIndexSettings(), createKnnIndexMapping(TEST_FIELD, DIMENSIONS, ALGO, FAISS_NAME));
createKnnIndex(
upgradedIndex,
getKNNDefaultIndexSettings(),
createKnnIndexMapping(TEST_FIELD, DIMENSIONS, ALGO, FAISS_NAME)
);
addKNNDocs(upgradedIndex, TEST_FIELD, DIMENSIONS, docIdOld, NUM_DOCS);

deleteKNNIndex(testIndex);
Expand All @@ -143,24 +146,28 @@ public void testKNNLuceneIndexCreation_withMethodMapper() throws Exception {
if (isFirstMixedRound()) {
docIdOld = 0;
createKnnIndex(
firstMixRoundIndex,
getKNNDefaultIndexSettings(),
createKnnIndexMapping(TEST_FIELD, DIMENSIONS, ALGO, LUCENE_NAME)
firstMixRoundIndex,
getKNNDefaultIndexSettings(),
createKnnIndexMapping(TEST_FIELD, DIMENSIONS, ALGO, LUCENE_NAME)
);
addKNNDocs(firstMixRoundIndex, TEST_FIELD, DIMENSIONS, docIdOld, NUM_DOCS);
} else {
docIdOld = 0;
createKnnIndex(
otherMixRoundIndex,
getKNNDefaultIndexSettings(),
createKnnIndexMapping(TEST_FIELD, DIMENSIONS, ALGO, LUCENE_NAME)
otherMixRoundIndex,
getKNNDefaultIndexSettings(),
createKnnIndexMapping(TEST_FIELD, DIMENSIONS, ALGO, LUCENE_NAME)
);
addKNNDocs(otherMixRoundIndex, TEST_FIELD, DIMENSIONS, docIdOld, NUM_DOCS);
}
break;
case UPGRADED:
docIdOld = 0;
createKnnIndex(upgradedIndex, getKNNDefaultIndexSettings(), createKnnIndexMapping(TEST_FIELD, DIMENSIONS, ALGO, LUCENE_NAME));
createKnnIndex(
upgradedIndex,
getKNNDefaultIndexSettings(),
createKnnIndexMapping(TEST_FIELD, DIMENSIONS, ALGO, LUCENE_NAME)
);
addKNNDocs(upgradedIndex, TEST_FIELD, DIMENSIONS, docIdOld, NUM_DOCS);

deleteKNNIndex(testIndex);
Expand All @@ -178,4 +185,4 @@ public void validateKNNIndexingOnUpgrade(int totalDocsCount, int docId) throws E
totalDocsCount = totalDocsCount + NUM_DOCS;
validateKNNSearch(testIndex, TEST_FIELD, DIMENSIONS, totalDocsCount, K);
}
}
}

0 comments on commit d96725b

Please sign in to comment.