embedding

package module
v0.3.0-alpha.1 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2026 License: MIT Imports: 3 Imported by: 0

README

gokit/embedding

embedding owns the canonical embedding abstraction plus a deterministic in-memory adapter for tests.

Install

go get github.com/kbukum/gokit/embedding
go get github.com/kbukum/gokit/embedding/inmem

Quick start

package main

import (
	"context"
	"fmt"

	"github.com/kbukum/gokit/ai"
	"github.com/kbukum/gokit/embedding"
	"github.com/kbukum/gokit/embedding/inmem"
)

func main() {
	provider := inmem.New(8)

	resp, err := provider.Execute(context.Background(), embedding.EmbedRequest{
		Model: ai.Model{Name: "inmem-embedding", Provider: ai.ProviderCustom},
		Inputs: []embedding.EmbedInput{
			embedding.Text{Text: "native provider shapes keep modules composable"},
		},
	})
	if err != nil {
		panic(err)
	}

	fmt.Println(resp.Embeddings[0].Dimensions)
}

When to use

Use embedding for canonical vector generation contracts. Provider implementations live here or in the provider-specific module that naturally owns the backend.

Documentation

Overview

Package embedding provides abstractions for text embedding providers and vector utility functions for computing distances and aggregations.

For concrete provider implementations, see the vendor modules:

  • github.com/kbukum/gokit/llm/providers/openai (OpenAI-compatible)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Audio

type Audio struct {
	Data []byte `json:"data,omitempty"`
	URL  string `json:"url,omitempty"`
}

Audio is an audio embedding input, either inline bytes or a URL.

type EmbedInput

type EmbedInput interface {
	// contains filtered or unexported methods
}

EmbedInput is the sealed interface for embedding inputs.

type EmbedRequest

type EmbedRequest struct {
	Model   ai.Model       `json:"model"`
	Inputs  []EmbedInput   `json:"inputs"`
	Options map[string]any `json:"options,omitempty"`
}

EmbedRequest carries embedding inputs and provider-specific options.

type EmbedResponse

type EmbedResponse struct {
	Embedding  Embedding   `json:"embedding"`
	Embeddings []Embedding `json:"embeddings,omitempty"`
	Model      ai.Model    `json:"model"`
	Usage      ai.Usage    `json:"usage,omitempty"`
}

EmbedResponse carries normalized embeddings, model echo, and usage.

type Embedding

type Embedding struct {
	Vector     []float32 `json:"vector"`
	Dimensions int       `json:"dimensions"`
	Index      int       `json:"index"`
}

Embedding is a normalized vector with its request index.

type Image

type Image struct {
	Data []byte `json:"data,omitempty"`
	URL  string `json:"url,omitempty"`
}

Image is an image embedding input, either inline bytes or a URL.

type Provider

type Provider interface {
	provider.RequestResponse[EmbedRequest, EmbedResponse]
	EmbedBatch(ctx context.Context, reqs []EmbedRequest) ([]EmbedResponse, error)
}

Provider generates vector embeddings for text and multimodal inputs.

Per locked decision D7 (NATIVE EMBED), Provider natively embeds provider.RequestResponse so any embedding provider drops into dag / pipeline / chain / worker consumers without a bridge. The single-request method IS Execute (the canonical RR method); EmbedBatch is the batched extension.

Required methods (by transitive embedding):

  • Name() string // provider.Provider
  • IsAvailable(ctx context.Context) bool // provider.Provider
  • Execute(ctx, EmbedRequest) (EmbedResponse, error) // RequestResponse
  • EmbedBatch(ctx, []EmbedRequest) ([]EmbedResponse, error)

type Text

type Text struct {
	Text string `json:"text"`
}

Text is a text embedding input.

type Video

type Video struct {
	Data []byte `json:"data,omitempty"`
	URL  string `json:"url,omitempty"`
}

Video is a video embedding input, either inline bytes or a URL.

Directories

Path Synopsis
Package inmem provides a deterministic in-memory embedding provider for tests and local development.
Package inmem provides a deterministic in-memory embedding provider for tests and local development.

Jump to

Keyboard shortcuts

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