Skip to content

Commit 960eb97

Browse files
committed
Merge branch 'feat/averiewang/support-bm25' into 'main' (merge request !53)
feat: add example
2 parents 655cd57 + 09afea4 commit 960eb97

File tree

1 file changed

+36
-7
lines changed

1 file changed

+36
-7
lines changed

example/sparse_vector_demo/main.go

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package main
33
import (
44
"context"
55
"log"
6-
"strconv"
76
"time"
87

98
"github.com/tencent/vectordatabase-sdk-go/tcvdbtext/encoder"
@@ -158,17 +157,47 @@ func (d *Demo) UpsertData(ctx context.Context, database, collection string) erro
158157

159158
log.Println("------------------------------ Upsert ------------------------------")
160159

161-
documentList := make([]tcvectordb.Document, 0)
162-
for i := 0; i < 5; i++ {
163-
id := "000" + strconv.Itoa(i)
164-
documentList = append(documentList, tcvectordb.Document{
165-
Id: id,
160+
documentList := []tcvectordb.Document{
161+
{
162+
Id: "0001",
166163
Vector: []float32{0.2123, 0.21, 0.213},
167164
SparseVector: []encoder.SparseVecItem{
168165
{TermId: 1172076521, Score: 0.71296215},
169166
{TermId: 3434399993, Score: 0.71296215},
170167
},
171-
})
168+
},
169+
{
170+
Id: "0002",
171+
Vector: []float32{0.2123, 0.22, 0.213},
172+
SparseVector: []encoder.SparseVecItem{
173+
{TermId: 225043997, Score: 0.71296215},
174+
{TermId: 256049420, Score: 0.71296215},
175+
},
176+
},
177+
{
178+
Id: "0003",
179+
Vector: []float32{0.2123, 0.23, 0.213},
180+
SparseVector: []encoder.SparseVecItem{
181+
{TermId: 4162843804, Score: 0.71296215},
182+
{TermId: 256049420, Score: 0.71296215},
183+
},
184+
},
185+
{
186+
Id: "0004",
187+
Vector: []float32{0.2123, 0.24, 0.213},
188+
SparseVector: []encoder.SparseVecItem{
189+
{TermId: 3656406568, Score: 0.71296215},
190+
{TermId: 256049420, Score: 0.71296215},
191+
},
192+
},
193+
{
194+
Id: "0005",
195+
Vector: []float32{0.2123, 0.25, 0.213},
196+
SparseVector: []encoder.SparseVecItem{
197+
{TermId: 4162843804, Score: 0.71296215},
198+
{TermId: 3656406568, Score: 0.71296215},
199+
},
200+
},
172201
}
173202

174203
result, err := coll.Upsert(ctx, documentList)

0 commit comments

Comments
 (0)