Skip to content

Commit bfaabb4

Browse files
committed
Strip filter_type from options and pass as typed FilterType to VectorSearchIndex
Signed-off-by: Eric Wei <mengwei.eric@gmail.com>
1 parent dd6450f commit bfaabb4

3 files changed

Lines changed: 39 additions & 2 deletions

File tree

opensearch/src/main/java/org/opensearch/sql/opensearch/storage/VectorSearchIndex.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,32 @@ public class VectorSearchIndex extends OpenSearchIndex {
2626
private final String field;
2727
private final float[] vector;
2828
private final Map<String, String> options;
29+
private final FilterType filterType; // null means default (POST)
2930

3031
public VectorSearchIndex(
3132
OpenSearchClient client,
3233
Settings settings,
3334
String indexName,
3435
String field,
3536
float[] vector,
36-
Map<String, String> options) {
37+
Map<String, String> options,
38+
FilterType filterType) {
3739
super(client, settings, indexName);
3840
this.field = field;
3941
this.vector = vector;
4042
this.options = options;
43+
this.filterType = filterType;
44+
}
45+
46+
/** Backward-compatible constructor — defaults to no explicit filter type. */
47+
public VectorSearchIndex(
48+
OpenSearchClient client,
49+
Settings settings,
50+
String indexName,
51+
String field,
52+
float[] vector,
53+
Map<String, String> options) {
54+
this(client, settings, indexName, field, vector, options, null);
4155
}
4256

4357
@Override

opensearch/src/main/java/org/opensearch/sql/opensearch/storage/VectorSearchTableFunctionImplementation.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,14 @@ public Table applyArguments() {
100100
Map<String, String> options = parseOptions(optionStr);
101101
validateOptions(options);
102102

103-
return new VectorSearchIndex(client, settings, tableName, fieldName, vector, options);
103+
// Strip filter_type — it's a SQL-layer directive, not a knn parameter
104+
FilterType filterType = null;
105+
if (options.containsKey("filter_type")) {
106+
filterType = FilterType.fromString(options.remove("filter_type"));
107+
}
108+
109+
return new VectorSearchIndex(
110+
client, settings, tableName, fieldName, vector, options, filterType);
104111
}
105112

106113
private float[] parseVector(String vectorLiteral) {

opensearch/src/test/java/org/opensearch/sql/opensearch/storage/VectorSearchIndexTest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
package org.opensearch.sql.opensearch.storage;
77

88
import static org.junit.jupiter.api.Assertions.assertEquals;
9+
import static org.junit.jupiter.api.Assertions.assertFalse;
910
import static org.junit.jupiter.api.Assertions.assertTrue;
1011

1112
import java.util.LinkedHashMap;
@@ -139,6 +140,21 @@ void buildKnnQueryJsonNonNumericOptionRenderedQuoted() {
139140
assertTrue(json.contains("\"k\":5"), "Numeric option should be unquoted");
140141
}
141142

143+
@Test
144+
void buildKnnQueryJsonExcludesFilterType() {
145+
LinkedHashMap<String, String> options = new LinkedHashMap<>();
146+
options.put("k", "5");
147+
148+
VectorSearchIndex index =
149+
new VectorSearchIndex(
150+
client, settings, "test-index", "embedding",
151+
new float[] {1.0f}, options, FilterType.EFFICIENT);
152+
153+
String json = index.buildKnnQueryJson();
154+
assertFalse(json.contains("filter_type"), "filter_type should not appear in knn JSON");
155+
assertTrue(json.contains("\"k\":5"), "k should still be present");
156+
}
157+
142158
@Test
143159
void isInstanceOfOpenSearchIndex() {
144160
VectorSearchIndex index =

0 commit comments

Comments
 (0)