-
Notifications
You must be signed in to change notification settings - Fork 1
/
null.go
59 lines (41 loc) · 1.13 KB
/
null.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
package embeddings
import (
"context"
)
// NullEmbedder implements the `Embedder` interface using an Null API endpoint to derive embeddings.
type NullEmbedder struct {
Embedder
}
func init() {
ctx := context.Background()
err := RegisterEmbedder(ctx, "null", NewNullEmbedder)
if err != nil {
panic(err)
}
}
func NewNullEmbedder(ctx context.Context, uri string) (Embedder, error) {
e := &NullEmbedder{}
return e, nil
}
func (e *NullEmbedder) Embeddings(ctx context.Context, content string) ([]float64, error) {
embeddings := make([]float64, 0)
return embeddings, nil
}
func (e *NullEmbedder) Embeddings32(ctx context.Context, content string) ([]float32, error) {
e64, err := e.Embeddings(ctx, content)
if err != nil {
return nil, err
}
return asFloat32(e64), nil
}
func (e *NullEmbedder) ImageEmbeddings(ctx context.Context, data []byte) ([]float64, error) {
embeddings := make([]float64, 0)
return embeddings, nil
}
func (e *NullEmbedder) ImageEmbeddings32(ctx context.Context, data []byte) ([]float32, error) {
e64, err := e.ImageEmbeddings(ctx, data)
if err != nil {
return nil, err
}
return asFloat32(e64), nil
}