pgvector

package
v0.6.1-rc.2 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

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 DefaultHNSWIndex = &HNSWIndex{
	m:                16,
	efConstruction:   64,
	distanceFunction: "vector_l2_ops",
}

Functions

This section is empty.

Types

type CloseNoErr

type CloseNoErr interface {
	Close()
}

type HNSWIndex

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

HNSWIndex lets you specify 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).

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 VectorStore

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

func New

func New(ctx context.Context, dsn string, embeddingFunc cg.EmbeddingFunc) (*VectorStore, error)

func (VectorStore) AddDocuments

func (v VectorStore) AddDocuments(ctx context.Context, docs []vs.Document, collection string) ([]string, error)

func (VectorStore) CreateCollection

func (v VectorStore) CreateCollection(ctx context.Context, collection string) error

func (VectorStore) ExportCollectionsToFile

func (v VectorStore) ExportCollectionsToFile(ctx context.Context, path string, collections ...string) error

func (VectorStore) GetDocuments

func (v VectorStore) GetDocuments(ctx context.Context, collection string, where map[string]string, whereDocument []cg.WhereDocument) ([]vs.Document, error)

func (VectorStore) ImportCollectionsFromFile

func (v VectorStore) ImportCollectionsFromFile(ctx context.Context, path string, collections ...string) error

func (VectorStore) RemoveCollection

func (v VectorStore) RemoveCollection(ctx context.Context, collection string) error

func (VectorStore) RemoveDocument

func (v VectorStore) RemoveDocument(ctx context.Context, documentID string, collection string, where map[string]string, whereDocument []cg.WhereDocument) error

func (VectorStore) SimilaritySearch

func (v VectorStore) SimilaritySearch(ctx context.Context, query string, numDocuments int, collection string, where map[string]string, whereDocument []cg.WhereDocument) ([]vs.Document, error)

SimilaritySearch performs a similarity search on the given query and returns the most similar documents. * pgvector supports different distance functions: https://github.com/pgvector/pgvector/blob/master/README.md#querying * Supported distance functions are (more have been added since writing this): * - `<->` - L2 distance * - `<#>` - (negative) inner product * - `<=>` - cosine distance (for cosine similarity, use 1 - cosine distance) * - `<+>` - L1 distance (added in 0.7.0) * - `<~>` - Hamming distance (binary vectors, added in 0.7.0) * - `<%>` - Jaccard distance (binary vectors, added in 0.7.0)

Jump to

Keyboard shortcuts

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