embedv1
import embedv1 "pocketone.dev/ext/contracts/llm/embed/v1"
Package embedv1 is the llm.embed/v1 contract: a model turns texts into vectors, for search by meaning.
A wire contract at /api/_c/llm.embed/v1. In pb_hooks it's $llm.embed.
Source: ext/contracts/llm/embed/v1.
Variables
var Contract = extkit.NewContract[Embed]("llm.embed/v1", extkit.One).JS(extkit.JSHooks, nil).JSTypes(jsTypes)
Contract is llm.embed/v1.
var W = extkit.NewWire(Contract, "llm", func(inner Embed, g *extkit.Guard[Embed]) Embed {
return &guardEmbed{inner, g}
},
extkit.Op[Embed]{
Name: "embed",
Desc: "Returns one vector per input text, in order.",
Method: "POST",
Path: "embed",
In: reflect.TypeOf(EmbedInput{}),
Out: extkit.OutJSON,
Invoke: func(ctx context.Context, impl Embed, a extkit.Auth, req extkit.OpRequest) (any, error) {
var in EmbedInput
if err := extkit.DecodeInput(req.JSON, &in); err != nil {
return nil, err
}
return impl.Embed(ctx, a, in)
},
},
extkit.Op[Embed]{
Name: "models",
Desc: "Lists the embedding models of every provider in Settings → LLM.",
Method: "GET",
Path: "models",
Scope: "llm:read",
In: reflect.TypeOf(llm.ModelsInput{}),
Out: extkit.OutJSON,
Invoke: func(ctx context.Context, impl Embed, a extkit.Auth, req extkit.OpRequest) (any, error) {
var in llm.ModelsInput
if err := extkit.DecodeQuery(req.Query, &in); err != nil {
return nil, err
}
return impl.Models(ctx, a, in)
},
},
)
W is llm.embed/v1's wire side: routes at /api/_c/llm.embed/v1/<op>, action hooks, MCP tools and the client.
Functions
OnEmbed
func OnEmbed(owner any, fn func(e *extkit.CallEvent, in *EmbedInput) error)
OnEmbed binds fn to embed calls on owner (an app, or a host's scope for calls the host answers). Call e.Next() to continue; return an error to refuse. in is the call's input; changes reach the provider.
OnModels
func OnModels(owner any, fn func(e *extkit.CallEvent, in *llm.ModelsInput) error)
OnModels binds fn to models calls on owner (an app, or a host's scope for calls the host answers). Call e.Next() to continue; return an error to refuse. in is the call's input; changes reach the provider.
Types
Client
type Client struct {
// contains filtered or unexported fields
}
Client is llm.embed/v1 over HTTP, for the CLI and other apps. It implements Embed; the token it was made with is the credential, so the extkit.Auth argument is ignored.
NewClient
func NewClient(baseURL, token string, hc *http.Client) *Client
NewClient calls llm.embed/v1 on the app at baseURL with token (a PocketBase auth token or an API token).
Client.Embed
func (c *Client) Embed(ctx context.Context, _ extkit.Auth, in EmbedInput) (Result, error)
Client.Models
func (c *Client) Models(ctx context.Context, _ extkit.Auth, in llm.ModelsInput) (llm.Models, error)
Embed
type Embed interface {
// Embed returns one vector per input text, in order.
//
//op: POST embed
Embed(ctx context.Context, a extkit.Auth, in EmbedInput) (Result, error)
// Models lists the embedding models of every provider in Settings → LLM.
//
//op: GET models scope=llm:read
Models(ctx context.Context, a extkit.Auth, in llm.ModelsInput) (llm.Models, error)
}
Embed turns texts into vectors.
EmbedInput
type EmbedInput struct {
Model string `json:"model"` // "provider/model", required
Input []string `json:"input"`
// Dimensions shortens the vectors, for models that allow it.
Dimensions int `json:"dimensions,omitempty"`
Options llm.Options `json:"options,omitempty"`
}
EmbedInput is the texts.
Result
type Result struct {
Vectors [][]float64 `json:"vectors"`
Model string `json:"model"`
Usage llm.Usage `json:"usage"`
}
Result is the vectors, one per input.
Questions and comments
Comments are a GitHub Discussions thread; sign in with GitHub to post.