Skip to content

Commit

Permalink
2.0.6
Browse files Browse the repository at this point in the history
  • Loading branch information
anyihao committed Oct 25, 2024
1 parent db2353c commit 1ad9ac8
Show file tree
Hide file tree
Showing 22 changed files with 388 additions and 39 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.4</version>
<version>2.0.6</version>
</dependency>
```

- Gradle/Grails

```gradle
compile 'com.tencent.tcvectordb:vectordatabase-sdk-java:2.0.4'
compile 'com.tencent.tcvectordb:vectordatabase-sdk-java:2.0.6'
```

### 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.4</version>
<version>2.0.6</version>
</dependency>
```

- Gradle/Grails

```gradle
compile 'com.tencent.tcvectordb:vectordatabase-sdk-java:2.0.4'
compile 'com.tencent.tcvectordb:vectordatabase-sdk-java:2.0.6'
```

### 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.4</version>
<version>2.0.6</version>
<packaging>jar</packaging>

<name>vectordatabase-sdk-java</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ public VectorDBClient(ConnectParam connectParam, ReadConsistencyEnum readConsist
protected VectorDBClient() {
}

public void close() {
if (stub != null) {
stub.close();
}
}

/**
* create database
* @param databaseName database's name to create. The name of the database. A database name can only include
Expand Down Expand Up @@ -88,11 +94,13 @@ public Database createDatabaseIfNotExists(String databaseName) throws VectorDBEx
}

/**
* this method is deprecated, recommend use {@link VectorDBClient#IsExistsDatabase(String)}
* check database exists, return true if existed else false
* @param databaseName database's name
* @return Boolean
* @throws VectorDBException
*/
@Deprecated
public Boolean existsDatabase(String databaseName) throws VectorDBException {
List<String> databaseNames = stub.listDatabases();
if(databaseNames!=null && databaseNames.contains(databaseName)){
Expand All @@ -101,6 +109,20 @@ public Boolean existsDatabase(String databaseName) throws VectorDBException {
return false;
}

/**
* check database exists, return true if existed else false
* @param databaseName database's name
* @return Boolean
* @throws VectorDBException
*/
public Boolean IsExistsDatabase(String databaseName) throws VectorDBException {
List<String> databaseNames = stub.listDatabases();
if(databaseNames!=null && databaseNames.contains(databaseName)){
return true;
}
return false;
}

/**
* drop database
* @param databaseName: database's name to drop
Expand Down Expand Up @@ -169,12 +191,14 @@ public AIDatabase aiDatabase(String databaseName){


/**
* this method is deprecated, recommend use {@link VectorDBClient#IsExistsCollection(String, String)}
* exists collection, true if collection exists else false
* @param databaseName
* @param collection
* @return boolean
* @throws VectorDBException
*/
@Deprecated
public Boolean existsCollection(String databaseName, String collection) throws VectorDBException {
Collection collectionInfo = null;
try {
Expand All @@ -183,6 +207,21 @@ public Boolean existsCollection(String databaseName, String collection) throws V
return collectionInfo!=null;
}

/**
* exists collection, true if collection exists else false
* @param databaseName
* @param collection
* @return boolean
* @throws VectorDBException
*/
public Boolean IsExistsCollection(String databaseName, String collection) throws VectorDBException {
Collection collectionInfo = null;
try {
collectionInfo = stub.describeCollection(databaseName, collection);
}catch (Exception e){}
return collectionInfo!=null;
}

/**
* create collection if not existed
* @param databaseName
Expand All @@ -208,9 +247,23 @@ public Collection createCollectionIfNotExists(String databaseName, CreateCollect
* upsert document
* @param database: database name
* @param collection: collection name
* @param param: insert param
*
* @return
* @param param InsertParam: upsert data. buildIndex is whether to build index, default is true, documents
* is a list of JSONObject or Document.
* eg: Arrays.asList(
* new JSONObject("{\"id\":\"0013\",\"vector\":[0.2123, 0.21, 0.213],\"bookName\":\"三国演义\",\"author\":\"吴承恩\",\"page\":21,\"segment\":\"富贵功名,前缘分定,为人切莫欺心。\"}"),
* new JSONObject("{\"id\":\"0014\",\"vector\":[0.2123, 0.21, 0.213],\"bookName\":\"三国演义\",\"author\":\"吴承恩\",\"page\":21,\"segment\":\"富贵功名,前缘分定,为人切莫欺心。\"}")
* ); or
* Arrays.asList(Document.newBuilder()
* .withId("0001")
* .withVector(generateRandomVector(768))
* .withSparseVector(sparseVectors.get(0))
* .addDocField(new DocField("bookName", "三国演义"))
* .addDocField(new DocField("author", "罗贯中"))
* .addDocField(new DocField("page", 21))
* .addDocField(new DocField("segment", "富贵功名,前缘分定,为人切莫欺心。"))
* .addDocField(new DocField("text", "富贵功名,前缘分定,为人切莫欺心。"))
* .build());
* @return AffectRes.class
* @throws VectorDBException
*/
public AffectRes upsert(String database, String collection, InsertParam param) throws VectorDBException {
Expand All @@ -236,8 +289,14 @@ public AffectRes upsert(String database, String collection, InsertParam param) t
* query document
* @param database
* @param collection
* @param param
* @return
* @param param QueryParam:
* limit(int): Limit return row's count
* offset(int): Skip offset rows of query result set
* retrieve_vector(bool): Whether to return vector values.
* filter(Filter): filter rows before return result
* document_ids(List): filter rows by id list
* output_fields(List): return columns by column name list
* @return List<Document>
* @throws VectorDBException
*/
public List<Document> query(String database, String collection, QueryParam param) throws VectorDBException {
Expand All @@ -249,8 +308,15 @@ public List<Document> query(String database, String collection, QueryParam param
* search document
* @param database
* @param collection
* @param param
* @return
* @param param SearchByVectorParam:
* vectors: List<List<Double>>, search documents by the vectors
* limit(int): Limit return row's count
* retrieve_vector(bool): Whether to return vector values.
* filter(Filter): filter rows before return result
* output_fields(List): return columns by column name list
* radius(Float): radius of search
* params(Params): params for search, eg:HNSWSearchParams, GeneralParams
* @return List<List<Document>>: the size of the result is the same as the size of vectors
* @throws VectorDBException
*/
public List<List<Document>> search(String database, String collection, SearchByVectorParam param) throws VectorDBException {
Expand All @@ -262,8 +328,15 @@ public List<List<Document>> search(String database, String collection, SearchByV
* search document by ID
* @param database
* @param collection
* @param param
* @return
* @param param SearchByVectorParam:
* documentIds: List<String>, search documents by the document ids
* limit(int): Limit return row's count
* retrieve_vector(bool): Whether to return vector values.
* filter(Filter): filter rows before return result
* output_fields(List): return columns by column name list
* radius(Float): radius of search
* params(Params): params for search, eg:HNSWSearchParams, GeneralParams
* @return List<List<Document>>: the size of the result is the same as the size of documentIds
* @throws VectorDBException
*/
public List<List<Document>> searchById(String database, String collection, SearchByIdParam param) throws VectorDBException {
Expand All @@ -273,11 +346,18 @@ public List<List<Document>> searchById(String database, String collection, Searc


/**
* search document by embedding items
* search document by contents that would be embedded to vectors from the collection
* @param database
* @param collection
* @param param
* @return
* @param param SearchByVectorParam:
* embeddingItems: List<String>, search documents by the content
* limit(int): Limit return row's count
* retrieve_vector(bool): Whether to return vector values.
* filter(Filter): filter rows before return result
* output_fields(List): return columns by column name list
* radius(Float): radius of search
* params(Params): params for search, eg:HNSWSearchParams, GeneralParams
* @return List<List<Document>>: the size of the result is the same as the size of embeddingItems
* @throws VectorDBException
*/
public SearchRes searchByEmbeddingItems(String database, String collection, SearchByEmbeddingItemsParam param) throws VectorDBException {
Expand All @@ -289,8 +369,8 @@ public SearchRes searchByEmbeddingItems(String database, String collection, Sear
* delete document
* @param database
* @param collection
* @param param
* @return
* @param param DeleteParam: delete document that retrieved by filter and documentIds
* @return AffectRes
* @throws VectorDBException
*/
public AffectRes delete(String database, String collection, DeleteParam param) throws VectorDBException {
Expand All @@ -302,9 +382,9 @@ public AffectRes delete(String database, String collection, DeleteParam param) t
* update document use document object
* @param database
* @param collection
* @param param
* @param document
* @return
* @param param: update param used for retrieving document
* @param document(Document.class): the document to be updated
* @return AffectRes
* @throws VectorDBException
*/
public AffectRes update(String database, String collection, UpdateParam param, Document document) throws VectorDBException {
Expand All @@ -320,9 +400,9 @@ public AffectRes update(String database, String collection, UpdateParam param, D
* update document use json object
* @param database
* @param collection
* @param param
* @param document
* @return
* @param param: update param used for retrieving document
* @param document(JSONObject.class): the document to be updated
* @return AffectRes
* @throws VectorDBException
*/
public AffectRes update(String database, String collection, UpdateParam param, JSONObject document) throws VectorDBException {
Expand All @@ -338,8 +418,16 @@ public AffectRes update(String database, String collection, UpdateParam param, J
* sparse vector and vector hybrid search
* @param database
* @param collection
* @param param: HybridSearchParam
* @return
* @param param HybridSearchParam:
* ann(List<AnnOption>): ann options, annOption used for vector search,
* match(List<MatchOption>): match options, matchOption used for sparse vector search
* retrieve_vector(bool): Whether to return vector and sparse vector values.
* filter(Filter): filter rows before return result
* document_ids(List): filter rows by id list
* output_fields(List): return columns by column name list
* Limit(int): limit the number of rows returned
* rerank(RerankParam): rerank param, RRFRerankParam or WeightRerankParam
* @return HybridSearchRes: the size of the result is the same as the size of embeddingItems
* @throws VectorDBException
*/
public HybridSearchRes hybridSearch(String database, String collection, HybridSearchParam param) throws VectorDBException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ private static void createDatabaseAndCollection(VectorDBClient client) {
Database db = client.createDatabase(DBNAME);
// 可以使用这种方式创建db
// Database db = client.createDatabaseIfNotExists(DBNAME);
Boolean isExisted = client.IsExistsDatabase("test_db");

// 2. 列出所有数据库
System.out.println("---------------------- listCollections ----------------------");
Expand All @@ -80,7 +81,7 @@ private static void createDatabaseAndCollection(VectorDBClient client) {
// 可以使用下面方式创建collection
// db.createCollectionIfNotExists(collectionParam);

System.out.println(COLL_NAME + " exists: "+ db.existsCollection(COLL_NAME));
System.out.println(COLL_NAME + " exists: "+ db.IsExistsCollection(COLL_NAME));

// 4. 列出所有 collection
// Database db = client.database(DBNAME);
Expand Down Expand Up @@ -200,11 +201,11 @@ private static void queryData(VectorDBClient client) {
// 使用 filter 过滤数据
.withFilter(filterParam)
// limit 限制返回行数,1 到 16384 之间
.withLimit(3)
.withLimit(5)
// 偏移
.withOffset(1)
.withOffset(0)
// 指定返回的 fields
.withOutputFields(outputFields)
// .withOutputFields(outputFields)
// 是否返回 vector 数据
.withRetrieveVector(false)
.build();
Expand Down
Loading

0 comments on commit 1ad9ac8

Please sign in to comment.