Преглед изворни кода

返回向量数据库查询列表

lamphua пре 1 недеља
родитељ
комит
fcc47deb1a

+ 7
- 8
llm-back/ruoyi-agent/src/main/java/com/ruoyi/agent/controller/KnowLedgeController.java Прегледај датотеку

@@ -1,5 +1,6 @@
1 1
 package com.ruoyi.agent.controller;
2 2
 
3
+import com.alibaba.fastjson2.JSONObject;
3 4
 import com.ruoyi.agent.service.LangChainMilvusService;
4 5
 import com.ruoyi.common.config.RuoYiConfig;
5 6
 import com.ruoyi.common.core.controller.BaseController;
@@ -33,8 +34,7 @@ public class KnowLedgeController extends BaseController
33 34
     @GetMapping("/list")
34 35
     public AjaxResult listKnowLedgeCollection()
35 36
     {
36
-        List<String> collectionNames = milvusService.getCollectionNames();
37
-        milvusService.close();
37
+        JSONObject collectionNames = milvusService.getCollectionNames();
38 38
         return success(collectionNames);
39 39
     }
40 40
 
@@ -42,10 +42,10 @@ public class KnowLedgeController extends BaseController
42 42
      * 新建知识库
43 43
      */
44 44
     @PostMapping("/create")
45
-    public AjaxResult createKnowLedgeCollection(String collectionName)
45
+    public AjaxResult createKnowLedgeCollection(String collectionName, String description)
46 46
     {
47
-        milvusService.createCollection(collectionName, 512);
48
-        milvusService.close();
47
+        milvusService.createCollection(collectionName, description, 512);
48
+        milvusService.releaseCollectionName(collectionName);
49 49
         return success();
50 50
     }
51 51
 
@@ -56,7 +56,7 @@ public class KnowLedgeController extends BaseController
56 56
     public AjaxResult modifyKnowLedgeCollection(String collectionName, String newCollectionName)
57 57
     {
58 58
         milvusService.collectionRename(collectionName, newCollectionName);
59
-        milvusService.close();
59
+        milvusService.releaseCollectionName(collectionName);
60 60
         return success();
61 61
     }
62 62
 
@@ -67,7 +67,6 @@ public class KnowLedgeController extends BaseController
67 67
     public AjaxResult removeKnowLedgeCollection(String collectionName)
68 68
     {
69 69
         milvusService.deleteCollectionName(collectionName);
70
-        milvusService.close();
71 70
         return success();
72 71
     }
73 72
 
@@ -91,7 +90,7 @@ public class KnowLedgeController extends BaseController
91 90
             file.transferTo(transferFile);
92 91
         }
93 92
         langChainMilvusService.insertLangchainEmbeddingDocument(transferFile);
94
-        langChainMilvusService.close();
93
+        langChainMilvusService.releaseCollectionName(collectionName);
95 94
         return success();
96 95
     }
97 96
 

+ 1
- 1
llm-back/ruoyi-agent/src/main/java/com/ruoyi/agent/controller/RagController.java Прегледај датотеку

@@ -13,7 +13,7 @@ import java.io.IOException;
13 13
 import java.util.List;
14 14
 
15 15
 /**
16
- * cmc知识库Controller
16
+ * rag增强检索生成对话Controller
17 17
  * 
18 18
  * @author cmc
19 19
  * @date 2025-04-08

+ 2
- 2
llm-back/ruoyi-agent/src/main/java/com/ruoyi/agent/controller/SessionController.java Прегледај датотеку

@@ -12,7 +12,7 @@ import java.io.IOException;
12 12
 import java.util.concurrent.TimeUnit;
13 13
 
14 14
 /**
15
- * cmc知识库Controller
15
+ * session对话Controller
16 16
  * 
17 17
  * @author cmc
18 18
  * @date 2025-04-08
@@ -37,7 +37,7 @@ public class SessionController extends BaseController
37 37
         HttpUrl url = HttpUrl.parse("http://192.168.28.188:8000/generate")
38 38
                 .newBuilder()
39 39
                 .addQueryParameter("prompt", question)
40
-                .addQueryParameter("max_token", String.valueOf(1024))
40
+//                .addQueryParameter("max_token", String.valueOf(1024))
41 41
                 .build();
42 42
 
43 43
         Request request = new Request.Builder()

+ 13
- 2
llm-back/ruoyi-agent/src/main/java/com/ruoyi/agent/service/LangChainMilvusService.java Прегледај датотеку

@@ -15,6 +15,7 @@ import io.milvus.param.MetricType;
15 15
 import io.milvus.param.R;
16 16
 import io.milvus.param.RpcStatus;
17 17
 import io.milvus.param.collection.LoadCollectionParam;
18
+import io.milvus.param.collection.ReleaseCollectionParam;
18 19
 import io.milvus.param.dml.InsertParam;
19 20
 import io.milvus.param.dml.SearchParam;
20 21
 import io.milvus.response.SearchResultsWrapper;
@@ -44,7 +45,7 @@ public class LangChainMilvusService {
44 45
                         .withPort(port)
45 46
                         .build()
46 47
         );
47
-        this.LLM_SERVICE_URL = "http://" + host + ":8080/generate";
48
+        this.LLM_SERVICE_URL = "http://" + host + ":8000/generate";
48 49
         this.collectionName = collectionName;
49 50
         this.embeddingModel = embeddingModel;
50 51
     }
@@ -131,7 +132,7 @@ public class LangChainMilvusService {
131 132
         HttpUrl url = HttpUrl.parse(LLM_SERVICE_URL)
132 133
                 .newBuilder()
133 134
                 .addQueryParameter("prompt", prompt)
134
-                .addQueryParameter("max_token", String.valueOf(1024))
135
+//                .addQueryParameter("max_token", String.valueOf(1024))
135 136
                 .build();
136 137
 
137 138
         Request request = new Request.Builder()
@@ -159,6 +160,16 @@ public class LangChainMilvusService {
159 160
         return sb.toString();
160 161
     }
161 162
 
163
+    /**
164
+     * 释放知识库Collection
165
+     */
166
+    public void releaseCollectionName(String collectionName) {
167
+        ReleaseCollectionParam param = ReleaseCollectionParam.newBuilder()
168
+                .withCollectionName(collectionName)
169
+                .build();
170
+        milvusClient.releaseCollection(param);
171
+    }
172
+
162 173
     public void close() {
163 174
         milvusClient.close();
164 175
     }

+ 32
- 8
llm-back/ruoyi-agent/src/main/java/com/ruoyi/agent/service/MilvusService.java Прегледај датотеку

@@ -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
     }

Loading…
Откажи
Сачувај