Documentation
¶
Index ¶
- Constants
- type Intermediate
- type Mock
- func (svc *Mock) Demo(w http.ResponseWriter, r *http.Request) (err error)
- func (svc *Mock) DemoInit(w http.ResponseWriter, r *http.Request) (err error)
- func (svc *Mock) DemoStatus(w http.ResponseWriter, r *http.Request) (err error)
- func (svc *Mock) Embed(ctx context.Context, text string) (vector []float64, err error)
- func (svc *Mock) MockDemo(handler func(w http.ResponseWriter, r *http.Request) (err error)) *Mock
- func (svc *Mock) MockDemoInit(handler func(w http.ResponseWriter, r *http.Request) (err error)) *Mock
- func (svc *Mock) MockDemoStatus(handler func(w http.ResponseWriter, r *http.Request) (err error)) *Mock
- func (svc *Mock) MockEmbed(handler func(ctx context.Context, text string) (vector []float64, err error)) *Mock
- func (svc *Mock) MockSimilarity(...) *Mock
- func (svc *Mock) OnShutdown(ctx context.Context) (err error)
- func (svc *Mock) OnStartup(ctx context.Context) (err error)
- func (svc *Mock) Similarity(ctx context.Context, a string, b string) (score float64, err error)
- type Service
- func (svc *Service) Demo(w http.ResponseWriter, r *http.Request) (err error)
- func (svc *Service) DemoInit(w http.ResponseWriter, r *http.Request) (err error)
- func (svc *Service) DemoStatus(w http.ResponseWriter, r *http.Request) (err error)
- func (svc *Service) Embed(ctx context.Context, text string) (vector []float64, err error)
- func (svc *Service) Init(initializer func(svc *Service) (err error)) *Service
- func (svc *Service) OnShutdown(ctx context.Context) (err error)
- func (svc *Service) OnStartup(ctx context.Context) (err error)
- func (svc *Service) Similarity(ctx context.Context, a string, b string) (score float64, err error)
- func (svc *Service) StartPyVenv(ctx context.Context) error
- type ToDo
Constants ¶
const ( Hostname = embedderapi.Hostname Version = 2 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Intermediate ¶
Intermediate extends and customizes the generic base connector.
func NewIntermediate ¶
func NewIntermediate(impl ToDo) *Intermediate
NewIntermediate creates a new instance of the intermediate.
func (*Intermediate) MaxWorkers ¶
func (svc *Intermediate) MaxWorkers() (value int)
MaxWorkers caps how many calls into the Python venv may run concurrently.
func (*Intermediate) SetMaxWorkers ¶
func (svc *Intermediate) SetMaxWorkers(value int) (err error)
SetMaxWorkers sets the value of the configuration property.
type Mock ¶
type Mock struct {
*Intermediate
// contains filtered or unexported fields
}
Mock is a mockable version of the microservice, allowing functions, event sinks and web handlers to be mocked.
func (*Mock) DemoStatus ¶
DemoStatus executes the mock handler.
func (*Mock) MockDemoInit ¶
func (svc *Mock) MockDemoInit(handler func(w http.ResponseWriter, r *http.Request) (err error)) *Mock
MockDemoInit sets up a mock handler for DemoInit.
func (*Mock) MockDemoStatus ¶
func (svc *Mock) MockDemoStatus(handler func(w http.ResponseWriter, r *http.Request) (err error)) *Mock
MockDemoStatus sets up a mock handler for DemoStatus.
func (*Mock) MockEmbed ¶
func (svc *Mock) MockEmbed(handler func(ctx context.Context, text string) (vector []float64, err error)) *Mock
MockEmbed sets up a mock handler for Embed.
func (*Mock) MockSimilarity ¶
func (svc *Mock) MockSimilarity(handler func(ctx context.Context, a string, b string) (score float64, err error)) *Mock
MockSimilarity sets up a mock handler for Similarity.
func (*Mock) OnShutdown ¶
OnShutdown is called when the microservice is shut down.
type Service ¶
type Service struct {
*Intermediate // IMPORTANT: Do not remove
// contains filtered or unexported fields
}
Service implements the embedder.example microservice.
Embedder loads a sentence-transformers model in an in-process Python virtual environment via the github.com/microbus-io/pyvenv module and exposes two typed Go endpoints that delegate to it: Embed returns the vector for one string; Similarity returns the cosine similarity between two strings. The model loads on first Start of the venv and stays warm for subsequent calls.
func (*Service) DemoInit ¶
DemoInit kicks off Python venv Start in the background. Idempotent: a second invocation while initialization is pending or already ready returns the current status without restarting.
func (*Service) DemoStatus ¶
DemoStatus is a long-poll endpoint. The client passes its last-seen ETag via If-None-Match; the server snapshots the current status + tailed 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 if the request context 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 (*Service) OnShutdown ¶
OnShutdown is called when the microservice is shut down.
func (*Service) OnStartup ¶
OnStartup is called when the microservice is started up. The Python venv is constructed but not started; the demo page's "Initialize Python VM" button triggers the actual Start in the background so the multi-second pip install + model download is visible to the user rather than buried in the startup banner.
func (*Service) Similarity ¶
Similarity returns the cosine similarity between the embeddings of strings a and b.
func (*Service) StartPyVenv ¶
StartPyVenv synchronously starts the Python venv: pip install (skipped if requirements haven't changed), spawn the worker, load the embedded sources. Returns when the worker is Ready or on error. Tests opt in to running real Python by calling this directly.
type ToDo ¶
type ToDo interface {
OnStartup(ctx context.Context) (err error)
OnShutdown(ctx context.Context) (err error)
Embed(ctx context.Context, text string) (vector []float64, err error) // MARKER: Embed
Similarity(ctx context.Context, a string, b string) (score float64, err error) // MARKER: Similarity
Demo(w http.ResponseWriter, r *http.Request) (err error) // MARKER: Demo
DemoInit(w http.ResponseWriter, r *http.Request) (err error) // MARKER: DemoInit
DemoStatus(w http.ResponseWriter, r *http.Request) (err error) // MARKER: DemoStatus
}
ToDo is implemented by the service or mock. The intermediate delegates handling to this interface.