forked from philippgille/chromem-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
document_test.go
64 lines (60 loc) · 1.43 KB
/
document_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
package chromem
import (
"context"
"reflect"
"testing"
)
func TestDocument_New(t *testing.T) {
ctx := context.Background()
id := "test"
metadata := map[string]string{"foo": "bar"}
vectors := []float32{-0.40824828, 0.40824828, 0.81649655} // normalized version of `{-0.1, 0.1, 0.2}`
content := "hello world"
embeddingFunc := func(_ context.Context, _ string) ([]float32, error) {
return vectors, nil
}
tt := []struct {
name string
id string
metadata map[string]string
vectors []float32
content string
embeddingFunc EmbeddingFunc
}{
{
name: "No embedding",
id: id,
metadata: metadata,
vectors: nil,
content: content,
embeddingFunc: embeddingFunc,
},
{
name: "With embedding",
id: id,
metadata: metadata,
vectors: vectors,
content: content,
embeddingFunc: embeddingFunc,
},
}
for _, tc := range tt {
t.Run(tc.name, func(t *testing.T) {
// Create document
d, err := NewDocument(ctx, id, metadata, vectors, content, embeddingFunc)
if err != nil {
t.Fatal("expected no error, got", err)
}
// We can compare with DeepEqual after removing the embedding function
d.Embedding = nil
exp := Document{
ID: id,
Metadata: metadata,
Content: content,
}
if !reflect.DeepEqual(exp, d) {
t.Fatalf("expected %+v, got %+v", exp, d)
}
})
}
}