Documentation ¶
Overview ¶
Package embeddings contains the implementation for creating vector embeddings from text using different APIs, like OpenAI and Google PaLM (VertexAI).
The main components of this package are:
- Embedder interface: a common interface for creating vector embeddings from texts. - OpenAI: an Embedder implementation using the OpenAI API. - VertexAIPaLM: an Embedder implementation using Google PaLM (VertexAI) API. - Helper functions: utility functions for embedding, such as `batchTexts` and `maybeRemoveNewLines`.
The package provides a flexible way to handle different APIs for generating embeddings by using the Embedder interface as an abstraction.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrVectorsNotSameSize is returned if the vectors returned from the // embeddings api have different sizes. ErrVectorsNotSameSize = errors.New("vectors gotten not the same size") // ErrAllTextsLenZero is returned if all texts to be embedded has the combined // length of zero. ErrAllTextsLenZero = errors.New("all texts have length 0") )
Functions ¶
func BatchTexts ¶
BatchTexts splits strings by the length batchSize.
func MaybeRemoveNewLines ¶
Types ¶
type Embedder ¶
type Embedder interface { // EmbedDocuments returns a vector for each text. EmbedDocuments(ctx context.Context, texts []string) ([][]float64, error) // EmbedQuery embeds a single text. EmbedQuery(ctx context.Context, text string) ([]float64, error) }
Embedder is the interface for creating vector embeddings from texts.