@@ -21,6 +21,7 @@ import (
21
21
"fmt"
22
22
23
23
"github.com/firebase/genkit/go/core"
24
+ "github.com/firebase/genkit/go/internal/base"
24
25
"github.com/firebase/genkit/go/internal/registry"
25
26
)
26
27
@@ -32,6 +33,32 @@ type Embedder interface {
32
33
Embed (ctx context.Context , req * EmbedRequest ) (* EmbedResponse , error )
33
34
}
34
35
36
+ // EmbedderInfo represents the structure of the embedder information object.
37
+ type EmbedderInfo struct {
38
+ // Label is a user-friendly name for the embedder model (e.g., "Google AI - Gemini Pro").
39
+ Label string `json:"label,omitempty"`
40
+ // Supports defines the capabilities of the embedder, such as input types and multilingual support.
41
+ Supports * EmbedderSupports `json:"supports,omitempty"`
42
+ // Dimensions specifies the number of dimensions in the embedding vector.
43
+ Dimensions int `json:"dimensions,omitempty"`
44
+ }
45
+
46
+ // EmbedderSupports represents the supported capabilities of the embedder model.
47
+ type EmbedderSupports struct {
48
+ // Input lists the types of data the model can process (e.g., "text", "image", "video").
49
+ Input []string `json:"input,omitempty"`
50
+ // Multilingual indicates whether the model supports multiple languages.
51
+ Multilingual bool `json:"multilingual,omitempty"`
52
+ }
53
+
54
+ // EmbedderOptions represents the configuration options for an embedder.
55
+ type EmbedderOptions struct {
56
+ // ConfigSchema defines the schema for the embedder's configuration options.
57
+ ConfigSchema any `json:"configSchema,omitempty"`
58
+ // Info contains metadata about the embedder, such as its label and capabilities.
59
+ Info * EmbedderInfo `json:"info,omitempty"`
60
+ }
61
+
35
62
// An embedder is used to convert a document to a multidimensional vector.
36
63
type embedder core.ActionDef [* EmbedRequest , * EmbedResponse , struct {}]
37
64
@@ -40,9 +67,22 @@ type embedder core.ActionDef[*EmbedRequest, *EmbedResponse, struct{}]
40
67
func DefineEmbedder (
41
68
r * registry.Registry ,
42
69
provider , name string ,
70
+ opts * EmbedderOptions ,
43
71
embed func (context.Context , * EmbedRequest ) (* EmbedResponse , error ),
44
72
) Embedder {
45
- return (* embedder )(core .DefineAction (r , provider , name , core .ActionTypeEmbedder , nil , embed ))
73
+ metadata := map [string ]any {}
74
+ metadata ["type" ] = "embedder"
75
+ metadata ["info" ] = opts .Info
76
+ if opts .ConfigSchema != nil {
77
+ metadata ["embedder" ] = map [string ]any {"customOptions" : base .ToSchemaMap (opts .ConfigSchema )}
78
+ }
79
+ inputSchema := base .InferJSONSchema (EmbedRequest {})
80
+ if inputSchema .Properties != nil && opts .ConfigSchema != nil {
81
+ if _ , ok := inputSchema .Properties .Get ("options" ); ok {
82
+ inputSchema .Properties .Set ("options" , base .InferJSONSchema (opts .ConfigSchema ))
83
+ }
84
+ }
85
+ return (* embedder )(core .DefineActionWithInputSchema (r , provider , name , core .ActionTypeEmbedder , metadata , inputSchema , embed ))
46
86
}
47
87
48
88
// LookupEmbedder looks up an [Embedder] registered by [DefineEmbedder].
0 commit comments