pgvector

package
v0.0.0-...-b2b7851 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package pgvector contains an implementation of the VectorStore interface using pgvector.

Index

Constants

View Source
const (
	DefaultCollectionName           = "langchain"
	DefaultPreDeleteCollection      = false
	DefaultEmbeddingStoreTableName  = "langchain_pg_embedding"
	DefaultCollectionStoreTableName = "langchain_pg_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 HNSWIndex

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

type Option

type Option func(p *Store)

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

func WithCollectionMetadata

func WithCollectionMetadata(metadata map[string]any) Option

WithCollectionMetadata is an option for specifying the collection metadata.

func WithCollectionName

func WithCollectionName(name string) Option

WithCollectionName is an option for specifying the collection name.

func WithCollectionTableName

func WithCollectionTableName(name string) Option

WithCollectionTableName is an option for specifying the collection table name.

func WithConn

func WithConn(conn PGXConn) Option

WithConn is an option for specifying the Postgres connection. From pgx doc: it is not safe for concurrent usage.Use a connection pool to manage access to multiple database connections from multiple goroutines.

func WithConnectionURL

func WithConnectionURL(connectionURL string) Option

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

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 WithHNSWIndex

func WithHNSWIndex(m int, efConstruction int, distanceFunction string) Option

WithHNSWIndex is an option for specifying the HNSW index parameters. See here for more details: https://github.com/pgvector/pgvector#hnsw

m: he max number of connections per layer (16 by default) efConstruction: the size of the dynamic candidate list for constructing the graph (64 by default) distanceFunction: the distance function to use (l2 by default).

func WithPreDeleteCollection

func WithPreDeleteCollection(preDelete bool) Option

WithPreDeleteCollection is an option for setting if the collection should be deleted before creating.

func WithVectorDimensions

func WithVectorDimensions(size int) Option

WithVectorDimensions is an option for specifying the vector size.

type PGXConn

type PGXConn interface {
	Ping(ctx context.Context) error
	Begin(ctx context.Context) (pgx.Tx, error)
	Exec(ctx context.Context, sql string, arguments ...any) (pgconn.CommandTag, error)
	Query(ctx context.Context, sql string, arguments ...any) (pgx.Rows, error)
	QueryRow(ctx context.Context, sql string, arguments ...any) pgx.Row
	SendBatch(ctx context.Context, batch *pgx.Batch) pgx.BatchResults
}

PGXConn represents both a pgx.Conn and pgxpool.Pool conn.

type Store

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

Store is a wrapper around the pgvector 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 Postgres collection associated with 'Store'. and returns the ids of the added documents.

func (Store) Close

func (s Store) Close() error

Close closes the connection.

func (Store) DropTables

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

func (Store) RemoveCollection

func (s Store) RemoveCollection(ctx context.Context, tx pgx.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