Skip to content

Commit

Permalink
2.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
anyihao committed Dec 17, 2024
1 parent c119c83 commit 0924cff
Show file tree
Hide file tree
Showing 42 changed files with 9,618 additions and 960 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ You can use **Apache Maven** or **Gradle**/**Grails** to download the SDK.
<dependency>
<groupId>com.tencent.tcvectordb</groupId>
<artifactId>vectordatabase-sdk-java</artifactId>
<version>2.0.16</version>
<version>2.1.0</version>
</dependency>
```

- Gradle/Grails

```gradle
compile 'com.tencent.tcvectordb:vectordatabase-sdk-java:2.0.16'
compile 'com.tencent.tcvectordb:vectordatabase-sdk-java:2.1.0'
```

### Examples
Expand Down
4 changes: 2 additions & 2 deletions tcvectordb/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ You can use **Apache Maven** or **Gradle**/**Grails** to download the SDK.
<dependency>
<groupId>com.tencent.tcvectordb</groupId>
<artifactId>vectordatabase-sdk-java</artifactId>
<version>2.0.16</version>
<version>2.1.0</version>
</dependency>
```

- Gradle/Grails

```gradle
compile 'com.tencent.tcvectordb:vectordatabase-sdk-java:2.0.16'
compile 'com.tencent.tcvectordb:vectordatabase-sdk-java:2.1.0'
```

### Examples
Expand Down
2 changes: 1 addition & 1 deletion tcvectordb/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>com.tencent.tcvectordb</groupId>
<artifactId>vectordatabase-sdk-java</artifactId>
<version>2.0.16</version>
<version>2.1.0</version>
<packaging>jar</packaging>

<name>vectordatabase-sdk-java</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,7 @@ public HybridSearchRes hybridSearch(String database, String collection, HybridSe
}

/**
* this method is deprecated, recommend use {@link VectorDBClient#addIndex(String, String, AddIndexParam)}
* Used to add a scalar field index to an existing collection
* (the scalar field may contain historical data or a newly added empty field)
* @param database
Expand All @@ -451,9 +452,65 @@ public HybridSearchRes hybridSearch(String database, String collection, HybridSe
* @return
* @throws VectorDBException
*/
@Deprecated
public BaseRes AddIndex(String database, String collection, AddIndexParam addIndexParam) throws VectorDBException {
return this.stub.addIndex(
new AddIndexParamInner(database, collection, addIndexParam));
}


/**
* Used to add a scalar field index to an existing collection
* (the scalar field may contain historical data or a newly added empty field)
* @param database
* @param collection
* @param addIndexParam:
* @return
* @throws VectorDBException
*/
public BaseRes addIndex(String database, String collection, AddIndexParam addIndexParam) throws VectorDBException {
return this.stub.addIndex(
new AddIndexParamInner(database, collection, addIndexParam));
}


/**
* Used to query the number of documents that match the query, if countQueryParam is null,
* return all rows number of the collection
* @param database
* @param collection
* @param countQueryParam:
* @return
* @throws VectorDBException
*/
public BaseRes count(String database, String collection, CountQueryParam countQueryParam) throws VectorDBException {
return this.stub.countDocument(
new QueryCountParamInner(database, collection, countQueryParam, this.readConsistency), false);
}


/**
* Currently, this method is only for dense vectors, i.e. vector
* Supports re-specifying vector index parameters, HNSW supports re-specifying M and efConstruction, IVF supports re-specifying nlist (IVF_PQ supports re-specifying M and nlist)
* Supports re-specifying similarity calculation method
* The new configuration after the vector index is modified is defined by the field vectorIndexes
* After adjusting the parameters, this interface will trigger a rebuild, and the rebuild rules are specified by the field rebuildRules
* @param database The name of the database where the collection resides.
* @param collection The name of the collection
* @param modifyVectorIndexParam Adjust vector index parameters.
* vectorIndexes (List<VectorIndex></FilterIndex>): The vector fields to adjust
* rebuildRules: Specified rebuild rules.This interface will trigger a rebuild after adjusting
* the parameters:For example: {"drop_before_rebuild": True , "throttle": 1}
* drop_before_rebuild (bool): Whether to delete the old index before rebuilding the new index during
* index reconstruction. True: Delete the old index before rebuilding the index.
* throttle (int): Whether to limit the number of CPU cores for building the index on a single node.
* 0: No limit on CPU cores. 1: CPU core count is 1.
* @return
* @throws VectorDBException
*/
public BaseRes modifyVectorIndex(String database, String collection, ModifyVectorIndexParam modifyVectorIndexParam) throws VectorDBException {
return this.stub.modifyVectorIndex(
new ModifyIndexParamInner(database, collection, modifyVectorIndexParam), false);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public static void main(String[] args) throws InterruptedException {
upsertData(client);
queryData(client);
// addIndex(client);
modifyVectorIndex(client);
updateAndDelete(client);
deleteAndDrop(client);
testFilter();
Expand Down Expand Up @@ -234,6 +235,11 @@ private static void upsertData(VectorDBClient client) throws InterruptedExceptio
System.out.println(JsonUtils.toJsonString(affectRes));
// notice:upsert 操作可用会有延迟
Thread.sleep(1000 * 5);

BaseRes res = client.count(DBNAME,COLL_NAME, CountQueryParam.newBuilder()
.withFilter("bookName=\"三国演义\"")
.build());
System.out.println("count document: "+ res.getCount());
}

private static void queryData(VectorDBClient client) {
Expand All @@ -254,7 +260,7 @@ private static void queryData(VectorDBClient client) {
// 偏移
.withOffset(0)
// 指定返回的 fields
.addAllOutputFields("id", "bookName")
// .addAllOutputFields("id", "bookName")
// 是否返回 vector 数据
.withRetrieveVector(false)
.build();
Expand Down Expand Up @@ -330,7 +336,7 @@ private static void updateAndDelete(VectorDBClient client) throws InterruptedExc
UpdateParam updateParam = UpdateParam
.newBuilder()
.addAllDocumentId(documentIds)
// .withFilter("bookName=\"三国演义\"")
.withFilter("bookName=\"三国演义\"")
.build();
// JSONObject data = new JSONObject("{\"page\":100, \"extend\":\"extendContent_1\",\"array_test\":[\"extendContent\",\"extendContent1\"]}");
Document updateDoc = Document
Expand All @@ -353,7 +359,8 @@ private static void updateAndDelete(VectorDBClient client) throws InterruptedExc
DeleteParam build = DeleteParam
.newBuilder()
.addAllDocumentId("0001", "0003")
// .withFilter("bookName=\"西游记\"")
.withFilter("bookName=\"西游记\"")
.withLimit(1)
.build();
AffectRes deleteAffectRes = client.delete(DBNAME, COLL_NAME, build);
System.out.println(deleteAffectRes.toString());
Expand Down Expand Up @@ -479,5 +486,27 @@ public static void testFilter() {
.build().toString());
}

/**
* modifyVectorIndex test
* @param client
* @throws InterruptedException
*/
private static void modifyVectorIndex(VectorDBClient client) throws InterruptedException{
System.out.println("--------modify vector index-------");
Database db = client.database(DBNAME);
Collection collection = db.describeCollection(COLL_NAME);
System.out.println("before");
System.out.println(JsonUtils.toJsonString(collection));
BaseRes baseRes = client.modifyVectorIndex(DBNAME, COLL_NAME, ModifyVectorIndexParam.newBuilder()
.withVectorIndex(new VectorIndex(MetricType.IP, new HNSWParams(8, 100)))
.withRebuildRules(RebuildIndexParam.newBuilder().withDropBeforeRebuild(true).withThrottle(1).build())
.build());
System.out.println("modify res: "+ JsonUtils.toJsonString(baseRes));
Collection collectionAfter = db.describeCollection(COLL_NAME);
System.out.println("after");
System.out.println(JsonUtils.toJsonString(collectionAfter));

}


}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ public static void main(String[] args) throws Exception {
queryData(client);
updateAndDelete(client);
deleteAndDrop(client);
testFilter();
}

private static void createDatabaseAndCollection(VectorDBClient client) {
Expand Down Expand Up @@ -228,7 +227,6 @@ private static void queryData(VectorDBClient client) {
// search
// 1. search 提供按照 vector 搜索的能力
// 其他选项类似 search 接口

System.out.println("---------------------- search ----------------------");
queryParam = QueryParam.newBuilder()
.withDocumentIds(documentIds)
Expand All @@ -247,6 +245,7 @@ private static void queryData(VectorDBClient client) {
List<Double> vector = (List<Double>) document.getVector();
vectors.add(vector);
}
List<List<Double>> test = vectors;
SearchByVectorParam searchByVectorParam = SearchByVectorParam.newBuilder()
.withVectors(vectors)
// 若使用 HNSW 索引,则需要指定参数ef,ef越大,召回率越高,但也会影响检索速度
Expand Down Expand Up @@ -436,19 +435,4 @@ MetricType.COSINE, new HNSWParams(16, 200)))
.build();
}

/**
* 测试 Filter
*/
public static void testFilter() {
System.out.println("\tres: " + new Filter("author=\"jerry\"")
.and("a=1")
.or("r=\"or\"")
.orNot("rn=2")
.andNot("an=\"andNot\"")
.getCond());
System.out.println("\tres: " + Filter.in("key", Arrays.asList("v1", "v2", "v3")));
System.out.println("\tres: " + Filter.in("key", Arrays.asList(1, 2, 3)));
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ public static void main(String[] args) throws InterruptedException {
queryData(client);
updateAndDelete(client);
deleteAndDrop(client);
testFilter();
}


Expand Down Expand Up @@ -370,20 +369,5 @@ MetricType.IP, new HNSWParams(16, 200)))
.build();
}

/**
* 测试 Filter
*/
public static void testFilter() {
System.out.println("\tres: " + new Filter("author=\"jerry\"")
.and("a=1")
.or("r=\"or\"")
.orNot("rn=2")
.andNot("an=\"andNot\"")
.getCond());
System.out.println("\tres: " + Filter.in("key", Arrays.asList("v1", "v2", "v3")));
System.out.println("\tres: " + Filter.notIn("key", Arrays.asList(1, 2, 3)));
}


}

Loading

0 comments on commit 0924cff

Please sign in to comment.