Skip to content

Commit e7ba60d

Browse files
author
averiewang
committed
feat: support to query file details when uploading files to collection
1 parent aeb551a commit e7ba60d

File tree

6 files changed

+128
-10
lines changed

6 files changed

+128
-10
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Changelog
22

3+
## v1.7.2
4+
* feat: support float16_vector/bfloat16_vector types for HNSW vector
5+
* feat: support to query file details when uploading files to collection
36

47
## v1.7.1
58
* fix: Keep using collection/collectionView user defined to access the interface within the Collection/AICollectionView object

example/collection_upload_file_demo/main.go

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

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

2222
func NewDemo(url, username, key string) (*Demo, error) {
23-
cli, err := tcvectordb.NewRpcClient(url, username, key, &tcvectordb.ClientOption{
23+
cli, err := tcvectordb.NewClient(url, username, key, &tcvectordb.ClientOption{
2424
ReadConsistency: tcvectordb.StrongConsistency})
2525
if err != nil {
2626
return nil, err
@@ -109,8 +109,14 @@ func (d *Demo) UploadFile(ctx context.Context, database, collection, localFilePa
109109
"sectionNum": "section_num",
110110
},
111111
MetaData: map[string]interface{}{
112-
"testStr": "v1",
113-
"testInt": 1024,
112+
"testStr": "v1",
113+
"testInt": 1024,
114+
"testDouble": 0.1,
115+
"testArray": []string{"one", "two"},
116+
"testJson": map[string]interface{}{
117+
"a": 1,
118+
"b": "str",
119+
},
114120
},
115121
}
116122

@@ -125,6 +131,22 @@ func (d *Demo) UploadFile(ctx context.Context, database, collection, localFilePa
125131

126132
func (d *Demo) QueryData(ctx context.Context, database, collection, filename string) error {
127133
time.Sleep(15 * time.Second)
134+
log.Println("------------------------------ Query file details after waiting 15s to parse file ------------------------------")
135+
//limit := int64(2)
136+
fileDetialRes, err := d.client.QueryFileDetails(ctx, database, collection, &tcvectordb.QueryFileDetailsParams{
137+
FileNames: []string{filename},
138+
// Filter: tcvectordb.NewFilter(`_indexed_status = \"Ready\"`),
139+
// Limit: &limit,
140+
// Offset: 0,
141+
// OutputFields: []string{"id", "_indexed_status", "_user_metadata"},
142+
})
143+
if err != nil {
144+
return err
145+
}
146+
for _, doc := range fileDetialRes.Documents {
147+
log.Printf("File detail: %+v", doc)
148+
}
149+
128150
log.Println("------------------------------ Query after waiting 15s to parse file ------------------------------")
129151

130152
result, err := d.client.Query(ctx, database, collection, []string{}, &tcvectordb.QueryDocumentParams{
@@ -253,21 +275,23 @@ func printErr(err error) {
253275
}
254276

255277
func main() {
256-
database := "go-sdk-demo-db"
257-
collectionName := "go-sdk-demo-col-test4"
278+
database := "test-db"
279+
collectionName := "test-coll"
258280

259281
_, filePath, _, _ := runtime.Caller(0)
260-
localFilePath := path.Join(path.Dir(filePath), "../demo_files/tcvdb.pdf")
282+
localFilePath := path.Join(path.Dir(filePath), "../demo_files/tcvdb.md")
261283
filename := filepath.Base(localFilePath)
262284

263285
ctx := context.Background()
264286
testVdb, err := NewDemo("vdb http url or ip and port", "vdb username", "key get from web console")
287+
printErr(err)
288+
err = testVdb.DeleteAndDrop(ctx, database, collectionName)
289+
printErr(err)
265290
err = testVdb.CreateDBAndCollection(ctx, database, collectionName)
266291
printErr(err)
267292
err = testVdb.UploadFile(ctx, database, collectionName, localFilePath)
268293
printErr(err)
269294
err = testVdb.QueryData(ctx, database, collectionName, filename)
270295
printErr(err)
271-
err = testVdb.DeleteAndDrop(ctx, database, collectionName)
272-
printErr(err)
296+
273297
}

tcvectordb/api/document/api.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,3 +313,25 @@ type ImageInfo struct {
313313
ImageName string `json:"imageName"`
314314
ImageUrl string `json:"imageUrl"`
315315
}
316+
317+
type QueryFileDetailsReq struct {
318+
api.Meta `path:"/ai/document/queryFileDetails" tags:"Document" method:"Post" summary:"查询文件详情"`
319+
Database string `json:"database"`
320+
Collection string `json:"collection"`
321+
ReadConsistency string `json:"readConsistency,omitempty"`
322+
Query *QueryFileDetailsCond `json:"query,omitempty"`
323+
}
324+
325+
type QueryFileDetailsCond struct {
326+
FileNames []string `json:"fileNames,omitempty"`
327+
Filter string `json:"filter,omitempty"`
328+
Limit *int64 `json:"limit,omitempty"`
329+
Offset int64 `json:"offset,omitempty"`
330+
OutputFields []string `json:"outputFields,omitempty"`
331+
}
332+
333+
type QueryFileDetailsRes struct {
334+
api.CommonRes
335+
Count uint64 `json:"count"`
336+
Documents []*Document `json:"documents"`
337+
}

tcvectordb/base_flat.go

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ type FlatInterface interface {
9797

9898
GetImageUrl(ctx context.Context, databaseName, collectionName string,
9999
param GetImageUrlParams) (result *GetImageUrlResult, err error)
100+
101+
QueryFileDetails(ctx context.Context, databaseName, collectionName string,
102+
param *QueryFileDetailsParams) (result *QueryFileDetailsResult, err error)
100103
}
101104

102105
// [CreateUserParams] holds the parameters for creating the user.
@@ -557,3 +560,64 @@ func getImageUrl(ctx context.Context, cli SdkClient, databaseName, collectionNam
557560
result.Images = res.Images
558561
return result, nil
559562
}
563+
564+
type QueryFileDetailsParams struct {
565+
FileNames []string
566+
Filter *Filter
567+
Limit *int64
568+
Offset int64
569+
OutputFields []string
570+
}
571+
572+
type QueryFileDetailsResult struct {
573+
Documents []Document
574+
Count uint64
575+
}
576+
577+
func (i *implementerFlatDocument) QueryFileDetails(ctx context.Context, databaseName, collectionName string,
578+
param *QueryFileDetailsParams) (result *QueryFileDetailsResult, err error) {
579+
return queryFileDetails(ctx, i.SdkClient, databaseName, collectionName, param)
580+
}
581+
582+
func queryFileDetails(ctx context.Context, cli SdkClient, databaseName, collectionName string,
583+
param *QueryFileDetailsParams) (result *QueryFileDetailsResult, err error) {
584+
req := new(document.QueryFileDetailsReq)
585+
req.Database = databaseName
586+
req.Collection = collectionName
587+
if param != nil {
588+
req.Query = new(document.QueryFileDetailsCond)
589+
req.Query.FileNames = param.FileNames
590+
if param.Filter != nil {
591+
req.Query.Filter = param.Filter.Cond()
592+
}
593+
if param.Limit != nil {
594+
req.Query.Limit = param.Limit
595+
}
596+
req.Query.Offset = param.Offset
597+
req.Query.OutputFields = param.OutputFields
598+
}
599+
600+
res := new(document.QueryFileDetailsRes)
601+
err = cli.Request(ctx, req, res)
602+
if err != nil {
603+
return nil, err
604+
}
605+
606+
result = new(QueryFileDetailsResult)
607+
result.Count = res.Count
608+
609+
result.Documents = make([]Document, len(res.Documents))
610+
611+
for index, doc := range res.Documents {
612+
var d Document
613+
d.Id = doc.Id
614+
d.Fields = make(map[string]Field)
615+
616+
for n, v := range doc.Fields {
617+
d.Fields[n] = Field{Val: v}
618+
}
619+
result.Documents[index] = d
620+
}
621+
622+
return result, nil
623+
}

tcvectordb/rpc_base_document.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -973,3 +973,8 @@ func (r *rpcImplementerFlatDocument) UploadFile(ctx context.Context, databaseNam
973973
func (r *rpcImplementerFlatDocument) GetImageUrl(ctx context.Context, databaseName, collectionName string, param GetImageUrlParams) (result *GetImageUrlResult, err error) {
974974
return getImageUrl(ctx, r.SdkClient, databaseName, collectionName, param)
975975
}
976+
977+
func (r *rpcImplementerFlatDocument) QueryFileDetails(ctx context.Context, databaseName, collectionName string,
978+
param *QueryFileDetailsParams) (result *QueryFileDetailsResult, err error) {
979+
return queryFileDetails(ctx, r.SdkClient, databaseName, collectionName, param)
980+
}

tcvectordb/version.go

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

1919
package tcvectordb
2020

21-
const SDKVersion = "v1.7.1"
21+
const SDKVersion = "v1.7.2"

0 commit comments

Comments
 (0)