Documentation
¶
Index ¶
- Constants
- func AllowInsecureFromEnv() bool
- func ConfigFloat64(cfg EmbeddingFunctionConfig, key string) (float64, bool)
- func ConfigInt(cfg EmbeddingFunctionConfig, key string) (int, bool)
- func ConfigStringSlice(cfg EmbeddingFunctionConfig, key string) ([]string, bool)
- func HasContent(name string) bool
- func HasDense(name string) bool
- func HasMultimodal(name string) bool
- func HasSparse(name string) bool
- func IsNeutralIntent(intent Intent) bool
- func ListContent() []string
- func ListDense() []string
- func ListMultimodal() []string
- func ListSparse() []string
- func LogInsecureEnvVarWarning(providerName string)
- func NewValidator() *validator.Validate
- func RegisterContent(name string, factory ContentEmbeddingFunctionFactory) error
- func RegisterDense(name string, factory EmbeddingFunctionFactory) error
- func RegisterMultimodal(name string, factory MultimodalEmbeddingFunctionFactory) error
- func RegisterSparse(name string, factory SparseEmbeddingFunctionFactory) error
- func ValidateContentSupport(content Content, caps CapabilityMetadata) error
- func ValidateContents(contents []Content) error
- func ValidateContentsSupport(contents []Content, caps CapabilityMetadata) error
- type BinarySource
- type CapabilityAware
- type CapabilityMetadata
- type Closeable
- type ConsistentHashEmbeddingFunction
- func (e *ConsistentHashEmbeddingFunction) DefaultSpace() DistanceMetric
- func (e *ConsistentHashEmbeddingFunction) EmbedDocuments(ctx context.Context, documents []string) ([]Embedding, error)
- func (e *ConsistentHashEmbeddingFunction) EmbedQuery(_ context.Context, document string) (Embedding, error)
- func (e *ConsistentHashEmbeddingFunction) GetConfig() EmbeddingFunctionConfig
- func (e *ConsistentHashEmbeddingFunction) Name() string
- func (e *ConsistentHashEmbeddingFunction) SupportedSpaces() []DistanceMetric
- type Content
- func NewAudioFile(path string, opts ...ContentOption) Content
- func NewAudioURL(url string, opts ...ContentOption) Content
- func NewContent(parts []Part, opts ...ContentOption) Content
- func NewImageFile(path string, opts ...ContentOption) Content
- func NewImageURL(url string, opts ...ContentOption) Content
- func NewPDFFile(path string, opts ...ContentOption) Content
- func NewPDFURL(url string, opts ...ContentOption) Content
- func NewTextContent(text string, opts ...ContentOption) Content
- func NewVideoFile(path string, opts ...ContentOption) Content
- func NewVideoURL(url string, opts ...ContentOption) Content
- type ContentEmbeddingFunction
- func AdaptEmbeddingFunctionToContent(ef EmbeddingFunction, caps CapabilityMetadata) ContentEmbeddingFunction
- func AdaptMultimodalEmbeddingFunctionToContent(ef MultimodalEmbeddingFunction, caps CapabilityMetadata) ContentEmbeddingFunction
- func BuildContent(name string, config EmbeddingFunctionConfig) (ContentEmbeddingFunction, error)
- func BuildContentCloseable(name string, config EmbeddingFunctionConfig) (ContentEmbeddingFunction, func() error, error)
- type ContentEmbeddingFunctionFactory
- type ContentOption
- type Distance
- type DistanceMetric
- type DistanceMetricOperator
- type Distances
- type Embedding
- func NewEmbeddingFromFloat32(embedding []float32) Embedding
- func NewEmbeddingFromFloat64(embedding []float64) Embedding
- func NewEmbeddingFromInt32(embedding []int32) Embedding
- func NewEmbeddingsFromFloat32(lst [][]float32) ([]Embedding, error)
- func NewEmbeddingsFromInt32(lst [][]int32) ([]Embedding, error)
- func NewEmbeddingsFromInterface(lst []interface{}) ([]Embedding, error)
- func NewEmptyEmbedding() Embedding
- func NewEmptyEmbeddings() []Embedding
- func NewInt32Embedding(embedding []int32) Embedding
- type EmbeddingFunction
- func BuildDense(name string, config EmbeddingFunctionConfig) (EmbeddingFunction, error)
- func BuildDenseCloseable(name string, config EmbeddingFunctionConfig) (EmbeddingFunction, func() error, error)
- func NewConsistentHashEmbeddingFunction() EmbeddingFunction
- func NewConsistentHashEmbeddingFunctionFromConfig(cfg EmbeddingFunctionConfig) (EmbeddingFunction, error)
- type EmbeddingFunctionConfig
- type EmbeddingFunctionFactory
- type EmbeddingFunctionUnwrapper
- type EmbeddingModel
- type Embeddings
- type Float32Embedding
- func (e *Float32Embedding) Compare(other Embedding, metric DistanceMetricOperator) float32
- func (e *Float32Embedding) ContentAsFloat32() []float32
- func (e *Float32Embedding) ContentAsInt32() []int32
- func (e *Float32Embedding) FromFloat32(content ...float32) error
- func (e *Float32Embedding) IsDefined() bool
- func (e *Float32Embedding) Len() int
- func (e *Float32Embedding) MarshalJSON() ([]byte, error)
- func (e *Float32Embedding) UnmarshalJSON(b []byte) error
- type ImageInput
- type ImageInputType
- type Int32Embedding
- func (e *Int32Embedding) Compare(other Embedding, metric DistanceMetricOperator) float32
- func (e *Int32Embedding) ContentAsFloat32() []float32
- func (e *Int32Embedding) ContentAsInt32() []int32
- func (e *Int32Embedding) FromFloat32(_ ...float32) error
- func (e *Int32Embedding) FromInt32(content ...int32) error
- func (e *Int32Embedding) IsDefined() bool
- func (e *Int32Embedding) Len() int
- func (e *Int32Embedding) MarshalJSON() ([]byte, error)
- func (e *Int32Embedding) UnmarshalJSON(b []byte) error
- type Intent
- type IntentMapper
- type KnnVector
- type Modality
- type MultimodalEmbeddingFunction
- type MultimodalEmbeddingFunctionFactory
- type Part
- type RequestOption
- type Secret
- func (s Secret) Format(f fmt.State, _ rune)
- func (s Secret) GoString() string
- func (s Secret) IsEmpty() bool
- func (s Secret) LogValue() slog.Value
- func (s Secret) MarshalJSON() ([]byte, error)
- func (s Secret) String() string
- func (s *Secret) UnmarshalJSON(_ []byte) error
- func (s Secret) Value() string
- type SourceKind
- type SparseEmbeddingFunction
- type SparseEmbeddingFunctionFactory
- type SparseVector
- type ValidationError
- type ValidationIssue
Constants ¶
const AllowInsecureEnvVar = "CHROMAGO_ALLOW_INSECURE_EF"
AllowInsecureEnvVar is the environment variable that allows insecure HTTP connections for embedding functions loaded from config. This is useful for backward compatibility with existing collections that have HTTP base URLs stored in config.
const (
// MaxImageFileSize is the maximum allowed size for image files (50 MB).
MaxImageFileSize = 50 * 1024 * 1024
)
Variables ¶
This section is empty.
Functions ¶
func AllowInsecureFromEnv ¶ added in v0.3.0
func AllowInsecureFromEnv() bool
AllowInsecureFromEnv checks if insecure mode is allowed via environment variable. When true, embedding functions loaded from config will allow HTTP connections even if the stored config doesn't have insecure: true.
func ConfigFloat64 ¶ added in v0.3.0
func ConfigFloat64(cfg EmbeddingFunctionConfig, key string) (float64, bool)
ConfigFloat64 extracts a float64 from EmbeddingFunctionConfig. Handles both float64 and int types.
func ConfigInt ¶ added in v0.3.0
func ConfigInt(cfg EmbeddingFunctionConfig, key string) (int, bool)
ConfigInt extracts an integer from EmbeddingFunctionConfig. Handles both int (direct assignment) and float64 (JSON unmarshaling).
func ConfigStringSlice ¶ added in v0.3.0
func ConfigStringSlice(cfg EmbeddingFunctionConfig, key string) ([]string, bool)
ConfigStringSlice extracts a []string from EmbeddingFunctionConfig. Handles both []string (direct assignment) and []interface{} (JSON unmarshaling).
func HasContent ¶ added in v0.4.1
HasContent checks if a content embedding function is registered.
func HasMultimodal ¶ added in v0.3.3
HasMultimodal checks if a multimodal embedding function is registered.
func IsNeutralIntent ¶ added in v0.4.1
IsNeutralIntent reports whether the intent is one of the 5 shared neutral constants. Custom or provider-native intent strings return false.
func ListContent ¶ added in v0.4.1
func ListContent() []string
ListContent returns all registered content embedding function names.
func ListDense ¶ added in v0.3.0
func ListDense() []string
ListDense returns all registered dense embedding function names.
func ListMultimodal ¶ added in v0.3.3
func ListMultimodal() []string
ListMultimodal returns all registered multimodal embedding function names.
func ListSparse ¶ added in v0.3.0
func ListSparse() []string
ListSparse returns all registered sparse embedding function names.
func LogInsecureEnvVarWarning ¶ added in v0.3.0
func LogInsecureEnvVarWarning(providerName string)
LogInsecureEnvVarWarning logs a warning when the insecure env var is used. This helps users discover they should migrate to config-based insecure setting.
func NewValidator ¶ added in v0.3.0
NewValidator creates a validator configured to properly validate Secret fields. The validator extracts the underlying string value so `validate:"required"` works correctly.
func RegisterContent ¶ added in v0.4.1
func RegisterContent(name string, factory ContentEmbeddingFunctionFactory) error
RegisterContent registers a content embedding function factory by name. Returns an error if a factory with the same name is already registered.
func RegisterDense ¶ added in v0.3.0
func RegisterDense(name string, factory EmbeddingFunctionFactory) error
RegisterDense registers a dense embedding function factory by name. Returns an error if a factory with the same name is already registered.
func RegisterMultimodal ¶ added in v0.3.3
func RegisterMultimodal(name string, factory MultimodalEmbeddingFunctionFactory) error
RegisterMultimodal registers a multimodal embedding function factory by name. Returns an error if a factory with the same name is already registered.
func RegisterSparse ¶ added in v0.3.0
func RegisterSparse(name string, factory SparseEmbeddingFunctionFactory) error
RegisterSparse registers a sparse embedding function factory by name. Returns an error if a factory with the same name is already registered.
func ValidateContentSupport ¶ added in v0.4.1
func ValidateContentSupport(content Content, caps CapabilityMetadata) error
ValidateContentSupport checks content against declared provider capabilities. Returns on the first unsupported check, consistent with batch fail-on-first behavior. Empty capability fields are treated as undeclared and pass through without validation.
func ValidateContents ¶ added in v0.4.1
ValidateContents validates a batch of multimodal content items.
func ValidateContentsSupport ¶ added in v0.4.1
func ValidateContentsSupport(contents []Content, caps CapabilityMetadata) error
ValidateContentsSupport validates a batch of content items against declared provider capabilities. Returns on the first unsupported item, consistent with existing batch validation behavior.
Types ¶
type BinarySource ¶ added in v0.4.1
type BinarySource struct {
Kind SourceKind
URL string
FilePath string
Base64 string
Bytes []byte
MIMEType string
}
BinarySource stores a single binary input reference for non-text modalities.
func NewBinarySourceFromBase64 ¶ added in v0.4.1
func NewBinarySourceFromBase64(base64Data string) BinarySource
NewBinarySourceFromBase64 creates a base64-backed binary source without decoding it.
func NewBinarySourceFromBytes ¶ added in v0.4.1
func NewBinarySourceFromBytes(data []byte) BinarySource
NewBinarySourceFromBytes creates an in-memory binary source.
func NewBinarySourceFromFile ¶ added in v0.4.1
func NewBinarySourceFromFile(filePath string) BinarySource
NewBinarySourceFromFile creates a file-backed binary source without opening it.
func NewBinarySourceFromURL ¶ added in v0.4.1
func NewBinarySourceFromURL(url string) BinarySource
NewBinarySourceFromURL creates a URL-backed binary source without dereferencing it.
func (BinarySource) Validate ¶ added in v0.4.1
func (s BinarySource) Validate() error
Validate checks that a binary source selects exactly one payload for the declared kind.
type CapabilityAware ¶ added in v0.4.1
type CapabilityAware interface {
Capabilities() CapabilityMetadata
}
CapabilityAware exposes shared provider capability metadata without requiring callers to type-assert provider-specific concrete implementations.
type CapabilityMetadata ¶ added in v0.4.1
type CapabilityMetadata struct {
Modalities []Modality
Intents []Intent
RequestOptions []RequestOption
SupportsBatch bool
SupportsMixedPart bool
}
CapabilityMetadata describes the shared capability surface exposed by an embedding provider.
func (CapabilityMetadata) SupportsIntent ¶ added in v0.4.1
func (m CapabilityMetadata) SupportsIntent(intent Intent) bool
SupportsIntent reports whether the capability metadata includes the given intent.
func (CapabilityMetadata) SupportsModality ¶ added in v0.4.1
func (m CapabilityMetadata) SupportsModality(modality Modality) bool
SupportsModality reports whether the capability metadata includes the given modality.
func (CapabilityMetadata) SupportsRequestOption ¶ added in v0.4.1
func (m CapabilityMetadata) SupportsRequestOption(option RequestOption) bool
SupportsRequestOption reports whether the capability metadata includes the given request option.
type Closeable ¶ added in v0.3.0
type Closeable interface {
Close() error
}
Closeable is an optional interface for embedding functions that hold resources. Callers should check if an embedding function implements this interface and call Close() when done to release resources (e.g., ONNX runtime, native libraries).
type ConsistentHashEmbeddingFunction ¶
type ConsistentHashEmbeddingFunction struct {
// contains filtered or unexported fields
}
ConsistentHashEmbeddingFunction generates deterministic embeddings using SHA-256 hashing. Useful for testing and scenarios where consistent embeddings are needed for the same input.
func (*ConsistentHashEmbeddingFunction) DefaultSpace ¶ added in v0.3.0
func (e *ConsistentHashEmbeddingFunction) DefaultSpace() DistanceMetric
func (*ConsistentHashEmbeddingFunction) EmbedDocuments ¶
func (*ConsistentHashEmbeddingFunction) EmbedQuery ¶
func (*ConsistentHashEmbeddingFunction) GetConfig ¶ added in v0.3.0
func (e *ConsistentHashEmbeddingFunction) GetConfig() EmbeddingFunctionConfig
func (*ConsistentHashEmbeddingFunction) Name ¶ added in v0.3.0
func (e *ConsistentHashEmbeddingFunction) Name() string
func (*ConsistentHashEmbeddingFunction) SupportedSpaces ¶ added in v0.3.0
func (e *ConsistentHashEmbeddingFunction) SupportedSpaces() []DistanceMetric
type Content ¶ added in v0.4.1
Content is the canonical multimodal request item for one semantic unit.
In batch requests, per-item Intent, Dimension, and ProviderHints that affect embedding configuration (e.g. Gemini's "task_type") are rejected because many providers apply a single configuration to the entire batch. Use context-level overrides (e.g. ContextWithTaskType, ContextWithDimension) for batch-wide settings.
func NewAudioFile ¶ added in v0.4.1
func NewAudioFile(path string, opts ...ContentOption) Content
NewAudioFile creates a Content with a single file-backed audio part.
func NewAudioURL ¶ added in v0.4.1
func NewAudioURL(url string, opts ...ContentOption) Content
NewAudioURL creates a Content with a single URL-backed audio part.
func NewContent ¶ added in v0.4.1
func NewContent(parts []Part, opts ...ContentOption) Content
NewContent creates a Content from pre-built parts with optional configuration.
func NewImageFile ¶ added in v0.4.1
func NewImageFile(path string, opts ...ContentOption) Content
NewImageFile creates a Content with a single file-backed image part.
func NewImageURL ¶ added in v0.4.1
func NewImageURL(url string, opts ...ContentOption) Content
NewImageURL creates a Content with a single URL-backed image part.
func NewPDFFile ¶ added in v0.4.1
func NewPDFFile(path string, opts ...ContentOption) Content
NewPDFFile creates a Content with a single file-backed PDF part.
func NewPDFURL ¶ added in v0.4.1
func NewPDFURL(url string, opts ...ContentOption) Content
NewPDFURL creates a Content with a single URL-backed PDF part.
func NewTextContent ¶ added in v0.4.1
func NewTextContent(text string, opts ...ContentOption) Content
NewTextContent creates a Content with a single text part.
func NewVideoFile ¶ added in v0.4.1
func NewVideoFile(path string, opts ...ContentOption) Content
NewVideoFile creates a Content with a single file-backed video part.
func NewVideoURL ¶ added in v0.4.1
func NewVideoURL(url string, opts ...ContentOption) Content
NewVideoURL creates a Content with a single URL-backed video part.
type ContentEmbeddingFunction ¶ added in v0.4.1
type ContentEmbeddingFunction interface {
// EmbedContents returns a vector for each multimodal content item.
EmbedContents(ctx context.Context, contents []Content) ([]Embedding, error)
// EmbedContent embeds a single multimodal content item.
EmbedContent(ctx context.Context, content Content) (Embedding, error)
}
ContentEmbeddingFunction is the shared multimodal foundation for ordered mixed-part content. It is additive in this phase and does not replace the legacy image-only MultimodalEmbeddingFunction.
func AdaptEmbeddingFunctionToContent ¶ added in v0.4.1
func AdaptEmbeddingFunctionToContent(ef EmbeddingFunction, caps CapabilityMetadata) ContentEmbeddingFunction
AdaptEmbeddingFunctionToContent bridges a legacy text-only embedding function into the shared content interface.
func AdaptMultimodalEmbeddingFunctionToContent ¶ added in v0.4.1
func AdaptMultimodalEmbeddingFunctionToContent(ef MultimodalEmbeddingFunction, caps CapabilityMetadata) ContentEmbeddingFunction
AdaptMultimodalEmbeddingFunctionToContent bridges a legacy text/image embedding function into the shared content interface.
func BuildContent ¶ added in v0.4.1
func BuildContent(name string, config EmbeddingFunctionConfig) (ContentEmbeddingFunction, error)
BuildContent creates a ContentEmbeddingFunction from name and config. Falls back from native content factory to multimodal+adapt to dense+adapt when a native content factory is not registered.
func BuildContentCloseable ¶ added in v0.4.1
func BuildContentCloseable(name string, config EmbeddingFunctionConfig) (ContentEmbeddingFunction, func() error, error)
BuildContentCloseable creates a ContentEmbeddingFunction and returns a closer function. The closer handles cleanup for embedding functions that implement Closeable. If the embedding function does not implement Closeable, the closer is a no-op.
type ContentEmbeddingFunctionFactory ¶ added in v0.4.1
type ContentEmbeddingFunctionFactory func(config EmbeddingFunctionConfig) (ContentEmbeddingFunction, error)
ContentEmbeddingFunctionFactory creates a ContentEmbeddingFunction from config.
type ContentOption ¶ added in v0.4.1
type ContentOption func(*Content)
ContentOption configures optional fields on a Content value built by convenience constructors.
func WithDimension ¶ added in v0.4.1
func WithDimension(dim int) ContentOption
WithDimension sets the target output dimensionality on the constructed Content.
func WithIntent ¶ added in v0.4.1
func WithIntent(intent Intent) ContentOption
WithIntent sets the provider-neutral intent on the constructed Content.
func WithProviderHints ¶ added in v0.4.1
func WithProviderHints(hints map[string]any) ContentOption
WithProviderHints sets provider-specific hints on the constructed Content.
type DistanceMetric ¶
type DistanceMetric string
const ( L2 DistanceMetric = "l2" COSINE DistanceMetric = "cosine" IP DistanceMetric = "ip" )
type DistanceMetricOperator ¶
type Embedding ¶
type Embedding interface {
Len() int
ContentAsFloat32() []float32
ContentAsInt32() []int32
FromFloat32(content ...float32) error
Compare(other Embedding, metric DistanceMetricOperator) float32
IsDefined() bool
}
Embedding represents a vector embedding that can be either float32 or int32 based. Implementations include Float32Embedding and Int32Embedding.
func NewEmbeddingFromFloat32 ¶
NewEmbeddingFromFloat32 creates a new Float32Embedding from a slice of float32 values.
func NewEmbeddingFromFloat64 ¶
NewEmbeddingFromFloat64 creates a Float32Embedding by converting float64 values to float32.
func NewEmbeddingFromInt32 ¶
NewEmbeddingFromInt32 creates a Float32Embedding by converting int32 values to float32.
func NewEmbeddingsFromFloat32 ¶
NewEmbeddingsFromFloat32 creates a slice of embeddings from a 2D slice of float32 values.
func NewEmbeddingsFromInt32 ¶
NewEmbeddingsFromInt32 creates a slice of Int32Embedding from a 2D slice of int32 values.
func NewEmbeddingsFromInterface ¶
NewEmbeddingsFromInterface parses embeddings from a slice of interface{} values, typically used when unmarshaling JSON responses from embedding APIs.
func NewEmptyEmbedding ¶
func NewEmptyEmbedding() Embedding
NewEmptyEmbedding creates an undefined embedding with no data.
func NewEmptyEmbeddings ¶
func NewEmptyEmbeddings() []Embedding
NewEmptyEmbeddings creates an empty slice of embeddings.
func NewInt32Embedding ¶
NewInt32Embedding creates a new Int32Embedding from a slice of int32 values.
type EmbeddingFunction ¶
type EmbeddingFunction interface {
// EmbedDocuments returns a vector for each text.
EmbedDocuments(ctx context.Context, texts []string) ([]Embedding, error)
// EmbedQuery embeds a single text.
EmbedQuery(ctx context.Context, text string) (Embedding, error)
// Name returns the static identifier for this embedding function (e.g., "openai", "cohere").
Name() string
// GetConfig returns the current configuration as a serializable map.
GetConfig() EmbeddingFunctionConfig
// DefaultSpace returns the recommended distance metric for this embedding function.
DefaultSpace() DistanceMetric
// SupportedSpaces returns all distance metrics supported by this embedding function.
SupportedSpaces() []DistanceMetric
}
func BuildDense ¶ added in v0.3.0
func BuildDense(name string, config EmbeddingFunctionConfig) (EmbeddingFunction, error)
BuildDense creates a dense EmbeddingFunction from name and config.
func BuildDenseCloseable ¶ added in v0.3.0
func BuildDenseCloseable(name string, config EmbeddingFunctionConfig) (EmbeddingFunction, func() error, error)
BuildDenseCloseable creates a dense EmbeddingFunction and returns a closer function. The closer handles cleanup for embedding functions that implement Closeable. If the embedding function does not implement Closeable, the closer is a no-op.
func NewConsistentHashEmbeddingFunction ¶
func NewConsistentHashEmbeddingFunction() EmbeddingFunction
NewConsistentHashEmbeddingFunction creates a ConsistentHashEmbeddingFunction with default dimension (384).
func NewConsistentHashEmbeddingFunctionFromConfig ¶ added in v0.3.0
func NewConsistentHashEmbeddingFunctionFromConfig(cfg EmbeddingFunctionConfig) (EmbeddingFunction, error)
NewConsistentHashEmbeddingFunctionFromConfig creates a ConsistentHashEmbeddingFunction from config
type EmbeddingFunctionConfig ¶ added in v0.3.0
type EmbeddingFunctionConfig map[string]interface{}
EmbeddingFunctionConfig represents serializable configuration for an embedding function. Used for cross-language compatibility and config persistence.
type EmbeddingFunctionFactory ¶ added in v0.3.0
type EmbeddingFunctionFactory func(config EmbeddingFunctionConfig) (EmbeddingFunction, error)
EmbeddingFunctionFactory creates an EmbeddingFunction from config.
type EmbeddingFunctionUnwrapper ¶ added in v0.4.1
type EmbeddingFunctionUnwrapper interface {
UnwrapEmbeddingFunction() EmbeddingFunction
}
EmbeddingFunctionUnwrapper is implemented by adapters that wrap an EmbeddingFunction.
type EmbeddingModel ¶
type EmbeddingModel string
EmbeddingModel represents the name/identifier of an embedding model.
type Float32Embedding ¶
type Float32Embedding struct {
ArrayOfFloat32 *[]float32
}
Float32Embedding implements Embedding using float32 values. This is the most common embedding type for dense vectors.
func (*Float32Embedding) Compare ¶
func (e *Float32Embedding) Compare(other Embedding, metric DistanceMetricOperator) float32
func (*Float32Embedding) ContentAsFloat32 ¶
func (e *Float32Embedding) ContentAsFloat32() []float32
func (*Float32Embedding) ContentAsInt32 ¶
func (e *Float32Embedding) ContentAsInt32() []int32
func (*Float32Embedding) FromFloat32 ¶
func (e *Float32Embedding) FromFloat32(content ...float32) error
func (*Float32Embedding) IsDefined ¶
func (e *Float32Embedding) IsDefined() bool
func (*Float32Embedding) Len ¶
func (e *Float32Embedding) Len() int
func (*Float32Embedding) MarshalJSON ¶
func (e *Float32Embedding) MarshalJSON() ([]byte, error)
func (*Float32Embedding) UnmarshalJSON ¶
func (e *Float32Embedding) UnmarshalJSON(b []byte) error
type ImageInput ¶ added in v0.3.3
ImageInput represents an image that can be embedded. Exactly one of Base64, URL, or FilePath must be set.
func NewImageInputFromBase64 ¶ added in v0.3.3
func NewImageInputFromBase64(base64Data string) ImageInput
NewImageInputFromBase64 creates an ImageInput from a base64-encoded string.
func NewImageInputFromFile ¶ added in v0.3.3
func NewImageInputFromFile(filePath string) ImageInput
NewImageInputFromFile creates an ImageInput from a local file path.
func NewImageInputFromURL ¶ added in v0.3.3
func NewImageInputFromURL(url string) ImageInput
NewImageInputFromURL creates an ImageInput from a URL.
func (ImageInput) ToBase64 ¶ added in v0.3.3
func (i ImageInput) ToBase64(_ context.Context) (string, error)
ToBase64 converts the image input to a base64-encoded string. For Base64 inputs, returns the value directly. For URL inputs, returns an error (URLs should be passed directly to the API). For FilePath inputs, reads the file and encodes it.
func (ImageInput) Type ¶ added in v0.3.3
func (i ImageInput) Type() ImageInputType
Type returns the type of the image input based on which field is set.
func (ImageInput) Validate ¶ added in v0.3.3
func (i ImageInput) Validate() error
Validate checks that exactly one input source is specified.
type ImageInputType ¶ added in v0.3.3
type ImageInputType string
ImageInputType represents the type of image input.
const ( ImageInputTypeBase64 ImageInputType = "base64" ImageInputTypeURL ImageInputType = "url" ImageInputTypeFilePath ImageInputType = "file" )
type Int32Embedding ¶
type Int32Embedding struct {
ArrayOfInt32 *[]int32
}
Int32Embedding implements Embedding using int32 values. Used for quantized embeddings to reduce memory usage.
func (*Int32Embedding) Compare ¶
func (e *Int32Embedding) Compare(other Embedding, metric DistanceMetricOperator) float32
func (*Int32Embedding) ContentAsFloat32 ¶
func (e *Int32Embedding) ContentAsFloat32() []float32
func (*Int32Embedding) ContentAsInt32 ¶
func (e *Int32Embedding) ContentAsInt32() []int32
func (*Int32Embedding) FromFloat32 ¶
func (e *Int32Embedding) FromFloat32(_ ...float32) error
func (*Int32Embedding) FromInt32 ¶
func (e *Int32Embedding) FromInt32(content ...int32) error
func (*Int32Embedding) IsDefined ¶
func (e *Int32Embedding) IsDefined() bool
func (*Int32Embedding) Len ¶
func (e *Int32Embedding) Len() int
func (*Int32Embedding) MarshalJSON ¶
func (e *Int32Embedding) MarshalJSON() ([]byte, error)
func (*Int32Embedding) UnmarshalJSON ¶
func (e *Int32Embedding) UnmarshalJSON(b []byte) error
type Intent ¶ added in v0.4.1
type Intent string
Intent describes the provider-neutral purpose of a multimodal request.
type IntentMapper ¶ added in v0.4.1
IntentMapper is implemented by providers that translate neutral intents to provider-native strings. Callers check for this interface via type assertion before calling MapIntent. When a provider does not implement IntentMapper, the intent string is passed through as-is.
type KnnVector ¶ added in v0.3.0
KnnVector represents a vector that can be used for k-nearest neighbor search.
type Modality ¶ added in v0.4.1
type Modality string
Modality identifies the content type for one multimodal part.
type MultimodalEmbeddingFunction ¶ added in v0.3.3
type MultimodalEmbeddingFunction interface {
EmbeddingFunction
// EmbedImages returns embeddings for a batch of images.
EmbedImages(ctx context.Context, images []ImageInput) ([]Embedding, error)
// EmbedImage returns an embedding for a single image.
EmbedImage(ctx context.Context, image ImageInput) (Embedding, error)
}
MultimodalEmbeddingFunction extends EmbeddingFunction with image embedding capabilities.
func BuildMultimodal ¶ added in v0.3.3
func BuildMultimodal(name string, config EmbeddingFunctionConfig) (MultimodalEmbeddingFunction, error)
BuildMultimodal creates a MultimodalEmbeddingFunction from name and config.
func BuildMultimodalCloseable ¶ added in v0.3.3
func BuildMultimodalCloseable(name string, config EmbeddingFunctionConfig) (MultimodalEmbeddingFunction, func() error, error)
BuildMultimodalCloseable creates a MultimodalEmbeddingFunction and returns a closer function. The closer handles cleanup for embedding functions that implement Closeable. If the embedding function does not implement Closeable, the closer is a no-op.
type MultimodalEmbeddingFunctionFactory ¶ added in v0.3.3
type MultimodalEmbeddingFunctionFactory func(config EmbeddingFunctionConfig) (MultimodalEmbeddingFunction, error)
MultimodalEmbeddingFunctionFactory creates a MultimodalEmbeddingFunction from config.
type Part ¶ added in v0.4.1
type Part struct {
Modality Modality
Text string
Source *BinarySource
}
Part is one ordered multimodal unit inside a content request.
func NewImagePartFromImageInput ¶ added in v0.4.1
func NewImagePartFromImageInput(input ImageInput) (Part, error)
NewImagePartFromImageInput bridges the legacy image-only input into the shared part model.
func NewPartFromSource ¶ added in v0.4.1
func NewPartFromSource(modality Modality, source BinarySource) Part
NewPartFromSource creates a non-text multimodal part from a binary source.
func NewTextPart ¶ added in v0.4.1
NewTextPart creates a text part for the shared multimodal contract.
type RequestOption ¶ added in v0.4.1
type RequestOption string
RequestOption identifies a shared request-time option that a provider can support.
const ( // RequestOptionDimension indicates support for caller-provided output dimensions. RequestOptionDimension RequestOption = "dimension" // RequestOptionProviderHints indicates support for provider-specific request hints. RequestOptionProviderHints RequestOption = "provider_hints" )
type Secret ¶ added in v0.3.0
type Secret struct {
// contains filtered or unexported fields
}
Secret is a string type that prevents accidental logging of sensitive values. It implements fmt.Stringer, fmt.GoStringer, fmt.Formatter, json.Marshaler, and slog.LogValuer to mask the value in all common output scenarios.
func (Secret) Format ¶ added in v0.3.0
Format implements fmt.Formatter for complete control over all format verbs.
func (Secret) LogValue ¶ added in v0.3.0
LogValue implements slog.LogValuer for structured logging protection.
func (Secret) MarshalJSON ¶ added in v0.3.0
MarshalJSON implements json.Marshaler, returning a redacted placeholder.
func (Secret) String ¶ added in v0.3.0
String implements fmt.Stringer, returning a redacted placeholder.
func (*Secret) UnmarshalJSON ¶ added in v0.3.0
UnmarshalJSON implements json.Unmarshaler. It returns an error to enforce the use of environment variables for secrets. Secrets should be passed via api_key_env_var configuration, not directly in JSON.
type SourceKind ¶ added in v0.4.1
type SourceKind string
SourceKind identifies how a binary multimodal input is provided.
const ( SourceKindURL SourceKind = "url" SourceKindFile SourceKind = "file" SourceKindBase64 SourceKind = "base64" SourceKindBytes SourceKind = "bytes" )
type SparseEmbeddingFunction ¶ added in v0.3.0
type SparseEmbeddingFunction interface {
// EmbedDocumentsSparse returns a sparse vector for each text.
EmbedDocumentsSparse(ctx context.Context, texts []string) ([]*SparseVector, error)
// EmbedQuerySparse embeds a single text as a sparse vector.
EmbedQuerySparse(ctx context.Context, text string) (*SparseVector, error)
// Name returns the static identifier for this sparse embedding function (e.g., "bm25", "splade").
Name() string
// GetConfig returns the current configuration as a serializable map.
GetConfig() EmbeddingFunctionConfig
}
func BuildSparse ¶ added in v0.3.0
func BuildSparse(name string, config EmbeddingFunctionConfig) (SparseEmbeddingFunction, error)
BuildSparse creates a SparseEmbeddingFunction from name and config.
func BuildSparseCloseable ¶ added in v0.3.0
func BuildSparseCloseable(name string, config EmbeddingFunctionConfig) (SparseEmbeddingFunction, func() error, error)
BuildSparseCloseable creates a SparseEmbeddingFunction and returns a closer function. The closer handles cleanup for embedding functions that implement Closeable. If the embedding function does not implement Closeable, the closer is a no-op.
type SparseEmbeddingFunctionFactory ¶ added in v0.3.0
type SparseEmbeddingFunctionFactory func(config EmbeddingFunctionConfig) (SparseEmbeddingFunction, error)
SparseEmbeddingFunctionFactory creates a SparseEmbeddingFunction from config.
type SparseVector ¶ added in v0.3.0
type SparseVector struct {
Indices []int `json:"indices"`
Values []float32 `json:"values"`
Labels []string `json:"labels,omitempty"`
}
SparseVector represents a sparse embedding vector
func NewSparseVector ¶ added in v0.3.0
func NewSparseVector(indices []int, values []float32) (*SparseVector, error)
NewSparseVector creates a new sparse vector. Returns an error if:
- indices and values have different lengths
- any index is negative
- any index is duplicated
- any value is NaN or infinite
func (*SparseVector) Len ¶ added in v0.3.0
func (s *SparseVector) Len() int
Len returns the number of non-zero elements
func (*SparseVector) MarshalJSON ¶ added in v0.3.0
func (s *SparseVector) MarshalJSON() ([]byte, error)
MarshalJSON implements JSON marshaling for sparse vectors
func (*SparseVector) Validate ¶ added in v0.3.0
func (s *SparseVector) Validate() error
Validate checks that the sparse vector is valid. A valid sparse vector has:
- matching lengths for indices and values
- all indices are non-negative
- no duplicate indices
- no NaN or infinite values
func (*SparseVector) ValuesAsFloat32 ¶ added in v0.3.0
func (s *SparseVector) ValuesAsFloat32() []float32
ValuesAsFloat32 returns the non-zero values
type ValidationError ¶ added in v0.4.1
type ValidationError struct {
Issues []ValidationIssue
}
ValidationError collects one or more multimodal validation issues.
func (*ValidationError) Error ¶ added in v0.4.1
func (e *ValidationError) Error() string
Error implements error.
type ValidationIssue ¶ added in v0.4.1
ValidationIssue describes one structural multimodal validation failure.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package defaultef exposes the legacy default ONNX embedding function package path.
|
Package defaultef exposes the legacy default ONNX embedding function package path. |
|
Package ort exposes the canonical ONNX runtime embedding function package path.
|
Package ort exposes the canonical ONNX runtime embedding function package path. |
|
Package roboflow provides a Roboflow CLIP embedding function for text and images.
|
Package roboflow provides a Roboflow CLIP embedding function for text and images. |