Skip to content

Commit e959ae7

Browse files
authored
Merge pull request #556 from weaviate/feat/drop-vector-index
2 parents 08b7f61 + 4a11e27 commit e959ae7

8 files changed

Lines changed: 76 additions & 5 deletions

File tree

.github/workflows/test.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ jobs:
9191
strategy:
9292
fail-fast: false
9393
matrix:
94-
WEAVIATE_VERSION: ["1.32.24", "1.33.11", "1.34.7", "1.35.2", "1.36.9"]
94+
WEAVIATE_VERSION:
95+
["1.32.24", "1.33.11", "1.34.7", "1.35.2", "1.36.9", "1.37.0-rc.0"]
9596
steps:
9697
- uses: actions/checkout@v4
9798

src/it/java/io/weaviate/containers/Weaviate.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ public enum Version {
4444
V133(1, 33, 11),
4545
V134(1, 34, 7),
4646
V135(1, 35, 2),
47-
V136(1, 36, 9);
47+
V136(1, 36, 9),
48+
V137(1, 37, "0-rc.0");
4849

4950
public final SemanticVersion semver;
5051

src/it/java/io/weaviate/integration/CollectionsITest.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,31 @@ public void test_dropPropertyIndex() throws IOException {
372372
.returns(false, Property::indexRangeFilters));
373373
}
374374

375+
@Test
376+
public void test_dropVectorIndex() throws IOException {
377+
Weaviate.Version.V137.orSkip();
378+
379+
// Arrange
380+
var nsThings = ns("Things");
381+
var things = client.collections.create(nsThings,
382+
c -> c.vectorConfig(VectorConfig.selfProvided("leaveme"), VectorConfig.selfProvided("dropme")));
383+
384+
var config = things.config.get();
385+
Assertions.assertThat(config).get()
386+
.extracting(CollectionConfig::vectors, InstanceOfAssertFactories.map(String.class, VectorConfig.class))
387+
.hasSize(2)
388+
.containsKey("dropme");
389+
390+
things.config.dropVectorIndex("dropme");
391+
392+
config = things.config.get();
393+
Assertions.assertThat(config).get()
394+
.extracting(CollectionConfig::vectors, InstanceOfAssertFactories.map(String.class, VectorConfig.class))
395+
.hasSize(2)
396+
.extractingByKey("dropme")
397+
.returns(null, VectorConfig::vectorIndex); // A dropped index has not vectorIndex configuration.
398+
}
399+
375400
@Test
376401
public void test_asyncReplicationConfig() throws IOException {
377402
Weaviate.Version.latest().orSkip();

src/main/java/io/weaviate/client6/v1/api/collections/VectorConfig.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1695,7 +1695,12 @@ public void write(JsonWriter out, VectorConfig value) throws IOException {
16951695
@Override
16961696
public VectorConfig read(JsonReader in) throws IOException {
16971697
var jsonObject = JsonParser.parseReader(in).getAsJsonObject();
1698-
var vectorIndexConfig = jsonObject.get("vectorIndexConfig").getAsJsonObject();
1698+
JsonObject vectorIndexConfig = new JsonObject();
1699+
if (jsonObject.has("vectorIndexConfig")) {
1700+
// If the vector index has been dropped it will still be present in the
1701+
// response, but won't contain "vectorIndexConfig" and "vectorIndexType" fields.
1702+
vectorIndexConfig = jsonObject.get("vectorIndexConfig").getAsJsonObject();
1703+
}
16991704

17001705
String quantizationKind = null;
17011706
for (var kind : new String[] {

src/main/java/io/weaviate/client6/v1/api/collections/VectorIndex.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,22 @@ public void write(JsonWriter out, VectorIndex value) throws IOException {
137137
public VectorIndex read(JsonReader in) throws IOException {
138138
var jsonObject = JsonParser.parseReader(in).getAsJsonObject();
139139

140+
var vectorIndexType = jsonObject.get("vectorIndexType");
141+
if (vectorIndexType == null || vectorIndexType.isJsonNull()) {
142+
// VectorConfig.CustomTypeAdapterFactory cannot provide this
143+
// value for vector indexes that have been dropped.
144+
return null;
145+
}
146+
147+
var vectorIndexConfig = jsonObject.get("vectorIndexConfig");
148+
if (vectorIndexConfig == null || vectorIndexConfig.isJsonNull()) {
149+
// VectorConfig.CustomTypeAdapterFactory cannot provide this
150+
// value for vector indexes that have been dropped.
151+
return null;
152+
}
153+
140154
VectorIndex.Kind kind;
141-
var kindString = jsonObject.get("vectorIndexType").getAsString();
155+
var kindString = vectorIndexType.getAsString();
142156
try {
143157
kind = VectorIndex.Kind.valueOfJson(kindString);
144158
} catch (IllegalArgumentException e) {
@@ -150,7 +164,7 @@ public VectorIndex read(JsonReader in) throws IOException {
150164
return null;
151165
}
152166

153-
var config = jsonObject.get("vectorIndexConfig").getAsJsonObject();
167+
var config = vectorIndexConfig.getAsJsonObject();
154168
return adapter.fromJsonTree(config);
155169
}
156170
}.nullSafe();
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package io.weaviate.client6.v1.api.collections.config;
2+
3+
import java.util.Collections;
4+
5+
import io.weaviate.client6.v1.internal.rest.Endpoint;
6+
import io.weaviate.client6.v1.internal.rest.SimpleEndpoint;
7+
8+
public record DeleteVectorIndexRequest(String collectionName, String vectorName) {
9+
public static final Endpoint<DeleteVectorIndexRequest, Void> _ENDPOINT = SimpleEndpoint.sideEffect(
10+
request -> "DELETE",
11+
request -> "/schema/" + request.collectionName + "/vectors/" + request.vectorName + "/index",
12+
request -> Collections.emptyMap());
13+
}

src/main/java/io/weaviate/client6/v1/api/collections/config/WeaviateConfigClient.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ public void dropPropertyIndex(String propertyName, PropertyIndexType indexType)
5858
DeletePropertyIndexRequest._ENDPOINT);
5959
}
6060

61+
public void dropVectorIndex(String vectorName) throws IOException {
62+
this.restTransport.performRequest(
63+
new DeleteVectorIndexRequest(collection.collectionName(), vectorName),
64+
DeleteVectorIndexRequest._ENDPOINT);
65+
}
66+
6167
public void addReference(String propertyName, String... dataTypes) throws IOException {
6268
this.addProperty(ReferenceProperty.to(propertyName, dataTypes).toProperty());
6369
}

src/main/java/io/weaviate/client6/v1/api/collections/config/WeaviateConfigClientAsync.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ public CompletableFuture<Void> dropPropertyIndex(String propertyName, PropertyIn
5959
DeletePropertyIndexRequest._ENDPOINT);
6060
}
6161

62+
public CompletableFuture<Void> dropVectorIndex(String vectorName) throws IOException {
63+
return this.restTransport.performRequestAsync(
64+
new DeleteVectorIndexRequest(collection.collectionName(), vectorName),
65+
DeleteVectorIndexRequest._ENDPOINT);
66+
}
67+
6268
public CompletableFuture<Void> addReference(String name, String... dataTypes) throws IOException {
6369
return this.addProperty(ReferenceProperty.to(name, dataTypes).toProperty());
6470
}

0 commit comments

Comments
 (0)