-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfetch_test.go
89 lines (75 loc) · 2.21 KB
/
fetch_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
81
82
83
84
85
86
87
88
89
package vector
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestFetch(t *testing.T) {
for _, ns := range namespaces {
for _, tcType := range testClientTypes {
t.Run("namespace_"+ns+"_index_type_"+string(tcType), func(t *testing.T) {
client, err := newTestClient(tcType, ns)
require.NoError(t, err)
id0 := randomString()
v0, sv0 := randomVectors(tcType)
id1 := randomString()
v1, sv1 := randomVectors(tcType)
err = client.UpsertMany([]Upsert{
{
Id: id0,
Vector: v0,
SparseVector: sv0,
Metadata: map[string]any{"foo": "bar"},
},
{
Id: id1,
Vector: v1,
SparseVector: sv1,
},
})
require.NoError(t, err)
t.Run("single", func(t *testing.T) {
vectors, err := client.Fetch(Fetch{
Ids: []string{id0},
})
require.NoError(t, err)
require.Equal(t, 1, len(vectors))
require.Equal(t, id0, vectors[0].Id)
})
t.Run("many", func(t *testing.T) {
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("non existing id", func(t *testing.T) {
vectors, err := client.Fetch(Fetch{
Ids: []string{randomString()},
})
require.NoError(t, err)
require.Equal(t, 1, len(vectors))
require.Equal(t, "", vectors[0].Id)
})
t.Run("with metadata and vectors", func(t *testing.T) {
vectors, err := client.Fetch(Fetch{
Ids: []string{id0, id1},
IncludeMetadata: true,
IncludeVectors: true,
})
require.NoError(t, err)
require.Equal(t, 2, len(vectors))
require.Equal(t, id0, vectors[0].Id)
require.Equal(t, map[string]any{"foo": "bar"}, vectors[0].Metadata)
require.Equal(t, v0, vectors[0].Vector)
require.Equal(t, sv0, vectors[0].SparseVector)
require.Equal(t, id1, vectors[1].Id)
require.Nil(t, vectors[1].Metadata) // was upserted with nil metadata
require.Equal(t, v1, vectors[1].Vector)
require.Equal(t, sv1, vectors[1].SparseVector)
})
})
}
}
}