-
Notifications
You must be signed in to change notification settings - Fork 1
/
fetch_test.go
79 lines (67 loc) · 1.89 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
package vector
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestFetch(t *testing.T) {
for _, ns := range namespaces {
t.Run("namespace_"+ns, func(t *testing.T) {
client, err := newTestClientWithNamespace(ns)
require.NoError(t, err)
id0 := randomString()
id1 := randomString()
err = client.UpsertMany([]Upsert{
{
Id: id0,
Vector: []float32{0, 1},
Metadata: map[string]any{"foo": "bar"},
},
{
Id: id1,
Vector: []float32{5, 10},
},
})
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, []float32{0, 1}, vectors[0].Vector)
require.Equal(t, id1, vectors[1].Id)
require.Nil(t, vectors[1].Metadata) // was upserted with nil metadata
require.Equal(t, []float32{5, 10}, vectors[1].Vector)
})
})
}
}