|
@@ -1,13 +1,15 @@
|
1
|
1
|
package com.ruoyi.agent.service;
|
2
|
2
|
|
|
3
|
+import com.alibaba.fastjson2.JSONArray;
|
3
|
4
|
import com.alibaba.fastjson2.JSONObject;
|
4
|
5
|
import io.milvus.client.MilvusServiceClient;
|
5
|
|
-import io.milvus.grpc.DataType;
|
|
6
|
+import io.milvus.grpc.*;
|
6
|
7
|
import io.milvus.param.ConnectParam;
|
7
|
8
|
import io.milvus.param.IndexType;
|
8
|
9
|
import io.milvus.param.MetricType;
|
9
|
10
|
import io.milvus.param.collection.*;
|
10
|
11
|
import io.milvus.param.highlevel.collection.ListCollectionsParam;
|
|
12
|
+import io.milvus.param.highlevel.collection.response.ListCollectionsResponse;
|
11
|
13
|
import io.milvus.param.index.CreateIndexParam;
|
12
|
14
|
|
13
|
15
|
import java.text.SimpleDateFormat;
|
|
@@ -84,21 +86,27 @@ public class MilvusService {
|
84
|
86
|
/**
|
85
|
87
|
* 查询知识库Collection
|
86
|
88
|
*/
|
87
|
|
- public JSONObject getCollectionNames() {
|
88
|
|
- JSONObject jsonObject = new JSONObject();
|
|
89
|
+ public JSONArray getCollectionNames() {
|
|
90
|
+ JSONArray jsonArray = new JSONArray();
|
89
|
91
|
ListCollectionsParam listParam = ListCollectionsParam.newBuilder().build();
|
90
|
|
- List<String> collectionNames = milvusClient.listCollections(listParam).getData().collectionNames;
|
91
|
|
- ShowCollectionsParam showParam = ShowCollectionsParam.newBuilder().withCollectionNames(collectionNames).build();
|
92
|
|
- int size = milvusClient.showCollections(showParam).getData().getCollectionIdsCount();
|
93
|
|
- for (int i = 0; i < size; i++) {
|
94
|
|
- jsonObject.put("collectionId", milvusClient.showCollections(showParam).getData().getCollectionIds(i));
|
95
|
|
- jsonObject.put("collectionName", milvusClient.showCollections(showParam).getData().getCollectionNames(i));
|
96
|
|
- SimpleDateFormat beijingFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
97
|
|
- beijingFormat.setTimeZone(TimeZone.getTimeZone("Asia/Shanghai"));
|
98
|
|
- String beijingTime = beijingFormat.format(milvusClient.showCollections(showParam).getData().getCreatedUtcTimestamps(i));
|
99
|
|
- jsonObject.put("createdTime", beijingTime);
|
|
92
|
+ ListCollectionsResponse listResponse = milvusClient.listCollections(listParam).getData();
|
|
93
|
+ if (listResponse != null) {
|
|
94
|
+ List<String> collectionNames = milvusClient.listCollections(listParam).getData().collectionNames;
|
|
95
|
+ for (int i = 0; i < collectionNames.size(); i++) {
|
|
96
|
+ JSONObject jsonObject = new JSONObject();
|
|
97
|
+ DescribeCollectionParam describeParam = DescribeCollectionParam.newBuilder().withCollectionName(collectionNames.get(i)).build();
|
|
98
|
+ DescribeCollectionResponse describeResponse = milvusClient.describeCollection(describeParam).getData();
|
|
99
|
+ jsonObject.put("collectionId", describeResponse.getCollectionID());
|
|
100
|
+ jsonObject.put("collectionName", collectionNames.get(i));
|
|
101
|
+ SimpleDateFormat beijingFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
102
|
+ beijingFormat.setTimeZone(TimeZone.getTimeZone("Asia/Shanghai"));
|
|
103
|
+ String beijingTime = beijingFormat.format(describeResponse.getCreatedUtcTimestamp());
|
|
104
|
+ jsonObject.put("createdTime", beijingTime);
|
|
105
|
+ jsonObject.put("description", describeResponse.getSchema().getDescription());
|
|
106
|
+ jsonArray.add(jsonObject);
|
|
107
|
+ }
|
100
|
108
|
}
|
101
|
|
- return jsonObject;
|
|
109
|
+ return jsonArray;
|
102
|
110
|
}
|
103
|
111
|
|
104
|
112
|
/**
|