Skip to content

Commit 51f702a

Browse files
committed
2.5.0
1 parent 7fd4486 commit 51f702a

41 files changed

Lines changed: 1818 additions & 451 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ You can use **Apache Maven** or **Gradle**/**Grails** to download the SDK.
2424
<dependency>
2525
<groupId>com.tencent.tcvectordb</groupId>
2626
<artifactId>vectordatabase-sdk-java</artifactId>
27-
<version>2.4.6</version>
27+
<version>2.5.0</version>
2828
</dependency>
2929
```
3030

3131
- Gradle/Grails
3232

3333
```gradle
34-
compile 'com.tencent.tcvectordb:vectordatabase-sdk-java:2.4.6'
34+
compile 'com.tencent.tcvectordb:vectordatabase-sdk-java:2.5.0'
3535
```
3636

3737
### Examples

tcvectordb/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ You can use **Apache Maven** or **Gradle**/**Grails** to download the SDK.
2424
<dependency>
2525
<groupId>com.tencent.tcvectordb</groupId>
2626
<artifactId>vectordatabase-sdk-java</artifactId>
27-
<version>2.4.6</version>
27+
<version>2.5.0</version>
2828
</dependency>
2929
```
3030

3131
- Gradle/Grails
3232

3333
```gradle
34-
compile 'com.tencent.tcvectordb:vectordatabase-sdk-java:2.4.6'
34+
compile 'com.tencent.tcvectordb:vectordatabase-sdk-java:2.5.0'
3535
```
3636

3737
### Examples

tcvectordb/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<groupId>com.tencent.tcvectordb</groupId>
66
<artifactId>vectordatabase-sdk-java</artifactId>
7-
<version>2.4.6</version>
7+
<version>2.5.0</version>
88
<packaging>jar</packaging>
99

1010
<name>vectordatabase-sdk-java</name>

tcvectordb/src/main/java/com/tencent/tcvectordb/client/VectorDBClient.java

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,28 @@ public Boolean IsExistsCollection(String databaseName, String collection) throws
223223
return collectionInfo!=null;
224224
}
225225

226+
/***
227+
* create collection
228+
* @param param createCollectionParam: the parameters of the collection to be created
229+
* databaseName: the name of the database to be created
230+
* collection: the name of the collection to be created
231+
* replicaNum: the number of replicas
232+
* shardNum: the number of shards
233+
* description: the description of the collection
234+
* indexes: list of the index fields
235+
* embedding: Embedding class
236+
* ttlConfig: TTLConfig class
237+
*
238+
* @return collection object
239+
*/
240+
public Collection createCollection(String databaseName, CreateCollectionParam param) throws VectorDBException {
241+
param.setDatabase(databaseName);
242+
param.setReadConsistency(readConsistency);
243+
stub.createCollection(param);
244+
param.setStub(this.stub);
245+
return param;
246+
}
247+
226248
/**
227249
* create collection if not existed
228250
* @param databaseName
@@ -508,6 +530,28 @@ public HybridSearchRes hybridSearch(String database, String collection, HybridSe
508530
database, collection, param, this.readConsistency), ai);
509531
}
510532

533+
534+
/**
535+
* full text search
536+
* @param database
537+
* @param collection
538+
* @param param FullTextSearchParam:
539+
* match(MatchOption): matchOption used for sparse vector search
540+
* retrieve_vector(bool): Whether to sparse vector values.
541+
* filter(Filter): filter rows before return result
542+
* output_fields(List): return columns by column name list
543+
* Limit(int): limit the number of rows returned
544+
* @return FullTextSearchRes:
545+
* documents: List<Document>: the List of document
546+
*
547+
* @throws VectorDBException
548+
*/
549+
public FullTextSearchRes fullTextSearch(String database, String collection, FullTextSearchParam param) throws VectorDBException {
550+
boolean ai = false;
551+
return this.stub.fullTextSearch(new FullTextSearchParamInner(
552+
database, collection, param, this.readConsistency), ai);
553+
}
554+
511555
/**
512556
* this method is deprecated, recommend use {@link VectorDBClient#addIndex(String, String, AddIndexParam)}
513557
* Used to add a scalar field index to an existing collection
@@ -527,6 +571,7 @@ public BaseRes AddIndex(String database, String collection, AddIndexParam addInd
527571
/**
528572
* rebuild index
529573
* @param rebuildIndexParam: rebuild index param
574+
*
530575
* @return BaseRes
531576
*/
532577
public BaseRes rebuildIndex(String database, String collection, RebuildIndexParam rebuildIndexParam) {
@@ -767,4 +812,33 @@ public GetImageUrlRes GetImageUrl(String database, String collection, GetImageUr
767812
return this.stub.GetImageUrl(paramInner);
768813
}
769814

815+
816+
/**
817+
* query file details
818+
* @param database database name
819+
* @param collection collection name
820+
* @param param QueryFileDetailParam.class
821+
* fileNames (List<String>): query file names
822+
* filter (String): filter rows before return result
823+
* outputFields (List<String>): return columns by column name list
824+
* limit (int): Limit return row's count
825+
* offset (int): Skip offset rows of query result set
826+
*
827+
* @return QueryFileDetailRes.class
828+
* documents: List<FileDetail>:
829+
* id (String): file name
830+
* _indexed_status (string): indexed status, "Ready" or "Failure"
831+
* _text_length(Long): text length
832+
*
833+
*/
834+
public QueryFileDetailRes queryFileDetails(String database, String collection, QueryFileDetailParam param) {
835+
QueryFileDetailsParamInner paramInner = new QueryFileDetailsParamInner();
836+
paramInner.setDatabase(database);
837+
paramInner.setCollection(collection);
838+
paramInner.setQuery(param);
839+
paramInner.setReadConsistency(this.readConsistency);
840+
841+
return this.stub.queryFileDetails(paramInner);
842+
}
843+
770844
}

tcvectordb/src/main/java/com/tencent/tcvectordb/examples/VectorDBExample.java

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -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("\tres: " + 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("\tres: " + 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("\tres: " + 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("\tres: " + 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("\tres: " + 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("\tres: " + 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("\tres: " + 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 ----------------------");

tcvectordb/src/main/java/com/tencent/tcvectordb/examples/VectorDBExampleWithCollectionUploadFile.java

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import com.tencent.tcvectordb.model.param.collectionView.*;
2929
import com.tencent.tcvectordb.model.param.dml.*;
3030
import com.tencent.tcvectordb.model.param.entity.GetImageUrlRes;
31+
import com.tencent.tcvectordb.model.param.entity.QueryFileDetailRes;
3132
import com.tencent.tcvectordb.model.param.entity.SearchRes;
3233
import com.tencent.tcvectordb.model.param.enums.EmbeddingModelEnum;
3334
import com.tencent.tcvectordb.model.param.enums.OrderEnum;
@@ -71,9 +72,21 @@ public static void main(String[] args) throws Exception {
7172
//
7273
// // 解析加载文件需要等待时间
7374
Thread.sleep(1000 * 30);
74-
75+
queryFileDetails(client, "tcvdb.pdf");
7576
queryData(client);
7677
client.dropDatabase(DBNAME);
78+
client.close();
79+
}
80+
81+
private static void queryFileDetails(VectorDBClient client, String fileName) {
82+
System.out.println("---------------------- queryFileDetails ----------------------");
83+
QueryFileDetailParam param = QueryFileDetailParam.newBuilder()
84+
.withFileNames(Arrays.asList(fileName))
85+
// .withFilter("")
86+
.build();
87+
QueryFileDetailRes res = client.queryFileDetails(DBNAME, COLL_NAME, param);
88+
System.out.println(JsonUtils.toJsonString(res));
89+
7790
}
7891

7992
private static void createDatabaseAndCollection(VectorDBClient client) throws InterruptedException {
@@ -152,7 +165,7 @@ private static void queryData(VectorDBClient client) {
152165
// 是否返回 vector 数据
153166
.withRetrieveVector(false)
154167
.build();
155-
List<Document> qdos = collection.query(queryParam);
168+
List<Document> qdos = client.query(DBNAME, COLL_NAME, queryParam);
156169
for (Document doc : qdos) {
157170
System.out.println("\tres: " + doc.toString());
158171
}
@@ -221,11 +234,11 @@ private static void queryChunkBySectionNumAndChunkNum(VectorDBClient client) {
221234

222235
// 根据chunk_num 和 section_num 获取chunk文本
223236
System.out.println("---------------------- get chunk text by chunk_num ----------------------");
224-
Long chunkNum = (Long) searchRes.getDocuments().get(0).get(0).getObject("chunk_num");
225-
Long sectionNum = (Long) searchRes.getDocuments().get(0).get(0).getObject("section_num");
226-
if (chunkNum==null || sectionNum==null){
237+
if (searchRes.getDocuments().get(0).get(0).getObject("chunk_num")==null){
227238
return;
228239
}
240+
Long chunkNum = Long.valueOf(searchRes.getDocuments().get(0).get(0).getObject("chunk_num").toString());
241+
Long sectionNum = Long.valueOf(searchRes.getDocuments().get(0).get(0).getObject("section_num").toString());
229242
Long startChunkNum = chunkNum-2;
230243
if (startChunkNum < 0){
231244
startChunkNum = 0L;
@@ -273,7 +286,7 @@ private static CreateCollectionParam initCreateCollectionParam(String collName)
273286
return CreateCollectionParam.newBuilder()
274287
.withName(collName)
275288
.withShardNum(1)
276-
.withReplicaNum(0)
289+
.withReplicaNum(1)
277290
.withDescription("test collection0")
278291
.addField(new FilterIndex("id", FieldType.String, IndexType.PRIMARY_KEY))
279292
.addField(new VectorIndex("vector", 768, IndexType.HNSW,

0 commit comments

Comments
 (0)