Skip to content

Commit 2189d20

Browse files
author
averiewang
committed
doc: add comments
1 parent e7ba60d commit 2189d20

File tree

8 files changed

+126
-23
lines changed

8 files changed

+126
-23
lines changed

example/collection_upload_file_demo/main.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ import (
1616
)
1717

1818
type Demo struct {
19-
client *tcvectordb.Client
19+
client *tcvectordb.RpcClient
2020
}
2121

2222
func NewDemo(url, username, key string) (*Demo, error) {
23-
cli, err := tcvectordb.NewClient(url, username, key, &tcvectordb.ClientOption{
23+
cli, err := tcvectordb.NewRpcClient(url, username, key, &tcvectordb.ClientOption{
2424
ReadConsistency: tcvectordb.StrongConsistency})
2525
if err != nil {
2626
return nil, err
@@ -275,23 +275,22 @@ func printErr(err error) {
275275
}
276276

277277
func main() {
278-
database := "test-db"
279-
collectionName := "test-coll"
278+
database := "go-sdk-demo-db"
279+
collectionName := "go-sdk-demo-col-test"
280280

281281
_, filePath, _, _ := runtime.Caller(0)
282-
localFilePath := path.Join(path.Dir(filePath), "../demo_files/tcvdb.md")
282+
localFilePath := path.Join(path.Dir(filePath), "../demo_files/tcvdb.pdf")
283283
filename := filepath.Base(localFilePath)
284284

285285
ctx := context.Background()
286286
testVdb, err := NewDemo("vdb http url or ip and port", "vdb username", "key get from web console")
287287
printErr(err)
288-
err = testVdb.DeleteAndDrop(ctx, database, collectionName)
289-
printErr(err)
290288
err = testVdb.CreateDBAndCollection(ctx, database, collectionName)
291289
printErr(err)
292290
err = testVdb.UploadFile(ctx, database, collectionName, localFilePath)
293291
printErr(err)
294292
err = testVdb.QueryData(ctx, database, collectionName, filename)
295293
printErr(err)
296-
294+
err = testVdb.DeleteAndDrop(ctx, database, collectionName)
295+
printErr(err)
297296
}

example/modify_vector_index/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ func (d *Demo) ModifyVectorIndex(ctx context.Context, database, collection strin
231231
param.VectorIndexes = make([]tcvectordb.ModifyVectorIndex, 0)
232232
param.VectorIndexes = append(param.VectorIndexes, tcvectordb.ModifyVectorIndex{
233233
FieldName: "vector",
234+
FieldType: "bfloat16_vector",
234235
MetricType: tcvectordb.COSINE,
235236
Params: &tcvectordb.HNSWParam{
236237
M: 8,

tcvectordb/ai_collection_view.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,11 +158,11 @@ func (i *implementerCollectionView) CreateCollectionView(ctx context.Context, na
158158
req.Description = param.Description
159159

160160
for _, v := range param.Indexes.FilterIndex {
161-
var column api.IndexColumn
161+
column := new(api.IndexColumn)
162162
column.FieldName = v.FieldName
163163
column.FieldType = string(v.FieldType)
164164
column.IndexType = string(v.IndexType)
165-
req.Indexes = append(req.Indexes, &column)
165+
req.Indexes = append(req.Indexes, column)
166166
}
167167

168168
if param.Embedding != nil {

tcvectordb/base_collection.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -174,38 +174,38 @@ func (i *implementerCollection) CreateCollection(ctx context.Context, name strin
174174
req.Description = description
175175

176176
for _, v := range indexes.VectorIndex {
177-
var column api.IndexColumn
177+
column := new(api.IndexColumn)
178178
column.FieldName = v.FieldName
179179
column.FieldType = string(v.FieldType)
180180
column.IndexType = string(v.IndexType)
181181
column.MetricType = string(v.MetricType)
182182
column.Dimension = v.Dimension
183183

184-
optionParams(&column, v)
184+
optionParams(column, v)
185185

186-
req.Indexes = append(req.Indexes, &column)
186+
req.Indexes = append(req.Indexes, column)
187187
}
188188

189189
for _, v := range indexes.SparseVectorIndex {
190-
var column api.IndexColumn
190+
column := new(api.IndexColumn)
191191
column.FieldName = v.FieldName
192192
column.FieldType = string(v.FieldType)
193193
column.IndexType = string(v.IndexType)
194194
column.MetricType = string(v.MetricType)
195195

196-
req.Indexes = append(req.Indexes, &column)
196+
req.Indexes = append(req.Indexes, column)
197197
}
198198

199199
for _, v := range indexes.FilterIndex {
200-
var column api.IndexColumn
200+
column := new(api.IndexColumn)
201201
column.FieldName = v.FieldName
202202
column.FieldType = string(v.FieldType)
203203
if v.FieldType == Array {
204204
column.FieldElementType = string(v.ElemType)
205205
}
206206
column.IndexType = string(v.IndexType)
207207
column.AutoId = v.AutoId
208-
req.Indexes = append(req.Indexes, &column)
208+
req.Indexes = append(req.Indexes, column)
209209
}
210210
if len(params) != 0 && params[0] != nil {
211211
param := params[0]
@@ -462,7 +462,7 @@ func (i *implementerCollection) toCollection(collectionItem *collection.Describe
462462
continue
463463
}
464464
switch index.FieldType {
465-
case string(Vector):
465+
case string(Vector), string(BinaryVector), string(BFloat16Vector), string(Float16Vector):
466466
vector := VectorIndex{}
467467
vector.FieldName = index.FieldName
468468
vector.FieldType = FieldType(index.FieldType)

tcvectordb/base_flat.go

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,15 @@ type FlatInterface interface {
9393
// [ChangePassword] changes the password for the specific user.
9494
ChangePassword(ctx context.Context, param ChangePasswordParams) error
9595

96-
UploadFile(ctx context.Context, databaseName, collectionName string, param UploadFileParams) (result *UploadFileResult, err error)
96+
// [UploadFile] uploads a file to the collection.
97+
UploadFile(ctx context.Context, databaseName, collectionName string,
98+
param UploadFileParams) (result *UploadFileResult, err error)
9799

100+
// [GetImageUrl] retrieves image URLs for the specified file and documents in the collection.
98101
GetImageUrl(ctx context.Context, databaseName, collectionName string,
99102
param GetImageUrlParams) (result *GetImageUrlResult, err error)
100103

104+
// [QueryFileDetails] queries file details from the collection.
101105
QueryFileDetails(ctx context.Context, databaseName, collectionName string,
102106
param *QueryFileDetailsParams) (result *QueryFileDetailsResult, err error)
103107
}
@@ -528,15 +532,35 @@ func uploadFile(ctx context.Context, cli SdkClient, databaseName, collectionName
528532
return result, nil
529533
}
530534

535+
// [GetImageUrlParams] holds the parameters for getting image URLs.
536+
//
537+
// Fields:
538+
// - FileName: The name of the file to get image URLs for.
539+
// - DocumentIds: The list of document IDs to get image URLs for.
531540
type GetImageUrlParams struct {
532541
FileName string
533542
DocumentIds []string
534543
}
535544

545+
// [GetImageUrlResult] holds the results for getting image URLs.
546+
//
547+
// Fields:
548+
// - Images: A two-dimensional array of image information, where each inner array contains image details for a document.
536549
type GetImageUrlResult struct {
537550
Images [][]document.ImageInfo
538551
}
539552

553+
// [GetImageUrl] retrieves image URLs for the specified file and documents in the collection.
554+
//
555+
// Parameters:
556+
// - ctx: A context.Context object controls the request's lifetime, allowing for the request
557+
// to be canceled or to timeout according to the context's deadline.
558+
// - databaseName: The name of the database.
559+
// - collectionName: The name of the collection.
560+
// - param: A [GetImageUrlParams] object that includes the other parameters for getting image URLs operation.
561+
// See [GetImageUrlParams] for more information.
562+
//
563+
// Returns a pointer to a [GetImageUrlResult] object or an error.
540564
func (i *implementerFlatDocument) GetImageUrl(ctx context.Context, databaseName, collectionName string,
541565
param GetImageUrlParams) (result *GetImageUrlResult, err error) {
542566
return getImageUrl(ctx, i.SdkClient, databaseName, collectionName, param)
@@ -561,6 +585,14 @@ func getImageUrl(ctx context.Context, cli SdkClient, databaseName, collectionNam
561585
return result, nil
562586
}
563587

588+
// [QueryFileDetailsParams] holds the parameters for querying file details.
589+
//
590+
// Fields:
591+
// - FileNames: The list of file names to query details for.
592+
// - Filter: A pointer to a Filter object for filtering the query results.
593+
// - Limit: A pointer to the maximum number of results to return. If nil, default limit is 10.
594+
// - Offset: The pagination offset to control the starting position of results returned by the paginated query.
595+
// - OutputFields: The list of fields to include in the output results.
564596
type QueryFileDetailsParams struct {
565597
FileNames []string
566598
Filter *Filter
@@ -569,11 +601,27 @@ type QueryFileDetailsParams struct {
569601
OutputFields []string
570602
}
571603

604+
// [QueryFileDetailsResult] holds the results for querying file details.
605+
//
606+
// Fields:
607+
// - Documents: The list of documents that match the query conditions.
608+
// - Count: The total number of documents that match the query conditions.
572609
type QueryFileDetailsResult struct {
573610
Documents []Document
574611
Count uint64
575612
}
576613

614+
// [QueryFileDetails] queries file details based on the specified query conditions from the collection.
615+
//
616+
// Parameters:
617+
// - ctx: A context.Context object controls the request's lifetime, allowing for the request
618+
// to be canceled or to timeout according to the context's deadline.
619+
// - databaseName: The name of the database.
620+
// - collectionName: The name of the collection.
621+
// - param: A pointer to a [QueryFileDetailsParams] object that includes the other parameters for querying file details operation.
622+
// See [QueryFileDetailsParams] for more information.
623+
//
624+
// Returns a pointer to a [QueryFileDetailsResult] object or an error.
577625
func (i *implementerFlatDocument) QueryFileDetails(ctx context.Context, databaseName, collectionName string,
578626
param *QueryFileDetailsParams) (result *QueryFileDetailsResult, err error) {
579627
return queryFileDetails(ctx, i.SdkClient, databaseName, collectionName, param)

tcvectordb/base_index_flat.go

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,23 @@ type AddIndexParams struct {
5757
BuildExistedData *bool
5858
}
5959

60+
// [ModifyVectorIndexParam] holds the parameters for modifying vector indexes in a collection.
61+
//
62+
// Fields:
63+
// - VectorIndexes: The list of vector indexes to be modified.
64+
// - RebuildRules: A pointer to [RebuildRules] object that specifies the rules for rebuilding indexes.
6065
type ModifyVectorIndexParam struct {
6166
VectorIndexes []ModifyVectorIndex
6267
RebuildRules *index.RebuildRules
6368
}
6469

70+
// [ModifyVectorIndex] represents a vector index configuration for modification.
71+
//
72+
// Fields:
73+
// - FieldName: The name of the field for the vector index.
74+
// - FieldType: The type of the field (e.g., "vector", "float16_vector", "bfloat16_vector").
75+
// - MetricType: The metric type used for similarity calculation (e.g., COSINE, L2).
76+
// - Params: The index parameters that specify the configuration details for the index.
6577
type ModifyVectorIndex struct {
6678
FieldName string
6779
FieldType string
@@ -158,20 +170,30 @@ func (i *implementerFlatIndex) DropIndex(ctx context.Context, databaseName, coll
158170
}
159171

160172
// [ModifyVectorIndex] modifies vector indexes to an existing collection.
173+
//
174+
// Parameters:
175+
// - ctx: A context.Context object controls the request's lifetime, allowing for the request
176+
// to be canceled or to timeout according to the context's deadline.
177+
// - databaseName: The name of the database.
178+
// - collectionName: The name of the collection.
179+
// - param: A [ModifyVectorIndexParam] object that includes the parameters for modifying vector indexes operation.
180+
// See [ModifyVectorIndexParam] for more information.
181+
//
182+
// Returns an error if the modification fails.
161183
func (i *implementerFlatIndex) ModifyVectorIndex(ctx context.Context, databaseName, collectionName string, param ModifyVectorIndexParam) error {
162184
req := new(index.ModifyVectorIndexReq)
163185
req.Database = databaseName
164186
req.Collection = collectionName
165187

166188
for _, v := range param.VectorIndexes {
167-
var column api.IndexColumn
189+
column := new(api.IndexColumn)
168190
column.FieldName = v.FieldName
169191
column.FieldType = v.FieldType
170192
column.MetricType = string(v.MetricType)
171193

172-
optionParamsFromIndexParams(&column, v.Params)
194+
optionParamsFromIndexParams(column, v.Params)
173195

174-
req.VectorIndexes = append(req.VectorIndexes, &column)
196+
req.VectorIndexes = append(req.VectorIndexes, column)
175197
}
176198
req.RebuildRules = param.RebuildRules
177199

tcvectordb/rpc_base_collection.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ func (r *rpcImplementerCollection) toCollection(collectionItem *olama.CreateColl
386386
continue
387387
}
388388
switch index.FieldType {
389-
case string(Vector), string(BinaryVector):
389+
case string(Vector), string(BinaryVector), string(BFloat16Vector), string(Float16Vector):
390390
vector := VectorIndex{}
391391
vector.FieldName = index.FieldName
392392
vector.FieldType = FieldType(index.FieldType)

tcvectordb/rpc_base_document.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -966,14 +966,47 @@ func (r *rpcImplementerFlatDocument) Count(ctx context.Context, databaseName, co
966966
return &CountDocumentResult{Count: res.Count}, nil
967967
}
968968

969+
// [UploadFile] uploads a file to the collection.
970+
//
971+
// Parameters:
972+
// - ctx: A context.Context object controls the request's lifetime, allowing for the request
973+
// to be canceled or to timeout according to the context's deadline.
974+
// - databaseName: The name of the database.
975+
// - collectionName: The name of the collection.
976+
// - param: A [UploadFileParams] object that includes the other parameters for uploading file operation.
977+
// See [UploadFileParams] for more information.
978+
//
979+
// Returns a pointer to a [UploadFileResult] object or an error.
969980
func (r *rpcImplementerFlatDocument) UploadFile(ctx context.Context, databaseName, collectionName string, param UploadFileParams) (result *UploadFileResult, err error) {
970981
return uploadFile(ctx, r.SdkClient, databaseName, collectionName, param)
971982
}
972983

984+
// [GetImageUrl] retrieves image URLs for the specified file and documents in the collection.
985+
//
986+
// Parameters:
987+
// - ctx: A context.Context object controls the request's lifetime, allowing for the request
988+
// to be canceled or to timeout according to the context's deadline.
989+
// - databaseName: The name of the database.
990+
// - collectionName: The name of the collection.
991+
// - param: A [GetImageUrlParams] object that includes the other parameters for getting image URLs operation.
992+
// See [GetImageUrlParams] for more information.
993+
//
994+
// Returns a pointer to a [GetImageUrlResult] object or an error.
973995
func (r *rpcImplementerFlatDocument) GetImageUrl(ctx context.Context, databaseName, collectionName string, param GetImageUrlParams) (result *GetImageUrlResult, err error) {
974996
return getImageUrl(ctx, r.SdkClient, databaseName, collectionName, param)
975997
}
976998

999+
// [QueryFileDetails] queries file details based on the specified query conditions from the collection.
1000+
//
1001+
// Parameters:
1002+
// - ctx: A context.Context object controls the request's lifetime, allowing for the request
1003+
// to be canceled or to timeout according to the context's deadline.
1004+
// - databaseName: The name of the database.
1005+
// - collectionName: The name of the collection.
1006+
// - param: A pointer to a [QueryFileDetailsParams] object that includes the other parameters for querying file details operation.
1007+
// See [QueryFileDetailsParams] for more information.
1008+
//
1009+
// Returns a pointer to a [QueryFileDetailsResult] object or an error.
9771010
func (r *rpcImplementerFlatDocument) QueryFileDetails(ctx context.Context, databaseName, collectionName string,
9781011
param *QueryFileDetailsParams) (result *QueryFileDetailsResult, err error) {
9791012
return queryFileDetails(ctx, r.SdkClient, databaseName, collectionName, param)

0 commit comments

Comments
 (0)