|
@@ -29,14 +29,13 @@ import io.grpc.ManagedChannel;
|
|
import io.grpc.ManagedChannelBuilder;
|
|
import io.grpc.ManagedChannelBuilder;
|
|
import io.grpc.StatusRuntimeException;
|
|
import io.grpc.StatusRuntimeException;
|
|
import io.milvus.grpc.*;
|
|
import io.milvus.grpc.*;
|
|
-
|
|
|
|
-import javax.annotation.Nonnull;
|
|
|
|
import java.nio.Buffer;
|
|
import java.nio.Buffer;
|
|
import java.nio.ByteBuffer;
|
|
import java.nio.ByteBuffer;
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
import java.util.concurrent.TimeUnit;
|
|
import java.util.concurrent.TimeUnit;
|
|
import java.util.function.Function;
|
|
import java.util.function.Function;
|
|
|
|
+import javax.annotation.Nonnull;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
@@ -96,7 +95,8 @@ public class MilvusGrpcClient implements MilvusClient {
|
|
// check server version
|
|
// check server version
|
|
String serverVersion = getServerVersion().getMessage();
|
|
String serverVersion = getServerVersion().getMessage();
|
|
if (!serverVersion.contains("0.10.")) {
|
|
if (!serverVersion.contains("0.10.")) {
|
|
- logError("Connect failed! Server version {} does not match SDK version 0.8.2", serverVersion);
|
|
|
|
|
|
+ logError(
|
|
|
|
+ "Connect failed! Server version {} does not match SDK version 0.8.2", serverVersion);
|
|
throw new ConnectFailedException("Failed to connect to Milvus server.");
|
|
throw new ConnectFailedException("Failed to connect to Milvus server.");
|
|
}
|
|
}
|
|
|
|
|
|
@@ -109,7 +109,8 @@ public class MilvusGrpcClient implements MilvusClient {
|
|
|
|
|
|
logInfo(
|
|
logInfo(
|
|
"Connection established successfully to host={}, port={}",
|
|
"Connection established successfully to host={}, port={}",
|
|
- connectParam.getHost(), String.valueOf(connectParam.getPort()));
|
|
|
|
|
|
+ connectParam.getHost(),
|
|
|
|
+ String.valueOf(connectParam.getPort()));
|
|
return new Response(Response.Status.SUCCESS);
|
|
return new Response(Response.Status.SUCCESS);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -173,8 +174,7 @@ public class MilvusGrpcClient implements MilvusClient {
|
|
Response.Status.valueOf(response.getErrorCodeValue()), response.getReason());
|
|
Response.Status.valueOf(response.getErrorCodeValue()), response.getReason());
|
|
} else {
|
|
} else {
|
|
logError(
|
|
logError(
|
|
- "Create collection failed\n{}\n{}",
|
|
|
|
- collectionMapping.toString(), response.toString());
|
|
|
|
|
|
+ "Create collection failed\n{}\n{}", collectionMapping.toString(), response.toString());
|
|
return new Response(
|
|
return new Response(
|
|
Response.Status.valueOf(response.getErrorCodeValue()), response.getReason());
|
|
Response.Status.valueOf(response.getErrorCodeValue()), response.getReason());
|
|
}
|
|
}
|
|
@@ -347,7 +347,9 @@ public class MilvusGrpcClient implements MilvusClient {
|
|
} else {
|
|
} else {
|
|
logError(
|
|
logError(
|
|
"Create partition `{}` in collection `{}` failed: {}",
|
|
"Create partition `{}` in collection `{}` failed: {}",
|
|
- tag, collectionName, response.toString());
|
|
|
|
|
|
+ tag,
|
|
|
|
+ collectionName,
|
|
|
|
+ response.toString());
|
|
return new Response(
|
|
return new Response(
|
|
Response.Status.valueOf(response.getErrorCodeValue()), response.getReason());
|
|
Response.Status.valueOf(response.getErrorCodeValue()), response.getReason());
|
|
}
|
|
}
|
|
@@ -373,21 +375,28 @@ public class MilvusGrpcClient implements MilvusClient {
|
|
response = blockingStub.hasPartition(request);
|
|
response = blockingStub.hasPartition(request);
|
|
|
|
|
|
if (response.getStatus().getErrorCode() == ErrorCode.SUCCESS) {
|
|
if (response.getStatus().getErrorCode() == ErrorCode.SUCCESS) {
|
|
- logInfo("hasPartition with tag `{}` in `{}` = {}", tag, collectionName, response.getBoolReply());
|
|
|
|
|
|
+ logInfo(
|
|
|
|
+ "hasPartition with tag `{}` in `{}` = {}",
|
|
|
|
+ tag,
|
|
|
|
+ collectionName,
|
|
|
|
+ response.getBoolReply());
|
|
return new HasPartitionResponse(
|
|
return new HasPartitionResponse(
|
|
- new Response(Response.Status.SUCCESS), response.getBoolReply());
|
|
|
|
|
|
+ new Response(Response.Status.SUCCESS), response.getBoolReply());
|
|
} else {
|
|
} else {
|
|
- logError("hasPartition with tag `{}` in `{}` failed:\n{}", tag, collectionName, response.toString());
|
|
|
|
|
|
+ logError(
|
|
|
|
+ "hasPartition with tag `{}` in `{}` failed:\n{}",
|
|
|
|
+ tag,
|
|
|
|
+ collectionName,
|
|
|
|
+ response.toString());
|
|
return new HasPartitionResponse(
|
|
return new HasPartitionResponse(
|
|
- new Response(
|
|
|
|
- Response.Status.valueOf(response.getStatus().getErrorCodeValue()),
|
|
|
|
- response.getStatus().getReason()),
|
|
|
|
- false);
|
|
|
|
|
|
+ new Response(
|
|
|
|
+ Response.Status.valueOf(response.getStatus().getErrorCodeValue()),
|
|
|
|
+ response.getStatus().getReason()),
|
|
|
|
+ false);
|
|
}
|
|
}
|
|
} catch (StatusRuntimeException e) {
|
|
} catch (StatusRuntimeException e) {
|
|
logError("hasPartition RPC failed:\n{}", e.getStatus().toString());
|
|
logError("hasPartition RPC failed:\n{}", e.getStatus().toString());
|
|
- return new HasPartitionResponse(
|
|
|
|
- new Response(Response.Status.RPC_ERROR, e.toString()), false);
|
|
|
|
|
|
+ return new HasPartitionResponse(new Response(Response.Status.RPC_ERROR, e.toString()), false);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -409,7 +418,8 @@ public class MilvusGrpcClient implements MilvusClient {
|
|
if (response.getStatus().getErrorCode() == ErrorCode.SUCCESS) {
|
|
if (response.getStatus().getErrorCode() == ErrorCode.SUCCESS) {
|
|
logInfo(
|
|
logInfo(
|
|
"Current partitions of collection {}: {}",
|
|
"Current partitions of collection {}: {}",
|
|
- collectionName, response.getPartitionTagArrayList());
|
|
|
|
|
|
+ collectionName,
|
|
|
|
+ response.getPartitionTagArrayList());
|
|
return new ListPartitionsResponse(
|
|
return new ListPartitionsResponse(
|
|
new Response(Response.Status.SUCCESS), response.getPartitionTagArrayList());
|
|
new Response(Response.Status.SUCCESS), response.getPartitionTagArrayList());
|
|
} else {
|
|
} else {
|
|
@@ -448,7 +458,9 @@ public class MilvusGrpcClient implements MilvusClient {
|
|
} else {
|
|
} else {
|
|
logError(
|
|
logError(
|
|
"Drop partition `{}` in collection `{}` failed:\n{}",
|
|
"Drop partition `{}` in collection `{}` failed:\n{}",
|
|
- tag, collectionName, response.toString());
|
|
|
|
|
|
+ tag,
|
|
|
|
+ collectionName,
|
|
|
|
+ response.toString());
|
|
return new Response(
|
|
return new Response(
|
|
Response.Status.valueOf(response.getErrorCodeValue()), response.getReason());
|
|
Response.Status.valueOf(response.getErrorCodeValue()), response.getReason());
|
|
}
|
|
}
|
|
@@ -485,7 +497,8 @@ public class MilvusGrpcClient implements MilvusClient {
|
|
if (response.getStatus().getErrorCode() == ErrorCode.SUCCESS) {
|
|
if (response.getStatus().getErrorCode() == ErrorCode.SUCCESS) {
|
|
logInfo(
|
|
logInfo(
|
|
"Inserted {} vectors to collection `{}` successfully!",
|
|
"Inserted {} vectors to collection `{}` successfully!",
|
|
- response.getVectorIdArrayCount(), insertParam.getCollectionName());
|
|
|
|
|
|
+ response.getVectorIdArrayCount(),
|
|
|
|
+ insertParam.getCollectionName());
|
|
return new InsertResponse(
|
|
return new InsertResponse(
|
|
new Response(Response.Status.SUCCESS), response.getVectorIdArrayList());
|
|
new Response(Response.Status.SUCCESS), response.getVectorIdArrayList());
|
|
} else {
|
|
} else {
|
|
@@ -536,7 +549,8 @@ public class MilvusGrpcClient implements MilvusClient {
|
|
if (result.getStatus().getErrorCode() == ErrorCode.SUCCESS) {
|
|
if (result.getStatus().getErrorCode() == ErrorCode.SUCCESS) {
|
|
logInfo(
|
|
logInfo(
|
|
"Inserted {} vectors to collection `{}` successfully!",
|
|
"Inserted {} vectors to collection `{}` successfully!",
|
|
- result.getVectorIdArrayCount(), insertParam.getCollectionName());
|
|
|
|
|
|
+ result.getVectorIdArrayCount(),
|
|
|
|
+ insertParam.getCollectionName());
|
|
} else {
|
|
} else {
|
|
logError("InsertAsync failed:\n{}", result.getStatus().toString());
|
|
logError("InsertAsync failed:\n{}", result.getStatus().toString());
|
|
}
|
|
}
|
|
@@ -722,7 +736,8 @@ public class MilvusGrpcClient implements MilvusClient {
|
|
} else {
|
|
} else {
|
|
logError(
|
|
logError(
|
|
"Get Collection Info `{}` failed:\n{}",
|
|
"Get Collection Info `{}` failed:\n{}",
|
|
- collectionName, response.getStatus().toString());
|
|
|
|
|
|
+ collectionName,
|
|
|
|
+ response.getStatus().toString());
|
|
return new GetCollectionInfoResponse(
|
|
return new GetCollectionInfoResponse(
|
|
new Response(
|
|
new Response(
|
|
Response.Status.valueOf(response.getStatus().getErrorCodeValue()),
|
|
Response.Status.valueOf(response.getStatus().getErrorCodeValue()),
|
|
@@ -775,8 +790,7 @@ public class MilvusGrpcClient implements MilvusClient {
|
|
|
|
|
|
if (!channelIsReadyOrIdle()) {
|
|
if (!channelIsReadyOrIdle()) {
|
|
logWarning("You are not connected to Milvus server");
|
|
logWarning("You are not connected to Milvus server");
|
|
- return new CountEntitiesResponse(
|
|
|
|
- new Response(Response.Status.CLIENT_NOT_CONNECTED), 0);
|
|
|
|
|
|
+ return new CountEntitiesResponse(new Response(Response.Status.CLIENT_NOT_CONNECTED), 0);
|
|
}
|
|
}
|
|
|
|
|
|
CollectionName request = CollectionName.newBuilder().setCollectionName(collectionName).build();
|
|
CollectionName request = CollectionName.newBuilder().setCollectionName(collectionName).build();
|
|
@@ -788,12 +802,12 @@ public class MilvusGrpcClient implements MilvusClient {
|
|
if (response.getStatus().getErrorCode() == ErrorCode.SUCCESS) {
|
|
if (response.getStatus().getErrorCode() == ErrorCode.SUCCESS) {
|
|
long collectionRowCount = response.getCollectionRowCount();
|
|
long collectionRowCount = response.getCollectionRowCount();
|
|
logInfo("Collection `{}` has {} entities", collectionName, collectionRowCount);
|
|
logInfo("Collection `{}` has {} entities", collectionName, collectionRowCount);
|
|
- return new CountEntitiesResponse(
|
|
|
|
- new Response(Response.Status.SUCCESS), collectionRowCount);
|
|
|
|
|
|
+ return new CountEntitiesResponse(new Response(Response.Status.SUCCESS), collectionRowCount);
|
|
} else {
|
|
} else {
|
|
logError(
|
|
logError(
|
|
"Get collection `{}` entity count failed:\n{}",
|
|
"Get collection `{}` entity count failed:\n{}",
|
|
- collectionName, response.getStatus().toString());
|
|
|
|
|
|
+ collectionName,
|
|
|
|
+ response.getStatus().toString());
|
|
return new CountEntitiesResponse(
|
|
return new CountEntitiesResponse(
|
|
new Response(
|
|
new Response(
|
|
Response.Status.valueOf(response.getStatus().getErrorCodeValue()),
|
|
Response.Status.valueOf(response.getStatus().getErrorCodeValue()),
|
|
@@ -802,8 +816,7 @@ public class MilvusGrpcClient implements MilvusClient {
|
|
}
|
|
}
|
|
} catch (StatusRuntimeException e) {
|
|
} catch (StatusRuntimeException e) {
|
|
logError("countEntities RPC failed:\n{}", e.getStatus().toString());
|
|
logError("countEntities RPC failed:\n{}", e.getStatus().toString());
|
|
- return new CountEntitiesResponse(
|
|
|
|
- new Response(Response.Status.RPC_ERROR, e.toString()), 0);
|
|
|
|
|
|
+ return new CountEntitiesResponse(new Response(Response.Status.RPC_ERROR, e.toString()), 0);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -895,7 +908,8 @@ public class MilvusGrpcClient implements MilvusClient {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
Index index =
|
|
Index index =
|
|
- new Index.Builder(response.getCollectionName(), IndexType.valueOf(response.getIndexType()))
|
|
|
|
|
|
+ new Index.Builder(
|
|
|
|
+ response.getCollectionName(), IndexType.valueOf(response.getIndexType()))
|
|
.withParamsInJson(extraParam)
|
|
.withParamsInJson(extraParam)
|
|
.build();
|
|
.build();
|
|
logInfo(
|
|
logInfo(
|
|
@@ -904,7 +918,8 @@ public class MilvusGrpcClient implements MilvusClient {
|
|
} else {
|
|
} else {
|
|
logError(
|
|
logError(
|
|
"Get index info for collection `{}` failed:\n{}",
|
|
"Get index info for collection `{}` failed:\n{}",
|
|
- collectionName, response.getStatus().toString());
|
|
|
|
|
|
+ collectionName,
|
|
|
|
+ response.getStatus().toString());
|
|
return new GetIndexInfoResponse(
|
|
return new GetIndexInfoResponse(
|
|
new Response(
|
|
new Response(
|
|
Response.Status.valueOf(response.getStatus().getErrorCodeValue()),
|
|
Response.Status.valueOf(response.getStatus().getErrorCodeValue()),
|
|
@@ -935,8 +950,7 @@ public class MilvusGrpcClient implements MilvusClient {
|
|
logInfo("Dropped index for collection `{}` successfully!", collectionName);
|
|
logInfo("Dropped index for collection `{}` successfully!", collectionName);
|
|
return new Response(Response.Status.SUCCESS);
|
|
return new Response(Response.Status.SUCCESS);
|
|
} else {
|
|
} else {
|
|
- logError(
|
|
|
|
- "Drop index for collection `{}` failed:\n{}", collectionName, response.toString());
|
|
|
|
|
|
+ logError("Drop index for collection `{}` failed:\n{}", collectionName, response.toString());
|
|
return new Response(
|
|
return new Response(
|
|
Response.Status.valueOf(response.getErrorCodeValue()), response.getReason());
|
|
Response.Status.valueOf(response.getErrorCodeValue()), response.getReason());
|
|
}
|
|
}
|
|
@@ -965,10 +979,11 @@ public class MilvusGrpcClient implements MilvusClient {
|
|
} else {
|
|
} else {
|
|
logError(
|
|
logError(
|
|
"getCollectionStats for `{}` failed:\n{}",
|
|
"getCollectionStats for `{}` failed:\n{}",
|
|
- collectionName, response.getStatus().toString());
|
|
|
|
|
|
+ collectionName,
|
|
|
|
+ response.getStatus().toString());
|
|
return new Response(
|
|
return new Response(
|
|
- Response.Status.valueOf(response.getStatus().getErrorCodeValue()),
|
|
|
|
- response.getStatus().getReason());
|
|
|
|
|
|
+ Response.Status.valueOf(response.getStatus().getErrorCodeValue()),
|
|
|
|
+ response.getStatus().getReason());
|
|
}
|
|
}
|
|
} catch (StatusRuntimeException e) {
|
|
} catch (StatusRuntimeException e) {
|
|
logError("getCollectionStats RPC failed:\n{}", e.getStatus().toString());
|
|
logError("getCollectionStats RPC failed:\n{}", e.getStatus().toString());
|
|
@@ -981,7 +996,7 @@ public class MilvusGrpcClient implements MilvusClient {
|
|
if (!channelIsReadyOrIdle()) {
|
|
if (!channelIsReadyOrIdle()) {
|
|
logWarning("You are not connected to Milvus server");
|
|
logWarning("You are not connected to Milvus server");
|
|
return new GetEntityByIDResponse(
|
|
return new GetEntityByIDResponse(
|
|
- new Response(Response.Status.CLIENT_NOT_CONNECTED), new ArrayList<>(), null);
|
|
|
|
|
|
+ new Response(Response.Status.CLIENT_NOT_CONNECTED), new ArrayList<>(), null);
|
|
}
|
|
}
|
|
|
|
|
|
VectorsIdentity request =
|
|
VectorsIdentity request =
|
|
@@ -993,8 +1008,7 @@ public class MilvusGrpcClient implements MilvusClient {
|
|
|
|
|
|
if (response.getStatus().getErrorCode() == ErrorCode.SUCCESS) {
|
|
if (response.getStatus().getErrorCode() == ErrorCode.SUCCESS) {
|
|
|
|
|
|
- logInfo(
|
|
|
|
- "getEntityByID in collection `{}` returned successfully!", collectionName);
|
|
|
|
|
|
+ logInfo("getEntityByID in collection `{}` returned successfully!", collectionName);
|
|
|
|
|
|
List<List<Float>> floatVectors = new ArrayList<>();
|
|
List<List<Float>> floatVectors = new ArrayList<>();
|
|
List<ByteBuffer> binaryVectors = new ArrayList<>();
|
|
List<ByteBuffer> binaryVectors = new ArrayList<>();
|
|
@@ -1003,12 +1017,13 @@ public class MilvusGrpcClient implements MilvusClient {
|
|
binaryVectors.add(response.getVectorsData(i).getBinaryData().asReadOnlyByteBuffer());
|
|
binaryVectors.add(response.getVectorsData(i).getBinaryData().asReadOnlyByteBuffer());
|
|
}
|
|
}
|
|
return new GetEntityByIDResponse(
|
|
return new GetEntityByIDResponse(
|
|
- new Response(Response.Status.SUCCESS), floatVectors, binaryVectors);
|
|
|
|
|
|
+ new Response(Response.Status.SUCCESS), floatVectors, binaryVectors);
|
|
|
|
|
|
} else {
|
|
} else {
|
|
logError(
|
|
logError(
|
|
"getEntityByID in collection `{}` failed:\n{}",
|
|
"getEntityByID in collection `{}` failed:\n{}",
|
|
- collectionName, response.getStatus().toString());
|
|
|
|
|
|
+ collectionName,
|
|
|
|
+ response.getStatus().toString());
|
|
return new GetEntityByIDResponse(
|
|
return new GetEntityByIDResponse(
|
|
new Response(
|
|
new Response(
|
|
Response.Status.valueOf(response.getStatus().getErrorCodeValue()),
|
|
Response.Status.valueOf(response.getStatus().getErrorCodeValue()),
|
|
@@ -1045,13 +1060,16 @@ public class MilvusGrpcClient implements MilvusClient {
|
|
|
|
|
|
logInfo(
|
|
logInfo(
|
|
"listIDInSegment in collection `{}`, segment `{}` returned successfully!",
|
|
"listIDInSegment in collection `{}`, segment `{}` returned successfully!",
|
|
- collectionName, segmentName);
|
|
|
|
|
|
+ collectionName,
|
|
|
|
+ segmentName);
|
|
return new ListIDInSegmentResponse(
|
|
return new ListIDInSegmentResponse(
|
|
new Response(Response.Status.SUCCESS), response.getVectorIdArrayList());
|
|
new Response(Response.Status.SUCCESS), response.getVectorIdArrayList());
|
|
} else {
|
|
} else {
|
|
logError(
|
|
logError(
|
|
"listIDInSegment in collection `{}`, segment `{}` failed:\n{}",
|
|
"listIDInSegment in collection `{}`, segment `{}` failed:\n{}",
|
|
- collectionName, segmentName, response.getStatus().toString());
|
|
|
|
|
|
+ collectionName,
|
|
|
|
+ segmentName,
|
|
|
|
+ response.getStatus().toString());
|
|
return new ListIDInSegmentResponse(
|
|
return new ListIDInSegmentResponse(
|
|
new Response(
|
|
new Response(
|
|
Response.Status.valueOf(response.getStatus().getErrorCodeValue()),
|
|
Response.Status.valueOf(response.getStatus().getErrorCodeValue()),
|