mariadb

package
v0.1.15 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2025 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package mariadb contains an implementation of the VectorStore interface using MariaDB.

Index

Constants

View Source
const (
	DefaultDatabaseName             = "langchain"
	DefaultPreDeleteDatabase        = false
	DefaultEmbeddingStoreTableName  = "langchain_mariadb_embedding"
	DefaultCollectionStoreTableName = "langchain_mariadb_collection"
)

Variables

View Source
var (
	ErrEmbedderWrongNumberVectors = errors.New("number of vectors from embedder does not match number of documents")
	ErrInvalidScoreThreshold      = errors.New("score threshold must be between 0 and 1")
	ErrInvalidFilters             = errors.New("invalid filters")
	ErrUnsupportedOptions         = errors.New("unsupported options")
)
View Source
var ErrInvalidOptions = errors.New("invalid options")

ErrInvalidOptions is returned when the options given are invalid.

Functions

This section is empty.

Types

type CloseNoErr

type CloseNoErr interface {
	Close()
}

type DB

type DB interface {
	PingContext(ctx context.Context) error
	BeginTx(ctx context.Context, opts *sql.TxOptions) (*sql.Tx, error)
	ExecContext(ctx context.Context, sql string, arguments ...any) (sql.Result, error)
	QueryContext(ctx context.Context, sql string, arguments ...any) (*sql.Rows, error)
	QueryRowContext(ctx context.Context, sql string, arguments ...any) *sql.Row
}

DB represents both a sql.DB and sql.Tx.

type Option

type Option func(p *Store)

Option is a function type that can be used to modify the client.

func WithCollectionTableName

func WithCollectionTableName(name string) Option

WithCollectionTableName is an option for specifying the collection table name.

func WithConnectionURL

func WithConnectionURL(connectionURL string) Option

WithConnectionURL is an option for specifying the MariaDB connection URL. Either this or WithConn must be used.

func WithDB

func WithDB(db DB) Option

WithDB is an option for specifying the MariaDB connection.

func WithDatabaseMetadata

func WithDatabaseMetadata(metadata map[string]any) Option

WithDatabaseMetadata is an option for specifying the database metadata.

func WithDatabaseName

func WithDatabaseName(name string) Option

WithDatabaseName is an option for specifying the database name.

func WithEmbedder

func WithEmbedder(e embeddings.Embedder) Option

WithEmbedder is an option for setting the embedder to use. Must be set.

func WithEmbeddingTableName

func WithEmbeddingTableName(name string) Option

WithEmbeddingTableName is an option for specifying the embedding table name.

func WithPreDeleteDatabase

func WithPreDeleteDatabase(preDelete bool) Option

WithPreDeleteDatabase is an option for setting if the database should be deleted before creating.

func WithVectorDimensions

func WithVectorDimensions(size int) Option

WithVectorDimensions is an option for specifying the vector size.

type Store

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

Store is a wrapper around the mariadb client.

func New

func New(ctx context.Context, opts ...Option) (Store, error)

New creates a new Store with options.

func (Store) AddDocuments

func (s Store) AddDocuments(
	ctx context.Context,
	docs []schema.Document,
	options ...vectorstores.Option,
) ([]string, error)

AddDocuments adds documents to the MariaDB database associated with 'Store'. and returns the ids of the added documents.

func (Store) Close

func (s Store) Close() error

Close closes the db.

func (Store) DropTables

func (s Store) DropTables(ctx context.Context) error

func (Store) RemoveDatabase

func (s Store) RemoveDatabase(ctx context.Context, tx *sql.Tx) error

func (Store) Search

func (s Store) Search(
	ctx context.Context,
	numDocuments int,
	options ...vectorstores.Option,
) ([]schema.Document, error)

func (Store) SimilaritySearch

func (s Store) SimilaritySearch(
	ctx context.Context,
	query string,
	numDocuments int,
	options ...vectorstores.Option,
) ([]schema.Document, error)

Jump to

Keyboard shortcuts

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