-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switch to vector bytes field to send vector when using gRPC
- Loading branch information
1 parent
339405e
commit 9de56e3
Showing
15 changed files
with
283 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
src/main/java/io/weaviate/client/base/util/GrpcVersionSupport.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package io.weaviate.client.base.util; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.apache.commons.lang3.StringUtils; | ||
|
||
@RequiredArgsConstructor | ||
public class GrpcVersionSupport { | ||
|
||
private final DbVersionProvider provider; | ||
|
||
public boolean supportsVectorBytesField() { | ||
String[] versionNumbers = StringUtils.split(provider.getVersion(), "."); | ||
if (versionNumbers != null && versionNumbers.length >= 2) { | ||
int major = Integer.parseInt(versionNumbers[0]); | ||
int minor = Integer.parseInt(versionNumbers[1]); | ||
if (major == 1 && minor == 22 && versionNumbers.length == 3) { | ||
String patch = versionNumbers[2]; | ||
if (!patch.contains("rc") && Integer.parseInt(patch) >= 6) { | ||
return true; | ||
} | ||
} | ||
return (major == 1 && minor >= 23) || major >= 2; | ||
} | ||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
src/test/java/io/weaviate/client/base/util/GrpcVersionSupportTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package io.weaviate.client.base.util; | ||
|
||
import com.jparams.junit4.JParamsTestRunner; | ||
import com.jparams.junit4.data.DataMethod; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.Mockito; | ||
import org.mockito.MockitoAnnotations; | ||
|
||
@RunWith(JParamsTestRunner.class) | ||
public class GrpcVersionSupportTest { | ||
|
||
private AutoCloseable openedMocks; | ||
@InjectMocks | ||
private GrpcVersionSupport grpcVersionProvider; | ||
@Mock | ||
private DbVersionProvider dbVersionProviderMock; | ||
|
||
@Before | ||
public void setUp() { | ||
openedMocks = MockitoAnnotations.openMocks(this); | ||
} | ||
|
||
@After | ||
public void tearDown() throws Exception { | ||
openedMocks.close(); | ||
} | ||
|
||
@Test | ||
@DataMethod(source = GrpcVersionSupportTest.class, method = "provideNotSupported") | ||
public void shouldNotSupportVectorBytes(String dbVersion) { | ||
Mockito.when(dbVersionProviderMock.getVersion()).thenReturn(dbVersion); | ||
|
||
assertThat(grpcVersionProvider.supportsVectorBytesField()).isFalse(); | ||
} | ||
|
||
public static Object[][] provideNotSupported() { | ||
return new Object[][]{ | ||
{"0.11"}, | ||
{"1.13.9"}, | ||
{"1.22.0-rc.0"}, | ||
{"1.22.4"}, | ||
{"1.22.5"}, | ||
}; | ||
} | ||
|
||
@Test | ||
@DataMethod(source = GrpcVersionSupportTest.class, method = "provideSupported") | ||
public void shouldSupportVectorBytes(String dbVersion) { | ||
Mockito.when(dbVersionProviderMock.getVersion()).thenReturn(dbVersion); | ||
|
||
assertThat(grpcVersionProvider.supportsVectorBytesField()).isTrue(); | ||
} | ||
|
||
public static Object[][] provideSupported() { | ||
return new Object[][]{ | ||
{"1.22.6"}, | ||
{"1.23.0-rc.0"}, | ||
{"1.23.10"}, | ||
{"1.30.1"}, | ||
{"1.31"}, | ||
{"2.31"}, | ||
{"10.11.12"}, | ||
}; | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
src/test/java/io/weaviate/integration/client/WeaviateContainer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package io.weaviate.integration.client; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import org.testcontainers.containers.GenericContainer; | ||
import org.testcontainers.containers.wait.strategy.Wait; | ||
|
||
public class WeaviateContainer { | ||
|
||
public static class DockerContainer { | ||
private final GenericContainer<?> container; | ||
|
||
private DockerContainer(GenericContainer<?> container) { | ||
this.container = container; | ||
} | ||
|
||
public void start() { | ||
container.start(); | ||
} | ||
|
||
public Integer getMappedPort(int originalPort) { | ||
return container.getMappedPort(originalPort); | ||
} | ||
|
||
public void stop() { | ||
container.stop(); | ||
} | ||
} | ||
|
||
public static DockerContainer create(String image) { | ||
Map<String, String> env = new HashMap<>(); | ||
env.put("AUTHENTICATION_ANONYMOUS_ACCESS_ENABLED", "true"); | ||
env.put("QUERY_DEFAULTS_LIMIT", "20"); | ||
env.put("PERSISTENCE_DATA_PATH", "./data"); | ||
env.put("DEFAULT_VECTORIZER_MODULE", "none"); | ||
GenericContainer<?> weaviate = new GenericContainer<>(image) | ||
.withEnv(env) | ||
.withExposedPorts(8080, 50051) | ||
.waitingFor(Wait.forListeningPorts(8080, 50051)); | ||
return new DockerContainer(weaviate); | ||
} | ||
} |
Oops, something went wrong.