@@ -60,6 +60,7 @@ public static void main(String[] args) throws InterruptedException {
6060 updateAndDelete (client );
6161 deleteAndDrop (client );
6262 testFilter ();
63+ client .close ();
6364
6465
6566 }
@@ -155,31 +156,31 @@ private static void createDatabaseAndCollection(VectorDBClient client) {
155156
156157 // 5. 设置 collection 别名
157158 System .out .println ("---------------------- setAlias ----------------------" );
158- AffectRes affectRes = db .setAlias (COLL_NAME , COLL_NAME_ALIAS );
159+ AffectRes affectRes = client .setAlias (DBNAME , COLL_NAME , COLL_NAME_ALIAS );
159160 System .out .println ("\t res: " + affectRes .toString ());
160161
161162
162163 // 6. describe collection
163164 System .out .println ("---------------------- describeCollection ----------------------" );
164- Collection descCollRes = db .describeCollection (COLL_NAME );
165+ Collection descCollRes = client .describeCollection (DBNAME , COLL_NAME );
165166 System .out .println ("\t res: " + descCollRes .toString ());
166167
167168 // 7. delete alias
168169 System .out .println ("---------------------- deleteAlias ----------------------" );
169- AffectRes affectRes1 = db .deleteAlias (COLL_NAME_ALIAS );
170+ AffectRes affectRes1 = client .deleteAlias (DBNAME , COLL_NAME_ALIAS );
170171 System .out .println ("\t res: " + affectRes1 );
171172
172173 // 8. describe collection
173174 System .out .println ("---------------------- describeCollection ----------------------" );
174- Collection descCollRes1 = db .describeCollection (COLL_NAME );
175+ Collection descCollRes1 = client .describeCollection (DBNAME , COLL_NAME );
175176 System .out .println ("\t res: " + descCollRes1 .toString ());
176177
177178 }
178179
179180
180181 private static void upsertData (VectorDBClient client ) throws InterruptedException {
181182 Database database = client .database (DBNAME );
182- Collection collection = database .describeCollection (COLL_NAME );
183+ Collection collection = client .describeCollection (DBNAME , COLL_NAME );
183184// List<JSONObject> documentList = Arrays.asList(
184185// new JSONObject("{\"id\":\"0013\",\"vector\":[0.2123, 0.21, 0.213],\"bookName\":\"三国演义\",\"author\":\"吴承恩\",\"page\":21,\"segment\":\"富贵功名,前缘分定,为人切莫欺心。\"}"),
185186// new JSONObject("{\"id\":\"0014\",\"vector\":[0.2123, 0.21, 0.213],\"bookName\":\"三国演义\",\"author\":\"吴承恩\",\"page\":21,\"segment\":\"富贵功名,前缘分定,为人切莫欺心。\"}")
@@ -249,7 +250,7 @@ private static void upsertData(VectorDBClient client) throws InterruptedExceptio
249250// documentList 是JSONObject列表或者document列表
250251// InsertParam insertParam = InsertParam.newBuilder().withDocumentsData(documentData).build();
251252
252- collection .upsert (insertParam );
253+ client .upsert (DBNAME , COLL_NAME , insertParam );
253254// 可以直接使用client进行操作
254255 AffectRes affectRes = client .upsert (DBNAME ,COLL_NAME , insertParam );
255256 System .out .println (JsonUtils .toJsonString (affectRes ));
@@ -264,7 +265,7 @@ private static void upsertData(VectorDBClient client) throws InterruptedExceptio
264265
265266 private static void queryData (VectorDBClient client ) {
266267 Database database = client .database (DBNAME );
267- Collection collection = database .describeCollection (COLL_NAME );
268+ Collection collection = client .describeCollection (DBNAME , COLL_NAME );
268269
269270 System .out .println ("---------------------- query ----------------------" );
270271 List <String > documentIds = Arrays .asList ("0001" , "0002" , "0003" , "0004" , "0005" );
@@ -285,7 +286,7 @@ private static void queryData(VectorDBClient client) {
285286 .withRetrieveVector (false )
286287 .withSort (OrderRule .newBuilder ().withFieldName ("page" ).withDirection (OrderEnum .DESC ).build ())
287288 .build ();
288- List <Document > qdos = collection .query (queryParam );
289+ List <Document > qdos = client .query (DBNAME , COLL_NAME , queryParam );
289290 for (Document doc : qdos ) {
290291 System .out .println ("\t res: " + doc .toString ());
291292 }
@@ -345,7 +346,7 @@ private static void queryData(VectorDBClient client) {
345346
346347 private static void updateAndDelete (VectorDBClient client ) throws InterruptedException {
347348 Database database = client .database (DBNAME );
348- Collection collection = database .describeCollection (COLL_NAME );
349+ Collection collection = client .describeCollection (DBNAME , COLL_NAME );
349350
350351 System .out .println ("---------------------- update ----------------------" );
351352 // update
@@ -395,7 +396,7 @@ private static void updateAndDelete(VectorDBClient client) throws InterruptedExc
395396 .withDropBeforeRebuild (false )
396397 .withThrottle (1 )
397398 .build ();
398- collection .rebuildIndex (rebuildIndexParam );
399+ client .rebuildIndex (DBNAME , COLL_NAME , rebuildIndexParam );
399400
400401 Thread .sleep (1000 * 5 );
401402
@@ -410,15 +411,15 @@ private static void updateAndDelete(VectorDBClient client) throws InterruptedExc
410411 // 是否返回 vector 数据
411412 .withRetrieveVector (false )
412413 .build ();
413- List <Document > qdos = collection .query (queryParam );
414+ List <Document > qdos = client .query (DBNAME , COLL_NAME , queryParam );
414415 for (Document doc : qdos ) {
415416 System .out .println ("\t res: " + doc .toString ());
416417 }
417418
418419
419420 // truncate 会清除整个 Collection 的数据,包括索引
420421 System .out .println ("---------------------- truncate collection ----------------------" );
421- AffectRes affectRes1 = database .truncateCollections (COLL_NAME );
422+ AffectRes affectRes1 = client .truncateCollections (DBNAME , COLL_NAME );
422423 System .out .println ("\t res: " + JsonUtils .toJsonString (affectRes1 ));
423424
424425 // notice:delete操作可用会有延迟
@@ -430,7 +431,7 @@ private static void deleteAndDrop(VectorDBClient client) {
430431
431432 // 删除 collection
432433 System .out .println ("---------------------- truncate collection ----------------------" );
433- database .dropCollection (COLL_NAME );
434+ client .dropCollection (DBNAME , COLL_NAME );
434435
435436 // 删除 database
436437 System .out .println ("---------------------- truncate collection ----------------------" );
0 commit comments