Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Change "space" parameter to "space_type" for custom scoring #232

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,9 @@ private void validateAndInitParams(Map<String, Object> params) {
}

// validate space
final Object space = params.get("space");
final Object space = params.get("space_type");
if (space == null) {
throw new IllegalArgumentException("Missing parameter [space]");
throw new IllegalArgumentException("Missing parameter [space_type]");
}
this.similaritySpace = (String)space;
if (!KNNConstants.COSINESIMIL.equalsIgnoreCase(similaritySpace) && !KNNConstants.L2.equalsIgnoreCase(similaritySpace)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public void testKNNL2ScriptScore() throws Exception {
float[] queryVector = {1.0f, 1.0f};
params.put("field", FIELD_NAME);
params.put("vector", queryVector);
params.put("space", KNNConstants.L2);
params.put("space_type", KNNConstants.L2);
Request request = constructKNNScriptQueryRequest(INDEX_NAME, qb, params, queryVector);
Response response = client().performRequest(request);
assertEquals(request.getEndpoint() + ": failed", RestStatus.OK,
Expand Down Expand Up @@ -106,15 +106,15 @@ public void testKNNCosineScriptScore() throws Exception {
* params": {
* "field": "my_dense_vector",
* "vector": [2.0, 2.0],
* "space": "L2"
* "space_type": "L2"
* }
*
*
*/
float[] queryVector = {2.0f, -2.0f};
params.put("field", FIELD_NAME);
params.put("vector", queryVector);
params.put("space", KNNConstants.COSINESIMIL);
params.put("space_type", KNNConstants.COSINESIMIL);
Request request = constructKNNScriptQueryRequest(INDEX_NAME, qb, params, queryVector);
Response response = client().performRequest(request);
assertEquals(request.getEndpoint() + ": failed", RestStatus.OK,
Expand Down Expand Up @@ -151,13 +151,13 @@ public void testKNNInvalidSourceScript() throws Exception {
* params": {
* "field": "my_dense_vector",
* "vector": [2.0, 2.0],
* "space": "cosinesimil"
* "space_type": "cosinesimil"
* }
*/
float[] queryVector = {2.0f, -2.0f};
params.put("field", FIELD_NAME);
params.put("vector", queryVector);
params.put("space", KNNConstants.COSINESIMIL);
params.put("space_type", KNNConstants.COSINESIMIL);
Script script = new Script(Script.DEFAULT_SCRIPT_TYPE, KNNScoringScriptEngine.NAME, "Dummy_source", params);
ScriptScoreQueryBuilder sc = new ScriptScoreQueryBuilder(qb, script);

Expand Down Expand Up @@ -196,7 +196,7 @@ public void testInvalidSpace() throws Exception {
float[] queryVector = {2.0f, -2.0f};
params.put("field", FIELD_NAME);
params.put("vector", queryVector);
params.put("space", INVALID_SPACE);
params.put("space_type", INVALID_SPACE);
Request request = constructKNNScriptQueryRequest(INDEX_NAME, qb, params, queryVector);
ResponseException ex = expectThrows(ResponseException.class, () -> client().performRequest(request));
assertThat(EntityUtils.toString(ex.getResponse().getEntity()),
Expand All @@ -216,7 +216,7 @@ public void testMissingParamsInScript() throws Exception {
Map<String, Object> params = new HashMap<>();
float[] queryVector = {2.0f, -2.0f};
params.put("vector", queryVector);
params.put("space", KNNConstants.COSINESIMIL);
params.put("space_type", KNNConstants.COSINESIMIL);
Request request = constructKNNScriptQueryRequest(INDEX_NAME, qb, params, queryVector);
ResponseException ex = expectThrows(ResponseException.class, () -> client().performRequest(request));
assertThat(EntityUtils.toString(ex.getResponse().getEntity()),
Expand All @@ -232,11 +232,11 @@ public void testMissingParamsInScript() throws Exception {

// Remove space parameter
params.put("vector", queryVector);
params.remove("space");
params.remove("space_type");
Request space_request = constructKNNScriptQueryRequest(INDEX_NAME, qb, params, queryVector);
ex = expectThrows(ResponseException.class, () -> client().performRequest(space_request));
assertThat(EntityUtils.toString(ex.getResponse().getEntity()),
containsString("Missing parameter [space]"));
containsString("Missing parameter [space_type]"));
}

public void testUnequalDimensions() throws Exception {
Expand All @@ -255,7 +255,7 @@ public void testUnequalDimensions() throws Exception {
float[] queryVector = {2.0f, -2.0f, -2.0f}; // query dimension and field dimension mismatch
params.put("field", FIELD_NAME);
params.put("vector", queryVector);
params.put("space", KNNConstants.COSINESIMIL);
params.put("space_type", KNNConstants.COSINESIMIL);
Request request = constructKNNScriptQueryRequest(INDEX_NAME, qb, params, queryVector);
ResponseException ex = expectThrows(ResponseException.class, () -> client().performRequest(request));
assertThat(EntityUtils.toString(ex.getResponse().getEntity()),
Expand Down