Documentation ¶
Index ¶
- Variables
- type CloseNoErr
- type HNSWIndex
- type PGXConn
- type VectorStore
- func (v VectorStore) AddDocuments(ctx context.Context, docs []vs.Document, collection string) ([]string, error)
- func (v VectorStore) CreateCollection(ctx context.Context, collection string) error
- func (v VectorStore) ExportCollectionsToFile(ctx context.Context, path string, collections ...string) error
- func (v VectorStore) GetDocuments(ctx context.Context, collection string, where map[string]string, ...) ([]vs.Document, error)
- func (v VectorStore) ImportCollectionsFromFile(ctx context.Context, path string, collections ...string) error
- func (v VectorStore) RemoveCollection(ctx context.Context, collection string) error
- func (v VectorStore) RemoveDocument(ctx context.Context, documentID string, collection string, ...) error
- func (v VectorStore) SimilaritySearch(ctx context.Context, query string, numDocuments int, collection string, ...) ([]vs.Document, error)
Constants ¶
This section is empty.
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 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 (VectorStore) CreateCollection ¶
func (v VectorStore) CreateCollection(ctx context.Context, collection string) error
func (VectorStore) ExportCollectionsToFile ¶
func (VectorStore) GetDocuments ¶
func (VectorStore) ImportCollectionsFromFile ¶
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)