embedding

package
v0.0.0-...-ab17b8d Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2024 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Package embedding provides the embedding provider management functionalities

Package embedding provides the embedding provider interface and its implementations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EmbeddingProviderMock

type EmbeddingProviderMock struct {
	mock.Mock
}

func NewProvider

func NewProvider(t interface {
	mock.TestingT
	Cleanup(func())
}) *EmbeddingProviderMock

func (*EmbeddingProviderMock) GetEmbedding

func (_m *EmbeddingProviderMock) GetEmbedding(ctx context.Context, text string) ([]types.ContentPart, error)

func (*EmbeddingProviderMock) GetID

func (_m *EmbeddingProviderMock) GetID() uuid.UUID

func (*EmbeddingProviderMock) HealthCheck

func (_m *EmbeddingProviderMock) HealthCheck() error

func (*EmbeddingProviderMock) Process

type Manager

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

Manager is the embedding provider manager

func NewEmbeddingManager

func NewEmbeddingManager(s storage.Storage, l *logrus.Logger, aclManager auth.ACLManager) *Manager

NewEmbeddingManager creates a new embedding manager

func (*Manager) RegisterRoutes

func (h *Manager) RegisterRoutes(r chi.Router)

RegisterRoutes registers the embedding provider routes

type NoOpEmbeddingProvider

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

Provider is an interface for an embedding provider

func (*NoOpEmbeddingProvider) GetEmbedding

func (n *NoOpEmbeddingProvider) GetEmbedding(_ context.Context, _ string) ([]types.ContentPart, error)

GetEmbedding returns the embedding for the given text

func (*NoOpEmbeddingProvider) GetID

func (n *NoOpEmbeddingProvider) GetID() uuid.UUID

GetID returns the ID of the embedding provider

func (*NoOpEmbeddingProvider) HealthCheck

func (n *NoOpEmbeddingProvider) HealthCheck() error

HealthCheck checks the health of the embedding provider

func (*NoOpEmbeddingProvider) Process

Process processes the given document

type OpenAIProvider

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

OpenAIProvider is an embedding provider that uses OpenAI to generate embeddings

func (*OpenAIProvider) GetEmbedding

func (p *OpenAIProvider) GetEmbedding(ctx context.Context, text string) ([]types.ContentPart, error)

GetEmbedding returns the embedding for the given text

func (*OpenAIProvider) GetID

func (p *OpenAIProvider) GetID() uuid.UUID

GetID returns the ID of the embedding provider

func (*OpenAIProvider) HealthCheck

func (p *OpenAIProvider) HealthCheck() error

HealthCheck checks the health of the embedding provider

func (*OpenAIProvider) Process

func (p *OpenAIProvider) Process(ctx context.Context, d *types.Document) error

Process processes the document by generating an embedding for the document body

type OpenAIRequest

type OpenAIRequest struct {
	Input string `json:"input"`
	Model string `json:"model"`
}

OpenAIRequest is a request to the OpenAI API

type OpenAIResponse

type OpenAIResponse struct {
	Object string `json:"object"`
	Data   []struct {
		Object    string    `json:"object"`
		Index     int       `json:"index"`
		Embedding []float32 `json:"embedding"`
	} `json:"data"`
	Model string `json:"model"`
	Usage struct {
		PromptTokens int32 `json:"prompt_tokens"`
		TotalTokens  int32 `json:"total_tokens"`
	} `json:"usage"`
}

OpenAIResponse is a response from the OpenAI API

type Provider

type Provider interface {
	GetEmbedding(ctx context.Context, text string) ([]types.ContentPart, error)
	Process(ctx context.Context, d *types.Document) error
	GetID() uuid.UUID
	HealthCheck() error
}

Provider is an interface for an embedding provider

func InitializeEmbeddingProvider

func InitializeEmbeddingProvider(ctx context.Context, st storage.Storage, logging *logrus.Logger) (Provider, error)

InitializeEmbeddingProvider initializes the embedding provider with the given storage and logger

func NewNoOpEmbeddingProvider

func NewNoOpEmbeddingProvider(settings *types.NoOpSettings) Provider

NewNoOpEmbeddingProvider creates a new NoOpEmbeddingProvider with the given settings

func NewOpenAIProvider

func NewOpenAIProvider(providerUUID uuid.UUID, settings *types.OpenAISettings, logging *logrus.Logger) Provider

NewOpenAIProvider creates a new OpenAIProvider with the given settings

Jump to

Keyboard shortcuts

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