diff --git a/src/it/java/io/weaviate/integration/CollectionsITest.java b/src/it/java/io/weaviate/integration/CollectionsITest.java index db7ee19ea..889041277 100644 --- a/src/it/java/io/weaviate/integration/CollectionsITest.java +++ b/src/it/java/io/weaviate/integration/CollectionsITest.java @@ -20,6 +20,7 @@ import io.weaviate.client6.v1.api.collections.Replication; import io.weaviate.client6.v1.api.collections.Replication.AsyncReplicationConfig; import io.weaviate.client6.v1.api.collections.VectorConfig; +import io.weaviate.client6.v1.api.collections.VectorIndex; import io.weaviate.client6.v1.api.collections.config.PropertyIndexType; import io.weaviate.client6.v1.api.collections.config.Shard; import io.weaviate.client6.v1.api.collections.config.ShardStatus; @@ -394,7 +395,8 @@ public void test_dropVectorIndex() throws IOException { .extracting(CollectionConfig::vectors, InstanceOfAssertFactories.map(String.class, VectorConfig.class)) .hasSize(2) .extractingByKey("dropme") - .returns(null, VectorConfig::vectorIndex); // A dropped index has not vectorIndex configuration. + .extracting(VectorConfig::vectorIndex) + .matches(VectorIndex::isNone).as("is 'none'"); } @Test diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/VectorIndex.java b/src/main/java/io/weaviate/client6/v1/api/collections/VectorIndex.java index af9d7bd6a..7fb697830 100644 --- a/src/main/java/io/weaviate/client6/v1/api/collections/VectorIndex.java +++ b/src/main/java/io/weaviate/client6/v1/api/collections/VectorIndex.java @@ -5,6 +5,7 @@ import java.util.Map; import com.google.gson.Gson; +import com.google.gson.JsonObject; import com.google.gson.JsonParser; import com.google.gson.TypeAdapter; import com.google.gson.TypeAdapterFactory; @@ -28,7 +29,8 @@ enum Kind implements JsonEnum { HNSW("hnsw"), FLAT("flat"), DYNAMIC("dynamic"), - HFRESH("hfresh"); + HFRESH("hfresh"), + NONE("none"); private static final Map jsonValueMap = JsonEnum.collectNames(Kind.values()); private final String jsonValue; @@ -87,6 +89,11 @@ default HFresh asHFresh() { return _as(VectorIndex.Kind.HFRESH); } + /** Is this a "none" vector index? */ + default boolean isNone() { + return _is(VectorIndex.Kind.NONE); + } + static enum CustomTypeAdapterFactory implements TypeAdapterFactory { INSTANCE; @@ -102,6 +109,7 @@ private final void init(Gson gson) { addAdapter(gson, VectorIndex.Kind.FLAT, Flat.class); addAdapter(gson, VectorIndex.Kind.DYNAMIC, Dynamic.class); addAdapter(gson, VectorIndex.Kind.HFRESH, HFresh.class); + addAdapter(gson, VectorIndex.Kind.NONE, NoneVectorIndex.class); } @SuppressWarnings("unchecked") @@ -148,7 +156,7 @@ public VectorIndex read(JsonReader in) throws IOException { if (vectorIndexConfig == null || vectorIndexConfig.isJsonNull()) { // VectorConfig.CustomTypeAdapterFactory cannot provide this // value for vector indexes that have been dropped. - return null; + vectorIndexConfig = new JsonObject(); } VectorIndex.Kind kind; @@ -169,5 +177,23 @@ public VectorIndex read(JsonReader in) throws IOException { } }.nullSafe(); } + + /** + * NoneVectorIndex is a special kind of vector index config + * used for an index that has been deleted. It is not possible + * to create an vector index with "none" config, so it stays + * private to it's parent {@link CustomTypeAdapterFactory}. + */ + private record NoneVectorIndex() implements VectorIndex { + @Override + public VectorIndex.Kind _kind() { + return VectorIndex.Kind.NONE; + } + + @Override + public Object _self() { + return this; + } + } } }