-
Notifications
You must be signed in to change notification settings - Fork 1
/
upsert_test.go
80 lines (71 loc) · 1.85 KB
/
upsert_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package vector
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestUpsert(t *testing.T) {
for _, ns := range namespaces {
t.Run("namespace_"+ns, func(t *testing.T) {
client, err := newTestClientWithNamespace(ns)
require.NoError(t, err)
t.Run("single", func(t *testing.T) {
id := randomString()
err := client.Upsert(Upsert{
Id: id,
Vector: []float32{0, 1},
})
require.NoError(t, err)
vectors, err := client.Fetch(Fetch{
Ids: []string{id},
})
require.NoError(t, err)
require.Equal(t, 1, len(vectors))
require.Equal(t, id, vectors[0].Id)
})
t.Run("many", func(t *testing.T) {
id0 := randomString()
id1 := randomString()
err = client.UpsertMany([]Upsert{
{
Id: id0,
Vector: []float32{0, 1},
},
{
Id: id1,
Vector: []float32{5, 10},
},
})
require.NoError(t, err)
vectors, err := client.Fetch(Fetch{
Ids: []string{id0, id1},
})
require.NoError(t, err)
require.Equal(t, 2, len(vectors))
require.Equal(t, id0, vectors[0].Id)
require.Equal(t, id1, vectors[1].Id)
})
t.Run("with metadata", func(t *testing.T) {
id := randomString()
err := client.Upsert(Upsert{
Id: id,
Vector: []float32{0, 1},
Metadata: map[string]any{"foo": "bar"},
Data: "some data",
})
require.NoError(t, err)
vectors, err := client.Fetch(Fetch{
Ids: []string{id},
IncludeMetadata: true,
IncludeVectors: true,
IncludeData: true,
})
require.NoError(t, err)
require.Equal(t, 1, len(vectors))
require.Equal(t, id, vectors[0].Id)
require.Equal(t, map[string]any{"foo": "bar"}, vectors[0].Metadata)
require.Equal(t, []float32{0, 1}, vectors[0].Vector)
require.Equal(t, "some data", vectors[0].Data)
})
})
}
}