embedderapi

package
v1.44.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 3, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const Description = `` /* 164-byte string literal not displayed */

Description is the human-readable summary of the microservice, surfaced in OpenAPI and discovery.

View Source
const Hostname = "embedder.example"

Hostname is the default hostname of the microservice.

View Source
const Name = "Embedder"

Name is the decorative PascalCase name of the microservice.

View Source
const Version = 2

Version is a generation counter bumped on each regeneration, not a semantic version.

Variables

View Source
var Demo = define.Web{
	Host: Hostname, Method: "ANY", Route: ":443/demo",
}

Demo serves the interactive demo page for the embedder.

View Source
var DemoInit = define.Web{
	Host: Hostname, Method: "POST", Route: ":443/demo/init",
}

DemoInit kicks off Python venv allocation in the background. It is idempotent: a second call while initialization is pending or already ready returns the current status without restarting.

View Source
var DemoStatus = define.Web{
	Host: Hostname, Method: "GET", Route: ":443/demo/status",
}

DemoStatus is a long-poll endpoint reporting venv initialization status and tailed logs. The client passes its last-seen ETag via If-None-Match; the server snapshots the current status and logs, hashes them into an ETag, and:

  • returns 200 with the new ETag and body if the snapshot differs;
  • holds the connection (polling every 500ms) until the snapshot changes;
  • returns 204 No Content when the request is within ~1s of its deadline without any change, so the client can immediately re-issue the request with the same ETag.

A fresh client (no If-None-Match) gets the current snapshot back on the first iteration.

View Source
var Embed = define.Function{
	Host: Hostname, Method: "GET", Route: ":443/embed",
	Manual: true, Tags: []string{"python"},
	In: EmbedIn{}, Out: EmbedOut{},
}

Embed returns the sentence-embedding vector for the input text.

View Source
var MaxWorkers = define.Config{
	Value:      int(0),
	Default:    "2",
	Validation: "int [1,]",
}

MaxWorkers caps how many calls into the Python venv may run concurrently.

View Source
var Similarity = define.Function{
	Host: Hostname, Method: "GET", Route: ":443/similarity",
	Manual: true, Tags: []string{"python"},
	In: SimilarityIn{}, Out: SimilarityOut{},
}

Similarity returns the cosine similarity between the embeddings of strings a and b.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is a lightweight proxy for making unicast calls to the microservice.

func NewClient

func NewClient(caller service.Publisher) Client

NewClient creates a new unicast client proxy to the microservice.

func (Client) Demo

func (_c Client) Demo(ctx context.Context, method string, relativeURL string, body any) (res *http.Response, err error)

Demo serves the interactive demo page for the embedder.

func (Client) DemoInit

func (_c Client) DemoInit(ctx context.Context, relativeURL string, body any) (res *http.Response, err error)

DemoInit kicks off Python venv allocation in the background. It is idempotent: a second call while initialization is pending or already ready returns the current status without restarting.

func (Client) DemoStatus

func (_c Client) DemoStatus(ctx context.Context, relativeURL string) (res *http.Response, err error)

DemoStatus is a long-poll endpoint reporting venv initialization status and tailed logs. The client passes its last-seen ETag via If-None-Match; the server snapshots the current status and logs, hashes them into an ETag, and:

  • returns 200 with the new ETag and body if the snapshot differs;
  • holds the connection (polling every 500ms) until the snapshot changes;
  • returns 204 No Content when the request is within ~1s of its deadline without any change, so the client can immediately re-issue the request with the same ETag.

A fresh client (no If-None-Match) gets the current snapshot back on the first iteration.

func (Client) Embed

func (_c Client) Embed(ctx context.Context, text string) (vector []float64, err error)

Embed returns the sentence-embedding vector for the input text.

func (Client) ForHost

func (_c Client) ForHost(host string) Client

ForHost returns a copy of the client with a different hostname to be applied to requests.

func (Client) Similarity

func (_c Client) Similarity(ctx context.Context, a string, b string) (score float64, err error)

Similarity returns the cosine similarity between the embeddings of strings a and b.

func (Client) WithOptions

func (_c Client) WithOptions(opts ...pub.Option) Client

WithOptions returns a copy of the client with options to be applied to requests.

type EmbedIn

type EmbedIn struct {
	Text string `json:"text,omitzero" jsonschema_description:"Text is the input string to embed"`
}

EmbedIn are the input arguments of Embed.

type EmbedOut

type EmbedOut struct {
	Vector []float64 `json:"vector,omitzero" jsonschema_description:"Vector is the embedding produced by the model"`
}

EmbedOut are the output arguments of Embed.

type EmbedResponse

type EmbedResponse multicastResponse // MARKER: Embed

EmbedResponse packs the response of Embed.

func (*EmbedResponse) Get

func (_res *EmbedResponse) Get() (vector []float64, err error)

Get unpacks the return arguments of Embed.

type MulticastClient

type MulticastClient struct {
	// contains filtered or unexported fields
}

MulticastClient is a lightweight proxy for making multicast calls to the microservice.

func NewMulticastClient

func NewMulticastClient(caller service.Publisher) MulticastClient

NewMulticastClient creates a new multicast client proxy to the microservice.

func (MulticastClient) Demo

func (_c MulticastClient) Demo(ctx context.Context, method string, relativeURL string, body any) iter.Seq[*pub.Response]

Demo serves the interactive demo page for the embedder.

func (MulticastClient) DemoInit

func (_c MulticastClient) DemoInit(ctx context.Context, relativeURL string, body any) iter.Seq[*pub.Response]

DemoInit kicks off Python venv allocation in the background. It is idempotent: a second call while initialization is pending or already ready returns the current status without restarting.

func (MulticastClient) DemoStatus

func (_c MulticastClient) DemoStatus(ctx context.Context, relativeURL string) iter.Seq[*pub.Response]

DemoStatus is a long-poll endpoint reporting venv initialization status and tailed logs. The client passes its last-seen ETag via If-None-Match; the server snapshots the current status and logs, hashes them into an ETag, and:

  • returns 200 with the new ETag and body if the snapshot differs;
  • holds the connection (polling every 500ms) until the snapshot changes;
  • returns 204 No Content when the request is within ~1s of its deadline without any change, so the client can immediately re-issue the request with the same ETag.

A fresh client (no If-None-Match) gets the current snapshot back on the first iteration.

func (MulticastClient) Embed

func (_c MulticastClient) Embed(ctx context.Context, text string) iter.Seq[*EmbedResponse]

Embed returns the sentence-embedding vector for the input text.

func (MulticastClient) ForHost

func (_c MulticastClient) ForHost(host string) MulticastClient

ForHost returns a copy of the client with a different hostname to be applied to requests.

func (MulticastClient) Similarity

Similarity returns the cosine similarity between the embeddings of strings a and b.

func (MulticastClient) WithOptions

func (_c MulticastClient) WithOptions(opts ...pub.Option) MulticastClient

WithOptions returns a copy of the client with options to be applied to requests.

type SimilarityIn

type SimilarityIn struct {
	A string `json:"a,omitzero" jsonschema_description:"A is the first input string"`
	B string `json:"b,omitzero" jsonschema_description:"B is the second input string"`
}

SimilarityIn are the input arguments of Similarity.

type SimilarityOut

type SimilarityOut struct {
	Score float64 `json:"score,omitzero" jsonschema_description:"Score is the cosine similarity in [-1.0, 1.0]"`
}

SimilarityOut are the output arguments of Similarity.

type SimilarityResponse

type SimilarityResponse multicastResponse // MARKER: Similarity

SimilarityResponse packs the response of Similarity.

func (*SimilarityResponse) Get

func (_res *SimilarityResponse) Get() (score float64, err error)

Get unpacks the return arguments of Similarity.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL