fastapi

package
v0.36.4 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package fastapi provides an embedder client for remote FastAPI embedding servers.

Use this package to connect to a custom FastAPI server that exposes an /embed endpoint for generating vector embeddings. Supports authentication via API keys.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(serverURL string, opts ...Option) (embeddings.Embedder, error)

New creates a new FastAPI embedder client.

Types

type Embedder

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

Embedder communicates with a remote FastAPI server to generate embeddings. It directly implements the embeddings.Embedder interface.

func (*Embedder) EmbedDocuments

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

EmbedDocuments sends a batch of documents to the FastAPI server for embedding.

func (*Embedder) EmbedQueries

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

EmbedQueries embeds a batch of queries.

func (*Embedder) EmbedQuery

func (e *Embedder) EmbedQuery(ctx context.Context, text string) ([]float32, error)

EmbedQuery embeds a single query.

func (*Embedder) GetDimension

func (e *Embedder) GetDimension(ctx context.Context) (int, error)

GetDimension lazily fetches the embedding dimension by sending a test query.

type Option

type Option func(*options)

Option defines a function type for configuring the embedder.

func WithAPIKey

func WithAPIKey(key string) Option

func WithHTTPClient

func WithHTTPClient(client *http.Client) Option

WithHTTPClient allows providing a custom http.Client.

func WithLogger

func WithLogger(logger *slog.Logger) Option

WithLogger sets a custom logger.

func WithTask

func WithTask(task string) Option

WithTask allows overriding the default task description sent to the API.

Jump to

Keyboard shortcuts

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