OpenAI Embeddings HTTP Client (embed/client.go)

msgvault · internal/vector/embed/client.go · go · MIT
ai, integration, lang:go

Implements an OpenAI-compatible embeddings HTTP client for converting text into vectors. Use when building vector search or retrieval pipelines.

// Source: https://github.com/obra/msgvault | License: MIT | Copyright 2025-2026 Wes McKinney
// Provided via justclaw.it.com; keep this notice with the code.
// Package embed implements an OpenAI-compatible /v1/embeddings HTTP client.
// It is used by the vector search pipeline to convert email text into
// embedding vectors suitable for ANN search.
package embed

import (
	"bytes"
	"context"
	"encoding/json"
	"errors"
	"fmt"
	"io"
	"net/http"
	"strconv"
	"strings"
	"time"
)

// ErrPermanent4xx marks a non-retryable HTTP 4xx response from the
// embeddings endpoint. Use errors.Is(err, ErrPermanent4xx) to detect
// it; the error message still carries the status code and a bounded
// response body. 429 (rate-limited) and 5xx are NOT wrapped — they
// flow through the retry loop as transient

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key