embedding

package
v0.0.88 Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2023 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Package embedding contains the implementation to create vector embeddings from text using different APIs

Index

Constants

This section is empty.

Variables

View Source
var DefaultOpenAIConfig = OpenAIOptions{
	ModelName:              "text-embedding-ada-002",
	EmbeddingContextLength: 8191,
	ChunkSize:              1000,
	MaxRetries:             3,
}

Functions

This section is empty.

Types

type AzureOpenAIOptions added in v0.0.26

type AzureOpenAIOptions struct {
	OpenAIOptions
	APIVersion string
	Deployment string
}

type Bedrock added in v0.0.73

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

Bedrock is a struct representing the Bedrock model embedding functionality.

func NewBedrock added in v0.0.73

func NewBedrock(client BedrockRuntimeClient, optFns ...func(o *BedrockOptions)) *Bedrock

NewBedrock creates a new instance of Bedrock with the provided BedrockRuntimeClient and optional configuration.

func (*Bedrock) EmbedDocuments added in v0.0.73

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

EmbedDocuments embeds a list of documents and returns their embeddings.

func (*Bedrock) EmbedQuery added in v0.0.73

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

EmbedQuery embeds a single query and returns its embedding.

type BedrockOptions added in v0.0.73

type BedrockOptions struct {
	*schema.CallbackOptions `map:"-"`
	schema.Tokenizer        `map:"-"`

	// Model id to use.
	ModelID string `map:"model_id,omitempty"`

	// Model params to use.
	ModelParams map[string]any `map:"model_params,omitempty"`
}

BedrockOptions contains options for configuring the Bedrock model.

type BedrockRuntimeClient added in v0.0.73

type BedrockRuntimeClient interface {
	InvokeModel(ctx context.Context, params *bedrockruntime.InvokeModelInput, optFns ...func(*bedrockruntime.Options)) (*bedrockruntime.InvokeModelOutput, error)
}

BedrockRuntimeClient is an interface for the Bedrock model runtime client.

type Cohere added in v0.0.39

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

Cohere is a client for the Cohere API.

func NewCohere added in v0.0.39

func NewCohere(apiKey string, optFns ...func(o *CohereOptions)) (*Cohere, error)

NewCohere creates a new Cohere instance with the provided API key and options. It returns the initialized Cohere instance or an error if initialization fails.

func NewCohereFromClient added in v0.0.39

func NewCohereFromClient(client CohereClient, optFns ...func(o *CohereOptions)) (*Cohere, error)

NewCohereFromClient creates a new Cohere instance from an existing Cohere client and options. It returns the initialized Cohere instance.

func (*Cohere) EmbedDocuments added in v0.0.39

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

EmbedDocuments embeds a list of documents and returns their embeddings.

func (*Cohere) EmbedQuery added in v0.0.39

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

EmbedQuery embeds a single query and returns its embedding.

type CohereClient added in v0.0.39

type CohereClient interface {
	Embed(opts cohere.EmbedOptions) (*cohere.EmbedResponse, error)
}

CohereClient is an interface for the Cohere client.

type CohereOptions added in v0.0.39

type CohereOptions struct {
	// Model name to use.
	Model string
	// Truncate embeddings that are too long from start or end ("NONE"|"START"|"END")
	Truncate string
	// MaxRetries represents the maximum number of retries to make when embedding.
	MaxRetries uint `map:"max_retries,omitempty"`
}

CohereOptions contains options for configuring the Cohere instance.

type Ernie added in v0.0.67

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

Ernie represents the text embedding component powered by Ernie.

func NewErnie added in v0.0.67

func NewErnie(clientID, clientSecret string, optFns ...func(o *ErnieOptions)) *Ernie

NewErnie creates a new instance of the Ernie text embedding component with default options.

func NewErnieFromClient added in v0.0.67

func NewErnieFromClient(client ErnieClient, optFns ...func(o *ErnieOptions)) *Ernie

NewErnieFromClient creates a new instance of the Ernie text embedding component with a custom ErnieClient and optional configuration.

func (*Ernie) EmbedDocuments added in v0.0.67

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

EmbedDocuments embeds a list of documents and returns their embeddings.

func (*Ernie) EmbedQuery added in v0.0.67

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

EmbedQuery embeds a single query and returns its embedding.

type ErnieClient added in v0.0.67

type ErnieClient interface {
	// CreateEmbedding generates text embeddings using the specified model and request.
	CreateEmbedding(ctx context.Context, model string, request ernie.EmbeddingRequest) (*ernie.EmbeddingResponse, error)
}

ErnieClient is an interface for interacting with the Ernie API for text embedding.

type ErnieOptions added in v0.0.67

type ErnieOptions struct {
	Model string
}

ErnieOptions represents configuration options for the Ernie text embedding component.

type Fake

type Fake struct {
	Size int
}

func NewFake

func NewFake(size int) *Fake

func (*Fake) EmbedDocuments

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

EmbedDocuments embeds a list of documents and returns their embeddings.

func (*Fake) EmbedQuery

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

EmbedQuery embeds a single query and returns its embedding.

type HuggingFaceHub added in v0.0.66

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

HuggingFaceHub represents an embedder for Hugging Face Hub models.

func NewHuggingFaceHub added in v0.0.66

func NewHuggingFaceHub(token string, optFns ...func(o *HuggingFaceHubOptions)) *HuggingFaceHub

NewHuggingFaceHub creates a new instance of the HuggingFaceHub embedder.

func NewHuggingFaceHubFromClient added in v0.0.66

func NewHuggingFaceHubFromClient(client HuggingFaceHubClient, optFns ...func(o *HuggingFaceHubOptions)) *HuggingFaceHub

NewHuggingFaceHubFromClient creates a new instance of the HuggingFaceHub embedder from a custom client.

func (*HuggingFaceHub) EmbedDocuments added in v0.0.66

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

EmbedDocuments embeds a list of documents and returns their embeddings.

func (*HuggingFaceHub) EmbedQuery added in v0.0.66

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

EmbedQuery embeds a single query and returns its embedding.

type HuggingFaceHubClient added in v0.0.66

type HuggingFaceHubClient interface {
	// FeatureExtractionWithAutomaticReduction performs feature extraction with automatic reduction.
	// It returns the extraction response or an error if the operation fails.
	FeatureExtractionWithAutomaticReduction(ctx context.Context, req *huggingface.FeatureExtractionRequest) (huggingface.FeatureExtractionWithAutomaticReductionResponse, error)
}

HuggingFaceHubClient represents a client for interacting with Hugging Face Hub.

type HuggingFaceHubOptions added in v0.0.66

type HuggingFaceHubOptions struct {
	// Model to use for embedding.
	Model string
	// Options represents optional settings for the feature extraction.
	Options huggingface.Options
}

type OpenAI added in v0.0.6

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

func NewAzureOpenAI added in v0.0.26

func NewAzureOpenAI(apiKey, baseURL string, optFns ...func(o *AzureOpenAIOptions)) (*OpenAI, error)

func NewOpenAI added in v0.0.6

func NewOpenAI(apiKey string, optFns ...func(o *OpenAIOptions)) (*OpenAI, error)

func NewOpenAIFromClient added in v0.0.38

func NewOpenAIFromClient(client OpenAIClient, optFns ...func(o *OpenAIOptions)) (*OpenAI, error)

func (*OpenAI) EmbedDocuments added in v0.0.6

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

EmbedDocuments embeds a list of documents and returns their embeddings.

func (*OpenAI) EmbedQuery added in v0.0.6

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

EmbedQuery embeds a single query and returns its embedding.

type OpenAIClient added in v0.0.68

type OpenAIClient interface {
	CreateEmbeddings(ctx context.Context, conv openai.EmbeddingRequestConverter) (res openai.EmbeddingResponse, err error)
}

type OpenAIOptions added in v0.0.6

type OpenAIOptions struct {
	// Model name to use.
	ModelName              string
	EmbeddingContextLength int
	// Maximum number of texts to embed in each batch
	ChunkSize int
	// BaseURL is the base URL of the OpenAI service.
	BaseURL string
	// OrgID is the organization ID for accessing the OpenAI service.
	OrgID string
	// MaxRetries represents the maximum number of retries to make when embedding.
	MaxRetries uint `map:"max_retries,omitempty"`
}

type Palm added in v0.0.38

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

Palm is a client for the Palm embedding service.

func NewPalm added in v0.0.38

func NewPalm(client PalmClient, optFns ...func(o *PalmOptions)) *Palm

NewPalm creates a new instance of the Palm client.

func (*Palm) EmbedDocuments added in v0.0.38

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

EmbedDocuments embeds a list of documents and returns their embeddings.

func (*Palm) EmbedQuery added in v0.0.38

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

EmbedQuery embeds a single query and returns its embedding.

type PalmClient added in v0.0.38

type PalmClient interface {
	EmbedText(context.Context, *generativelanguagepb.EmbedTextRequest, ...gax.CallOption) (*generativelanguagepb.EmbedTextResponse, error)
}

PalmClient is an interface for the Palm client.

type PalmOptions added in v0.0.38

type PalmOptions struct {
	ModelName string
}

PalmOptions contains options for configuring the Palm client.

Jump to

Keyboard shortcuts

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