storage

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: 22 Imported by: 0

Documentation

Overview

Package storage provides a storage system for the application.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewPostgresDB

func NewPostgresDB(cfg PostgresConfig) (*sql.DB, error)

NewPostgresDB creates a new Postgres database connection

Types

type DatasourceConfig

type DatasourceConfig struct {
	UUID       string                 `json:"uuid"`
	Name       string                 `json:"name"`
	SourceType string                 `json:"source_type"`
	Settings   map[string]interface{} `json:"settings"`
	Status     string                 `json:"status"`
	State      types.State            `json:"state"`
}

type Postgres

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

Postgres is a storage system that uses a Postgres database

func (*Postgres) AddConversation

func (p *Postgres) AddConversation(ctx context.Context, interactionUUID uuid.UUID, role string, message string) (types.Conversation, error)

AddConversation store a new conversation in the database

func (*Postgres) AddConversationTx

func (p *Postgres) AddConversationTx(ctx context.Context, tx *sql.Tx, interactionUUID string, conversation types.Conversation) (types.Conversation, error)

AddConversationTx adds a new conversation to the database using the provided transaction

func (*Postgres) AddDatasource

func (p *Postgres) AddDatasource(ctx context.Context, dsConfig types.DatasourceConfig) error

AddDatasource adds a new datasource to the database

func (*Postgres) CreateEmbeddingProvider

func (p *Postgres) CreateEmbeddingProvider(ctx context.Context, provider types.EmbeddingProviderConfig) error

CreateEmbeddingProvider creates a new embedding provider in the database

func (*Postgres) CreateInteraction

func (p *Postgres) CreateInteraction(ctx context.Context, interaction types.Interaction) (types.Interaction, error)

CreateInteraction creates a new interaction in the database

func (*Postgres) CreateLLMProvider

func (p *Postgres) CreateLLMProvider(ctx context.Context, provider types.LLMProviderConfig) error

CreateLLMProvider creates a new LLM provider in the database

func (*Postgres) CreateUser

func (p *Postgres) CreateUser(ctx context.Context, user *types.User) error

func (*Postgres) DeleteDatasource

func (p *Postgres) DeleteDatasource(ctx context.Context, uuid uuid.UUID) error

DeleteDatasource deletes a datasource from the database

func (*Postgres) DeleteEmbeddingProvider

func (p *Postgres) DeleteEmbeddingProvider(ctx context.Context, id uuid.UUID) error

DeleteEmbeddingProvider deletes an embedding provider from the database

func (*Postgres) DeleteLLMProvider

func (p *Postgres) DeleteLLMProvider(ctx context.Context, uuid uuid.UUID) error

DeleteLLMProvider deletes an LLM provider from the database

func (*Postgres) Get

Get the document from the database

func (*Postgres) GetAllDatasources

func (p *Postgres) GetAllDatasources(ctx context.Context, page, perPage int) (*types.PaginatedDatasources, error)

GetAllDatasources retrieves all datasources from the database

func (*Postgres) GetAllEmbeddingProviders

GetAllEmbeddingProviders retrieves all embedding providers from the database

func (*Postgres) GetAllInteractions

func (p *Postgres) GetAllInteractions(ctx context.Context, page, perPage int) (*types.PaginatedInteractions, error)

GetAllInteractions retrieves all interactions from the database

func (*Postgres) GetAllLLMProviders

GetAllLLMProviders retrieves all LLM providers from the database

func (*Postgres) GetAnalyticsOverview

func (p *Postgres) GetAnalyticsOverview(ctx context.Context) (types.AnalyticsOverview, error)

GetAnalyticsOverview retrieves an overview of analytics data from the database

func (*Postgres) GetConversation

func (p *Postgres) GetConversation(ctx context.Context, interactionUUID uuid.UUID) ([]types.Conversation, error)

GetConversation retrieves all conversations for an interaction from the database

func (*Postgres) GetDatasource

func (p *Postgres) GetDatasource(ctx context.Context, uuid uuid.UUID) (types.DatasourceConfig, error)

GetDatasource retrieves a datasource from the database

func (*Postgres) GetEmbeddingProvider

func (p *Postgres) GetEmbeddingProvider(ctx context.Context, id uuid.UUID) (*types.EmbeddingProviderConfig, error)

GetEmbeddingProvider retrieves an embedding provider from the database

func (*Postgres) GetForProcessing

func (p *Postgres) GetForProcessing(ctx context.Context, _ types.DocumentFilter, batchLimit int) ([]uuid.UUID, error)

GetForProcessing retrieves documents for processing

func (*Postgres) GetInteraction

func (p *Postgres) GetInteraction(ctx context.Context, uuid uuid.UUID) (types.Interaction, error)

GetInteraction retrieves an interaction from the database

func (*Postgres) GetKeyPair

func (p *Postgres) GetKeyPair() (privateKey, publicKey []byte, err error)

func (*Postgres) GetLLMProvider

func (p *Postgres) GetLLMProvider(ctx context.Context, uuid uuid.UUID) (*types.LLMProviderConfig, error)

GetLLMProvider retrieves an LLM provider from the database

func (*Postgres) GetPaginatedUsers

func (p *Postgres) GetPaginatedUsers(ctx context.Context, filter types.UserFilter, option types.UserFilterOption) (types.PaginatedUsers, error)

func (*Postgres) GetSettings

func (p *Postgres) GetSettings(ctx context.Context) (types.Settings, error)

GetSettings retrieves the application settings from the database

func (*Postgres) GetUser

func (p *Postgres) GetUser(ctx context.Context, uuid uuid.UUID) (*types.User, error)

func (*Postgres) HandleShutdown

func (p *Postgres) HandleShutdown(ctx context.Context) error

HandleShutdown handle graceful shutdown for db migration

func (*Postgres) HealthCheck

func (p *Postgres) HealthCheck() error

HealthCheck checks the health of the storage system

func (*Postgres) RecordAIOpsUsage

func (p *Postgres) RecordAIOpsUsage(ctx context.Context, usage types.AIUsage) error

RecordAIOpsUsage records AI operations usage in the database

func (*Postgres) RunMigration

func (p *Postgres) RunMigration() error

RunMigration run database migration

func (*Postgres) Search

func (p *Postgres) Search(ctx context.Context, config types.SearchConfig) (*types.SearchResults, error)

Search searches for documents in the database

func (*Postgres) SetActiveDatasource

func (p *Postgres) SetActiveDatasource(ctx context.Context, uuid uuid.UUID) error

SetActiveDatasource sets a datasource to active status

func (*Postgres) SetActiveEmbeddingProvider

func (p *Postgres) SetActiveEmbeddingProvider(ctx context.Context, uuid uuid.UUID) error

SetActiveEmbeddingProvider sets an embedding provider to active status

func (*Postgres) SetActiveLLMProvider

func (p *Postgres) SetActiveLLMProvider(ctx context.Context, id uuid.UUID) error

SetActiveLLMProvider sets an LLM provider to active status

func (*Postgres) SetDisableDatasource

func (p *Postgres) SetDisableDatasource(ctx context.Context, uuid uuid.UUID) error

SetDisableDatasource sets a datasource to inactive status

func (*Postgres) SetDisableEmbeddingProvider

func (p *Postgres) SetDisableEmbeddingProvider(ctx context.Context, uuid uuid.UUID) error

SetDisableEmbeddingProvider sets an embedding provider to inactive status

func (*Postgres) SetDisableLLMProvider

func (p *Postgres) SetDisableLLMProvider(ctx context.Context, id uuid.UUID) error

SetDisableLLMProvider sets an LLM provider to inactive status

func (*Postgres) Store

func (p *Postgres) Store(ctx context.Context, doc types.Document) error

Store the document in the database

func (*Postgres) Update

func (p *Postgres) Update(ctx context.Context, doc types.Document) error

Update the document in the database

func (*Postgres) UpdateDatasource

func (p *Postgres) UpdateDatasource(ctx context.Context, uuid uuid.UUID, settings types.DatasourceSettings, state types.DatasourceState) error

UpdateDatasource updates a datasource in the database

func (*Postgres) UpdateEmbeddingProvider

func (p *Postgres) UpdateEmbeddingProvider(ctx context.Context, provider types.EmbeddingProviderConfig) error

UpdateEmbeddingProvider updates an existing embedding provider in the database

func (*Postgres) UpdateKeyPair

func (p *Postgres) UpdateKeyPair(privateKey, publicKey []byte) error

func (*Postgres) UpdateLLMProvider

func (p *Postgres) UpdateLLMProvider(ctx context.Context, provider types.LLMProviderConfig) error

UpdateLLMProvider updates an existing LLM provider in the database

func (*Postgres) UpdateSettings

func (p *Postgres) UpdateSettings(ctx context.Context, settings types.Settings) error

UpdateSettings updates the application settings in the database

func (*Postgres) UpdateUserRoles

func (p *Postgres) UpdateUserRoles(ctx context.Context, uuid uuid.UUID, roles []types.UserRole) error

func (*Postgres) UpdateUserStatus

func (p *Postgres) UpdateUserStatus(ctx context.Context, uuid uuid.UUID, status types.UserStatus) error

type PostgresConfig

type PostgresConfig struct {
	Host     string
	Port     int
	User     string
	Password string
	DBName   string
}

PostgresConfig contains configuration for a Postgres database

type Storage

type Storage interface {
	HealthCheck() error

	Store(ctx context.Context, document types.Document) error
	Update(ctx context.Context, document types.Document) error
	Get(ctx context.Context, filter types.DocumentFilter, options types.DocumentFilterOption) (types.PaginatedDocuments, error)
	GetForProcessing(ctx context.Context, filter types.DocumentFilter, batchLimit int) ([]uuid.UUID, error)

	AddDatasource(ctx context.Context, dsConfig types.DatasourceConfig) error
	GetDatasource(ctx context.Context, uuid uuid.UUID) (types.DatasourceConfig, error)
	GetAllDatasources(ctx context.Context, page, perPage int) (*types.PaginatedDatasources, error)
	UpdateDatasource(ctx context.Context, uuid uuid.UUID, settings types.DatasourceSettings, state types.DatasourceState) error
	SetActiveDatasource(ctx context.Context, uuid uuid.UUID) error
	SetDisableDatasource(ctx context.Context, uuid uuid.UUID) error
	DeleteDatasource(ctx context.Context, uuid uuid.UUID) error

	CreateEmbeddingProvider(ctx context.Context, provider types.EmbeddingProviderConfig) error
	UpdateEmbeddingProvider(ctx context.Context, provider types.EmbeddingProviderConfig) error
	DeleteEmbeddingProvider(ctx context.Context, id uuid.UUID) error
	GetEmbeddingProvider(ctx context.Context, id uuid.UUID) (*types.EmbeddingProviderConfig, error)
	GetAllEmbeddingProviders(ctx context.Context, filter types.EmbeddingProviderFilter, option types.EmbeddingProviderFilterOption) (*types.PaginatedEmbeddingProviders, error)
	SetActiveEmbeddingProvider(ctx context.Context, uuid uuid.UUID) error
	SetDisableEmbeddingProvider(ctx context.Context, uuid uuid.UUID) error

	CreateLLMProvider(ctx context.Context, provider types.LLMProviderConfig) error
	UpdateLLMProvider(ctx context.Context, provider types.LLMProviderConfig) error
	DeleteLLMProvider(ctx context.Context, uuid uuid.UUID) error
	GetLLMProvider(ctx context.Context, uuid uuid.UUID) (*types.LLMProviderConfig, error)
	GetAllLLMProviders(ctx context.Context, filter types.LLMProviderFilter, option types.LLMProviderFilterOption) (*types.PaginatedLLMProviders, error)
	SetActiveLLMProvider(ctx context.Context, id uuid.UUID) error
	SetDisableLLMProvider(ctx context.Context, id uuid.UUID) error

	RecordAIOpsUsage(ctx context.Context, usage types.AIUsage) error

	Search(ctx context.Context, config types.SearchConfig) (*types.SearchResults, error)

	UpdateSettings(ctx context.Context, settings types.Settings) error
	GetSettings(ctx context.Context) (types.Settings, error)

	CreateInteraction(ctx context.Context, interaction types.Interaction) (types.Interaction, error)
	GetInteraction(ctx context.Context, uuid uuid.UUID) (types.Interaction, error)
	GetAllInteractions(ctx context.Context, page, perPage int) (*types.PaginatedInteractions, error)
	AddConversationTx(ctx context.Context, tx *sql.Tx, interactionUUID string, conversation types.Conversation) (types.Conversation, error)
	AddConversation(ctx context.Context, interactionUUID uuid.UUID, role string, message string) (types.Conversation, error)
	GetConversation(ctx context.Context, interactionUUID uuid.UUID) ([]types.Conversation, error)

	GetAnalyticsOverview(ctx context.Context) (types.AnalyticsOverview, error)

	RunMigration() error
	HandleShutdown(ctx context.Context) error

	GetKeyPair() (privateKey, publicKey []byte, err error)
	UpdateKeyPair(privateKey, publicKey []byte) error

	CreateUser(ctx context.Context, user *types.User) error
	GetUser(ctx context.Context, uuid uuid.UUID) (*types.User, error)
	UpdateUserStatus(ctx context.Context, uuid uuid.UUID, status types.UserStatus) error
	GetPaginatedUsers(ctx context.Context, filter types.UserFilter, option types.UserFilterOption) (types.PaginatedUsers, error)
	UpdateUserRoles(ctx context.Context, uuid uuid.UUID, roles []types.UserRole) error
}

func NewPostgres

func NewPostgres(cfg PostgresConfig, logger *logrus.Logger) (Storage, error)

NewPostgres creates a new Postgres storage system

type StorageMock

type StorageMock struct {
	mock.Mock
}

StorageMock is an autogenerated mock type for the StorageMock type

func NewStorageMock

func NewStorageMock(t interface {
	mock.TestingT
	Cleanup(func())
}) *StorageMock

NewStorage creates a new instance of StorageMock. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. The first argument is typically a *testing.T value.

func (*StorageMock) AddConversation

func (_m *StorageMock) AddConversation(ctx context.Context, interactionUUID uuid.UUID, role string, message string) (types.Conversation, error)

AddConversation provides a mock function with given fields: ctx, interactionUUID, role, message

func (*StorageMock) AddConversationTx

func (_m *StorageMock) AddConversationTx(ctx context.Context, tx *sql.Tx, interactionUUID string, conversation types.Conversation) (types.Conversation, error)

AddConversationTx provides a mock function with given fields: ctx, tx, interactionUUID, conversation

func (*StorageMock) AddDatasource

func (_m *StorageMock) AddDatasource(ctx context.Context, dsConfig types.DatasourceConfig) error

AddDatasource provides a mock function with given fields: ctx, dsConfig

func (*StorageMock) CreateEmbeddingProvider

func (_m *StorageMock) CreateEmbeddingProvider(ctx context.Context, provider types.EmbeddingProviderConfig) error

CreateEmbeddingProvider provides a mock function with given fields: ctx, provider

func (*StorageMock) CreateInteraction

func (_m *StorageMock) CreateInteraction(ctx context.Context, interaction types.Interaction) (types.Interaction, error)

CreateInteraction provides a mock function with given fields: ctx, interaction

func (*StorageMock) CreateLLMProvider

func (_m *StorageMock) CreateLLMProvider(ctx context.Context, provider types.LLMProviderConfig) error

CreateLLMProvider provides a mock function with given fields: ctx, provider

func (*StorageMock) CreateUser

func (_m *StorageMock) CreateUser(ctx context.Context, user *types.User) error

CreateUser provides a mock function with given fields: ctx, user

func (*StorageMock) DeleteDatasource

func (_m *StorageMock) DeleteDatasource(ctx context.Context, _a1 uuid.UUID) error

DeleteDatasource provides a mock function with given fields: ctx, _a1

func (*StorageMock) DeleteEmbeddingProvider

func (_m *StorageMock) DeleteEmbeddingProvider(ctx context.Context, id uuid.UUID) error

DeleteEmbeddingProvider provides a mock function with given fields: ctx, id

func (*StorageMock) DeleteLLMProvider

func (_m *StorageMock) DeleteLLMProvider(ctx context.Context, _a1 uuid.UUID) error

DeleteLLMProvider provides a mock function with given fields: ctx, _a1

func (*StorageMock) Get

Get provides a mock function with given fields: ctx, filter, options

func (*StorageMock) GetAllDatasources

func (_m *StorageMock) GetAllDatasources(ctx context.Context, page int, perPage int) (*types.PaginatedDatasources, error)

GetAllDatasources provides a mock function with given fields: ctx, page, perPage

func (*StorageMock) GetAllEmbeddingProviders

GetAllEmbeddingProviders provides a mock function with given fields: ctx, filter, option

func (*StorageMock) GetAllInteractions

func (_m *StorageMock) GetAllInteractions(ctx context.Context, page int, perPage int) (*types.PaginatedInteractions, error)

GetAllInteractions provides a mock function with given fields: ctx, page, perPage

func (*StorageMock) GetAllLLMProviders

GetAllLLMProviders provides a mock function with given fields: ctx, filter, option

func (*StorageMock) GetAnalyticsOverview

func (_m *StorageMock) GetAnalyticsOverview(ctx context.Context) (types.AnalyticsOverview, error)

GetAnalyticsOverview provides a mock function with given fields: ctx

func (*StorageMock) GetConversation

func (_m *StorageMock) GetConversation(ctx context.Context, interactionUUID uuid.UUID) ([]types.Conversation, error)

GetConversation provides a mock function with given fields: ctx, interactionUUID

func (*StorageMock) GetDatasource

func (_m *StorageMock) GetDatasource(ctx context.Context, _a1 uuid.UUID) (types.DatasourceConfig, error)

GetDatasource provides a mock function with given fields: ctx, _a1

func (*StorageMock) GetEmbeddingProvider

func (_m *StorageMock) GetEmbeddingProvider(ctx context.Context, id uuid.UUID) (*types.EmbeddingProviderConfig, error)

GetEmbeddingProvider provides a mock function with given fields: ctx, id

func (*StorageMock) GetForProcessing

func (_m *StorageMock) GetForProcessing(ctx context.Context, filter types.DocumentFilter, batchLimit int) ([]uuid.UUID, error)

GetForProcessing provides a mock function with given fields: ctx, filter, batchLimit

func (*StorageMock) GetInteraction

func (_m *StorageMock) GetInteraction(ctx context.Context, _a1 uuid.UUID) (types.Interaction, error)

GetInteraction provides a mock function with given fields: ctx, _a1

func (*StorageMock) GetKeyPair

func (_m *StorageMock) GetKeyPair() ([]byte, []byte, error)

GetKeyPair provides a mock function with given fields:

func (*StorageMock) GetLLMProvider

func (_m *StorageMock) GetLLMProvider(ctx context.Context, _a1 uuid.UUID) (*types.LLMProviderConfig, error)

GetLLMProvider provides a mock function with given fields: ctx, _a1

func (*StorageMock) GetPaginatedUsers

func (_m *StorageMock) GetPaginatedUsers(ctx context.Context, filter types.UserFilter, option types.UserFilterOption) (types.PaginatedUsers, error)

GetPaginatedUsers provides a mock function with given fields: ctx, filter, option

func (*StorageMock) GetSettings

func (_m *StorageMock) GetSettings(ctx context.Context) (types.Settings, error)

GetSettings provides a mock function with given fields: ctx

func (*StorageMock) GetUser

func (_m *StorageMock) GetUser(ctx context.Context, _a1 uuid.UUID) (*types.User, error)

GetUser provides a mock function with given fields: ctx, _a1

func (*StorageMock) HandleShutdown

func (_m *StorageMock) HandleShutdown(ctx context.Context) error

HandleShutdown provides a mock function with given fields: ctx

func (*StorageMock) HealthCheck

func (_m *StorageMock) HealthCheck() error

HealthCheck provides a mock function with given fields:

func (*StorageMock) RecordAIOpsUsage

func (_m *StorageMock) RecordAIOpsUsage(ctx context.Context, usage types.AIUsage) error

RecordAIOpsUsage provides a mock function with given fields: ctx, usage

func (*StorageMock) RunMigration

func (_m *StorageMock) RunMigration() error

RunMigration provides a mock function with given fields:

func (*StorageMock) Search

func (_m *StorageMock) Search(ctx context.Context, config types.SearchConfig) (*types.SearchResults, error)

Search provides a mock function with given fields: ctx, config

func (*StorageMock) SetActiveDatasource

func (_m *StorageMock) SetActiveDatasource(ctx context.Context, _a1 uuid.UUID) error

SetActiveDatasource provides a mock function with given fields: ctx, _a1

func (*StorageMock) SetActiveEmbeddingProvider

func (_m *StorageMock) SetActiveEmbeddingProvider(ctx context.Context, _a1 uuid.UUID) error

SetActiveEmbeddingProvider provides a mock function with given fields: ctx, _a1

func (*StorageMock) SetActiveLLMProvider

func (_m *StorageMock) SetActiveLLMProvider(ctx context.Context, id uuid.UUID) error

SetActiveLLMProvider provides a mock function with given fields: ctx, id

func (*StorageMock) SetDisableDatasource

func (_m *StorageMock) SetDisableDatasource(ctx context.Context, _a1 uuid.UUID) error

SetDisableDatasource provides a mock function with given fields: ctx, _a1

func (*StorageMock) SetDisableEmbeddingProvider

func (_m *StorageMock) SetDisableEmbeddingProvider(ctx context.Context, _a1 uuid.UUID) error

SetDisableEmbeddingProvider provides a mock function with given fields: ctx, _a1

func (*StorageMock) SetDisableLLMProvider

func (_m *StorageMock) SetDisableLLMProvider(ctx context.Context, id uuid.UUID) error

SetDisableLLMProvider provides a mock function with given fields: ctx, id

func (*StorageMock) Store

func (_m *StorageMock) Store(ctx context.Context, document types.Document) error

Store provides a mock function with given fields: ctx, document

func (*StorageMock) Update

func (_m *StorageMock) Update(ctx context.Context, document types.Document) error

Update provides a mock function with given fields: ctx, document

func (*StorageMock) UpdateDatasource

func (_m *StorageMock) UpdateDatasource(ctx context.Context, _a1 uuid.UUID, settings types.DatasourceSettings, state types.DatasourceState) error

UpdateDatasource provides a mock function with given fields: ctx, _a1, settings, state

func (*StorageMock) UpdateEmbeddingProvider

func (_m *StorageMock) UpdateEmbeddingProvider(ctx context.Context, provider types.EmbeddingProviderConfig) error

UpdateEmbeddingProvider provides a mock function with given fields: ctx, provider

func (*StorageMock) UpdateKeyPair

func (_m *StorageMock) UpdateKeyPair(privateKey []byte, publicKey []byte) error

UpdateKeyPair provides a mock function with given fields: privateKey, publicKey

func (*StorageMock) UpdateLLMProvider

func (_m *StorageMock) UpdateLLMProvider(ctx context.Context, provider types.LLMProviderConfig) error

UpdateLLMProvider provides a mock function with given fields: ctx, provider

func (*StorageMock) UpdateSettings

func (_m *StorageMock) UpdateSettings(ctx context.Context, settings types.Settings) error

UpdateSettings provides a mock function with given fields: ctx, settings

func (*StorageMock) UpdateUserRoles

func (_m *StorageMock) UpdateUserRoles(ctx context.Context, _a1 uuid.UUID, roles []types.UserRole) error

UpdateUserRoles provides a mock function with given fields: ctx, _a1, roles

func (*StorageMock) UpdateUserStatus

func (_m *StorageMock) UpdateUserStatus(ctx context.Context, _a1 uuid.UUID, status types.UserStatus) error

UpdateUserStatus provides a mock function with given fields: ctx, _a1, status

Jump to

Keyboard shortcuts

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