Documentation ¶
Overview ¶
Package pgvector contains an implementation of the VectorStore interface using pgvector.
Index ¶
- Constants
- Variables
- type CloseNoErr
- type HNSWIndex
- type Option
- func WithCollectionMetadata(metadata map[string]any) Option
- func WithCollectionName(name string) Option
- func WithCollectionTableName(name string) Option
- func WithConn(conn PGXConn) Option
- func WithConnectionURL(connectionURL string) Option
- func WithEmbedder(e embeddings.Embedder) Option
- func WithEmbeddingTableName(name string) Option
- func WithHNSWIndex(m int, efConstruction int, distanceFunction string) Option
- func WithPreDeleteCollection(preDelete bool) Option
- func WithVectorDimensions(size int) Option
- type PGXConn
- type Store
- func (s Store) AddDocuments(ctx context.Context, docs []schema.Document, options ...vectorstores.Option) ([]string, error)
- func (s Store) Close() error
- func (s Store) DropTables(ctx context.Context) error
- func (s Store) RemoveCollection(ctx context.Context, tx pgx.Tx) error
- func (s Store) Search(ctx context.Context, numDocuments int, options ...vectorstores.Option) ([]schema.Document, error)
- func (s Store) SimilaritySearch(ctx context.Context, query string, numDocuments int, ...) ([]schema.Document, error)
Constants ¶
const ( DefaultCollectionName = "langchain" DefaultPreDeleteCollection = false DefaultEmbeddingStoreTableName = "langchain_pg_embedding" DefaultCollectionStoreTableName = "langchain_pg_collection" )
Variables ¶
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") )
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 Option ¶
type Option func(p *Store)
Option is a function type that can be used to modify the client.
func WithCollectionMetadata ¶
WithCollectionMetadata is an option for specifying the collection metadata.
func WithCollectionName ¶
WithCollectionName is an option for specifying the collection name.
func WithCollectionTableName ¶
WithCollectionTableName is an option for specifying the collection table name.
func WithConn ¶
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 ¶
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 ¶
WithEmbeddingTableName is an option for specifying the embedding table name.
func WithHNSWIndex ¶
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 ¶
WithPreDeleteCollection is an option for setting if the collection should be deleted before creating.
func WithVectorDimensions ¶
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 (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.