Skip to content
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
23 changes: 15 additions & 8 deletions src/main/java/io/weaviate/client/v1/async/schema/Schema.java
Original file line number Diff line number Diff line change
@@ -1,34 +1,36 @@
package io.weaviate.client.v1.async.schema;

import org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient;

import io.weaviate.client.Config;
import io.weaviate.client.base.util.DbVersionSupport;
import io.weaviate.client.v1.async.schema.api.ClassCreator;
import io.weaviate.client.v1.async.schema.api.ClassDeleter;
import io.weaviate.client.v1.async.schema.api.ClassExists;
import io.weaviate.client.v1.async.schema.api.ClassGetter;
import io.weaviate.client.v1.async.schema.api.ClassUpdater;
import io.weaviate.client.v1.async.schema.api.SchemaGetter;
import io.weaviate.client.v1.async.schema.api.PropertyCreator;
import io.weaviate.client.v1.async.schema.api.SchemaDeleter;
import io.weaviate.client.v1.async.schema.api.ShardsGetter;
import io.weaviate.client.v1.async.schema.api.SchemaGetter;
import io.weaviate.client.v1.async.schema.api.ShardUpdater;
import io.weaviate.client.v1.async.schema.api.ShardsGetter;
import io.weaviate.client.v1.async.schema.api.ShardsUpdater;
import io.weaviate.client.v1.async.schema.api.TenantsCreator;
import io.weaviate.client.v1.async.schema.api.TenantsGetter;
import io.weaviate.client.v1.async.schema.api.TenantsUpdater;
import io.weaviate.client.v1.async.schema.api.TenantsDeleter;
import io.weaviate.client.v1.async.schema.api.TenantsExists;

import io.weaviate.client.v1.async.schema.api.TenantsGetter;
import io.weaviate.client.v1.async.schema.api.TenantsUpdater;
import io.weaviate.client.v1.async.schema.api.VectorAdder;
import io.weaviate.client.v1.auth.provider.AccessTokenProvider;
import org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient;

public class Schema {
private final CloseableHttpAsyncClient client;
private final Config config;
private final AccessTokenProvider tokenProvider;
private final DbVersionSupport dbVersionSupport;

public Schema(CloseableHttpAsyncClient client, Config config, AccessTokenProvider tokenProvider, DbVersionSupport dbVersionSupport) {
public Schema(CloseableHttpAsyncClient client, Config config, AccessTokenProvider tokenProvider,
DbVersionSupport dbVersionSupport) {
this.client = client;
this.config = config;
this.tokenProvider = tokenProvider;
Expand Down Expand Up @@ -63,8 +65,13 @@ public PropertyCreator propertyCreator() {
return new PropertyCreator(client, config, tokenProvider);
}

public VectorAdder vectorAdder() {
return new VectorAdder(client, config, tokenProvider);
}

public SchemaDeleter allDeleter() {
return new SchemaDeleter(new SchemaGetter(client, config, tokenProvider), new ClassDeleter(client, config, tokenProvider));
return new SchemaDeleter(new SchemaGetter(client, config, tokenProvider),
new ClassDeleter(client, config, tokenProvider));
}

public ShardsGetter shardsGetter() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package io.weaviate.client.v1.async.schema.api;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;

import org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient;
import org.apache.hc.core5.concurrent.FutureCallback;
import org.apache.hc.core5.http.ContentType;
import org.apache.hc.core5.http.HttpResponse;

import io.weaviate.client.Config;
import io.weaviate.client.base.AsyncBaseClient;
import io.weaviate.client.base.AsyncClientResult;
import io.weaviate.client.base.Response;
import io.weaviate.client.base.Result;
import io.weaviate.client.base.http.async.ResponseParser;
import io.weaviate.client.base.util.UrlEncoder;
import io.weaviate.client.v1.auth.provider.AccessTokenProvider;
import io.weaviate.client.v1.schema.model.WeaviateClass;
import io.weaviate.client.v1.schema.model.WeaviateClass.VectorConfig;

public class VectorAdder extends AsyncBaseClient<Boolean> implements AsyncClientResult<Boolean> {
private final ClassGetter getter;

private String className;
private Map<String, VectorConfig> addedVectors = new HashMap<>();

public VectorAdder(CloseableHttpAsyncClient client, Config config, AccessTokenProvider tokenProvider) {
super(client, config, tokenProvider);
this.getter = new ClassGetter(client, config, tokenProvider);
}

public VectorAdder withClassName(String className) {
this.className = className;
return this;
}

/**
* Add a named vectors. This method can be chained to add multiple named vectors
* without using a {@link Map}.
*/
public VectorAdder withVectorConfig(String name, VectorConfig vector) {
this.addedVectors.put(name, vector);
return this;
}

/**
* Add all vectors from the map. This will overwrite any vectors added
* previously.
*/
public VectorAdder withVectorConfig(Map<String, VectorConfig> vectors) {
this.addedVectors = Collections.unmodifiableMap(vectors);
return this;
}

@Override
public Future<Result<Boolean>> run(FutureCallback<Result<Boolean>> callback) {
CompletableFuture<Result<WeaviateClass>> getClass = CompletableFuture.supplyAsync(() -> {
try {
return getter.withClassName(className).run().get();
} catch (InterruptedException | ExecutionException e) {
throw new CompletionException(e);
}
});
CompletableFuture<Result<Boolean>> addVectors = getClass.<Result<Boolean>>thenApplyAsync(result -> {
if (result.getError() != null) {
return result.toErrorResult();
}
WeaviateClass cls = result.getResult();
addedVectors.entrySet().stream()
.forEach(vector -> cls.getVectorConfig()
.putIfAbsent(vector.getKey(), vector.getValue()));

String path = String.format("/schema/%s", UrlEncoder.encodePathParam(className));
try {
return sendPutRequest(path, cls, callback, new ResponseParser<Boolean>() {

@Override
public Result<Boolean> parse(HttpResponse response, String body, ContentType contentType) {
Response<WeaviateClass> resp = this.serializer.toResponse(response.getCode(), body, WeaviateClass.class);
return new Result<>(response.getCode(), response.getCode() <= 299, resp.getErrors());
}
}).get();
} catch (InterruptedException | ExecutionException e) {
throw new CompletionException(e);
}
});

return addVectors;
}
}
5 changes: 5 additions & 0 deletions src/main/java/io/weaviate/client/v1/schema/Schema.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import io.weaviate.client.v1.schema.api.TenantsExists;
import io.weaviate.client.v1.schema.api.TenantsGetter;
import io.weaviate.client.v1.schema.api.TenantsUpdater;
import io.weaviate.client.v1.schema.api.VectorAdder;

public class Schema {
private final Config config;
Expand Down Expand Up @@ -59,6 +60,10 @@ public PropertyCreator propertyCreator() {
return new PropertyCreator(httpClient, config);
}

public VectorAdder vectorAdder() {
return new VectorAdder(httpClient, config);
}

public SchemaDeleter allDeleter() {
return new SchemaDeleter(new SchemaGetter(httpClient, config), new ClassDeleter(httpClient, config));
}
Expand Down
67 changes: 67 additions & 0 deletions src/main/java/io/weaviate/client/v1/schema/api/VectorAdder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package io.weaviate.client.v1.schema.api;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

import io.weaviate.client.Config;
import io.weaviate.client.base.BaseClient;
import io.weaviate.client.base.ClientResult;
import io.weaviate.client.base.Response;
import io.weaviate.client.base.Result;
import io.weaviate.client.base.http.HttpClient;
import io.weaviate.client.base.util.UrlEncoder;
import io.weaviate.client.v1.schema.model.WeaviateClass;
import io.weaviate.client.v1.schema.model.WeaviateClass.VectorConfig;

public class VectorAdder extends BaseClient<WeaviateClass> implements ClientResult<Boolean> {
private final ClassGetter getter;

private String className;
private Map<String, VectorConfig> addedVectors = new HashMap<>();

public VectorAdder(HttpClient httpClient, Config config) {
super(httpClient, config);
this.getter = new ClassGetter(httpClient, config);
}

public VectorAdder withClassName(String className) {
this.className = className;
return this;
}

/**
* Add a named vectors. This method can be chained to add multiple named vectors
* without using a {@link Map}.
*/
public VectorAdder withVectorConfig(String name, VectorConfig vector) {
this.addedVectors.put(name, vector);
return this;
}

/**
* Add all vectors from the map. This will overwrite any vectors added
* previously.
*/
public VectorAdder withVectorConfig(Map<String, VectorConfig> vectors) {
this.addedVectors = Collections.unmodifiableMap(vectors);
return this;
}

@Override
public Result<Boolean> run() {
Result<WeaviateClass> result = getter.withClassName(className).run();
if (result.hasErrors()) {
result.toErrorResult();
}

WeaviateClass cls = result.getResult();
addedVectors.entrySet().stream()
.forEach(vector -> cls.getVectorConfig()
.putIfAbsent(vector.getKey(), vector.getValue()));

String path = String.format("/schema/%s", UrlEncoder.encodePathParam(className));
Response<WeaviateClass> resp = sendPutRequest(path, cls, WeaviateClass.class);
return new Result<>(resp.getStatusCode(), resp.getStatusCode() == 200, resp.getErrors());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
public class WeaviateVersion {

// docker image version
public static final String WEAVIATE_IMAGE = "1.31.0-rc.0-5ff7495";
public static final String WEAVIATE_IMAGE = "1.31.0";

// to be set according to weaviate docker image
public static final String EXPECTED_WEAVIATE_VERSION = "1.31.0-rc.0";
public static final String EXPECTED_WEAVIATE_VERSION = "1.31.0";
// to be set according to weaviate docker image
public static final String EXPECTED_WEAVIATE_GIT_HASH = "5ff7495";
public static final String EXPECTED_WEAVIATE_GIT_HASH = "79499d6";

private WeaviateVersion() {}
private WeaviateVersion() {
}
}
Loading