|
@@ -1,17 +1,18 @@
|
1
|
1
|
package com.ruoyi.agent.service;
|
2
|
2
|
|
|
3
|
+import com.alibaba.fastjson2.JSONObject;
|
3
|
4
|
import io.milvus.client.MilvusServiceClient;
|
4
|
5
|
import io.milvus.grpc.DataType;
|
5
|
6
|
import io.milvus.param.ConnectParam;
|
6
|
7
|
import io.milvus.param.IndexType;
|
7
|
8
|
import io.milvus.param.MetricType;
|
8
|
|
-import io.milvus.param.collection.CreateCollectionParam;
|
9
|
|
-import io.milvus.param.collection.DropCollectionParam;
|
10
|
|
-import io.milvus.param.collection.FieldType;
|
11
|
|
-import io.milvus.param.collection.RenameCollectionParam;
|
|
9
|
+import io.milvus.param.collection.*;
|
12
|
10
|
import io.milvus.param.highlevel.collection.ListCollectionsParam;
|
13
|
11
|
import io.milvus.param.index.CreateIndexParam;
|
|
12
|
+
|
|
13
|
+import java.text.SimpleDateFormat;
|
14
|
14
|
import java.util.List;
|
|
15
|
+import java.util.TimeZone;
|
15
|
16
|
|
16
|
17
|
public class MilvusService {
|
17
|
18
|
private MilvusServiceClient milvusClient;
|
|
@@ -31,7 +32,7 @@ public class MilvusService {
|
31
|
32
|
/**
|
32
|
33
|
* 新建知识库Collection(含Schema、Field、Index)
|
33
|
34
|
*/
|
34
|
|
- public void createCollection(String collectionName, int dimension) {
|
|
35
|
+ public void createCollection(String collectionName, String description, int dimension) {
|
35
|
36
|
FieldType idField = FieldType.newBuilder()
|
36
|
37
|
.withName("id")
|
37
|
38
|
.withDataType(DataType.Int64)
|
|
@@ -59,6 +60,7 @@ public class MilvusService {
|
59
|
60
|
|
60
|
61
|
CreateCollectionParam createCollectionParam = CreateCollectionParam.newBuilder()
|
61
|
62
|
.withCollectionName(collectionName)
|
|
63
|
+ .withDescription(description)
|
62
|
64
|
.addFieldType(idField)
|
63
|
65
|
.addFieldType(fileNameField)
|
64
|
66
|
.addFieldType(contentField)
|
|
@@ -82,9 +84,21 @@ public class MilvusService {
|
82
|
84
|
/**
|
83
|
85
|
* 查询知识库Collection
|
84
|
86
|
*/
|
85
|
|
- public List<String> getCollectionNames() {
|
86
|
|
- ListCollectionsParam param = ListCollectionsParam.newBuilder().build();
|
87
|
|
- return milvusClient.listCollections(param).getData().collectionNames;
|
|
87
|
+ public JSONObject getCollectionNames() {
|
|
88
|
+ JSONObject jsonObject = new JSONObject();
|
|
89
|
+ 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);
|
|
100
|
+ }
|
|
101
|
+ return jsonObject;
|
88
|
102
|
}
|
89
|
103
|
|
90
|
104
|
/**
|
|
@@ -108,6 +122,16 @@ public class MilvusService {
|
108
|
122
|
milvusClient.dropCollection(param);
|
109
|
123
|
}
|
110
|
124
|
|
|
125
|
+ /**
|
|
126
|
+ * 释放知识库Collection
|
|
127
|
+ */
|
|
128
|
+ public void releaseCollectionName(String collectionName) {
|
|
129
|
+ ReleaseCollectionParam param = ReleaseCollectionParam.newBuilder()
|
|
130
|
+ .withCollectionName(collectionName)
|
|
131
|
+ .build();
|
|
132
|
+ milvusClient.releaseCollection(param);
|
|
133
|
+ }
|
|
134
|
+
|
111
|
135
|
public void close() {
|
112
|
136
|
milvusClient.close();
|
113
|
137
|
}
|