embed

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package embed defines embedder interfaces and a deterministic test fixture.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ContextualEmbedder added in v0.4.0

type ContextualEmbedder interface {
	EmbedDocumentChunks(ctx context.Context, fullDoc string, chunks []string) ([][]float64, error)
}

ContextualEmbedder optionally embeds chunk texts with access to the full source document, enabling late-chunking or other context-aware strategies without changing the base Embedder contract.

type Embedder

type Embedder interface {
	Fingerprint() string
	Dimension(ctx context.Context) (int, error)
	EmbedDocuments(ctx context.Context, texts []string) ([][]float64, error)
	EmbedQueries(ctx context.Context, texts []string) ([][]float64, error)
}

Embedder generates embeddings for stored records and live queries.

type Fixture

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

Fixture is a deterministic embedder for tests and offline use.

func NewFixture

func NewFixture(model string, dimensions int) (*Fixture, error)

NewFixture returns a deterministic hash-based embedder.

func (*Fixture) Dimension

func (f *Fixture) Dimension(ctx context.Context) (int, error)

Dimension reports the embedding dimensionality.

func (*Fixture) EmbedDocuments

func (f *Fixture) EmbedDocuments(ctx context.Context, texts []string) ([][]float64, error)

EmbedDocuments returns deterministic embeddings for indexed document texts.

func (*Fixture) EmbedQueries

func (f *Fixture) EmbedQueries(ctx context.Context, texts []string) ([][]float64, error)

EmbedQueries returns deterministic embeddings for query texts.

func (*Fixture) Fingerprint

func (f *Fixture) Fingerprint() string

Fingerprint returns a stable identifier for the fixture configuration.

type OpenAI added in v0.3.0

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

OpenAI implements Embedder against an OpenAI-compatible HTTP embeddings API.

func NewOpenAI added in v0.3.0

func NewOpenAI(cfg OpenAIConfig) *OpenAI

NewOpenAI returns an OpenAI-compatible embedder bound to cfg.

func (*OpenAI) Config added in v0.3.0

func (e *OpenAI) Config() OpenAIConfig

Config returns the normalized embedder config.

func (*OpenAI) Dimension added in v0.3.0

func (e *OpenAI) Dimension(ctx context.Context) (int, error)

Dimension probes the upstream on first use and then reuses the cached value.

func (*OpenAI) EmbedDocuments added in v0.3.0

func (e *OpenAI) EmbedDocuments(ctx context.Context, texts []string) ([][]float64, error)

EmbedDocuments generates embeddings for indexed document texts.

func (*OpenAI) EmbedQueries added in v0.3.0

func (e *OpenAI) EmbedQueries(ctx context.Context, texts []string) ([][]float64, error)

EmbedQueries generates embeddings for query texts.

func (*OpenAI) Fingerprint added in v0.3.0

func (e *OpenAI) Fingerprint() string

Fingerprint returns a deterministic identifier for the endpoint, model, and input-preparation strategy.

func (*OpenAI) Unconfigured added in v0.3.0

func (e *OpenAI) Unconfigured() bool

Unconfigured reports whether the embedder is missing a base URL or model.

type OpenAIConfig added in v0.3.0

type OpenAIConfig struct {
	BaseURL  string
	Model    string
	Timeout  time.Duration
	APIToken string
}

OpenAIConfig configures an OpenAI-compatible embedder.

func (OpenAIConfig) Enabled added in v0.3.0

func (c OpenAIConfig) Enabled() bool

Enabled reports whether the config is usable for requests.

Jump to

Keyboard shortcuts

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