pgvector

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2023 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var VectorDimensionsByEmbeddingModel = map[EmbeddingModel]int{
	EmbeddingOpenAI:         1536,
	EmbeddingOpenAI_ada_002: 1536,
}

Functions

func NewPGVectorStore

func NewPGVectorStore(opts ...Options) (store.VectorStore, error)

Types

type EmbeddingModel

type EmbeddingModel int
const (
	EmbeddingOpenAI_ada_002 EmbeddingModel = iota
	EmbeddingOpenAI                        // default for openai
)

type Options

type Options func(o *pgvOptions)

func WithClient

func WithClient(sqlClient *sql.DB) Options

WithClient sets an existing sql client - useful for proxying or testing or supplying a pre-made sql client connection with customizations

func WithCollection

func WithCollection(name string) Options

WithCollection sets the name of the collection (table within the postgres database)

func WithCreateExtension added in v1.1.0

func WithCreateExtension() Options

WithCreateExtension If set, will attempt to enable the PGVECTOR extension in the database. The user should have the appropriate permissions. Otherwise, provision the database with pgvector pre-enabled

func WithCreds

func WithCreds(user, pwd string) Options

WithCreds sets the user creds for postgres

func WithDBName

func WithDBName(dbname string) Options

WithDBName sets the db name to use with postgres

func WithEmbedder

func WithEmbedder(e embeddings.Embedder) Options

WithEmbedder sets the embeddings provider

func WithEmbeddingMode

func WithEmbeddingMode(e EmbeddingModel) Options

WithEmbeddingMode sets the embeddings mode. Currently, only OpenAI ADA_002 is supported.

func WithEndpoint

func WithEndpoint(host string, port int) Options

WithEndpoint sets the host and port for the postgres instance to connect with

func WithSSLMode

func WithSSLMode(mode string) Options

WithSSLMode only "require" (default), "verify-full", "verify-ca", and "disable" supported

type Store

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

Store is a postgres based implementation of a vector store

func (*Store) AddDocuments

func (p *Store) AddDocuments(ctx context.Context, documents []schema.Document, option ...vectorstores.Option) error

func (*Store) ClearCollection

func (p *Store) ClearCollection() error

func (*Store) CollectionName

func (p *Store) CollectionName() string

func (*Store) CollectionSize

func (p *Store) CollectionSize() (int, error)

func (*Store) SimilaritySearch

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

type Vector

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

Vector is a wrapper for []float32 to implement sql.Scanner and driver.Valuer.

func NewVector

func NewVector(vec []float32) Vector

NewVector creates a new Vector from a slice of float32.

func NewVectorSlice

func NewVectorSlice(vec [][]float32) []Vector

func (*Vector) Parse

func (v *Vector) Parse(s string) error

Parse parses a string representation of a vector.

func (*Vector) Scan

func (v *Vector) Scan(src interface{}) (err error)

Scan implements the sql.Scanner interface.

func (*Vector) Slice

func (v *Vector) Slice() []float32

Slice returns the underlying slice of float32.

func (*Vector) String

func (v *Vector) String() string

String returns a string representation of the vector.

func (Vector) Value

func (v Vector) Value() (driver.Value, error)

Value implements the driver.Valuer interface.

Jump to

Keyboard shortcuts

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