Documentation
¶
Overview ¶
Package pgvector stores and ranks precomputed vectors for an explicitly Host-bound vector space. It does not own an embedding model or the connection pool. Metadata is preserved as opaque bytes; filtered native queries return vectorstore.ErrUnsupportedFilter before querying rows.
Index ¶
- Constants
- type IndexType
- type Store
- func (s *Store) CheckDocuments(ctx context.Context, space vectorstore.SpaceID, docs []*document.Document) error
- func (s *Store) CheckQuery(ctx context.Context, space vectorstore.SpaceID, ...) error
- func (s *Store) DeleteIDs(ctx context.Context, ids []string) error
- func (s *Store) Query(ctx context.Context, request *vectorstore.Query) (*vectorstore.SearchResponse, error)
- func (s *Store) Scan(ctx context.Context, config postgres.ScanConfig) ([]*document.Document, error)
- func (s *Store) Upsert(ctx context.Context, batch *vectorstore.Batch) error
- type StoreConfig
Examples ¶
Constants ¶
View Source
const ( DefaultSchemaName = "public" DefaultTableName = "vector_store" DefaultMetadataColumn = "metadata" DefaultIndexSuffix = "_embedding_idx" )
View Source
const Provider = "PgVector"
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
func NewStore ¶
func NewStore(ctx context.Context, config StoreConfig) (*Store, error)
Example ¶
package main
import (
"context"
"os"
"github.com/jackc/pgx/v5/pgxpool"
"github.com/Tangerg/scope/core/document"
"github.com/Tangerg/scope/core/vectorstore"
"github.com/Tangerg/scope/vectorstores/postgres/pgvector"
)
func main() {
ctx := context.Background()
pool, err := pgxpool.New(ctx, os.Getenv("SCOPE_PGVECTOR_DSN"))
if err != nil {
panic(err)
}
defer pool.Close()
store, err := pgvector.NewStore(ctx, pgvector.StoreConfig{Pool: pool, SchemaName: "scope", TableName: "documents", Space: "release-notes-v1", Dimensions: 2, InitializeSchema: true})
if err != nil {
panic(err)
}
if err = store.Upsert(ctx, &vectorstore.Batch{Space: "release-notes-v1", Records: []vectorstore.Record{{Document: &document.Document{ID: "one", Text: "current record"}, Values: []float64{1, 0}}}}); err != nil {
panic(err)
}
if _, err = store.Query(ctx, &vectorstore.Query{Space: "release-notes-v1", Values: []float64{1, 0}}); err != nil {
panic(err)
}
if err = store.DeleteIDs(ctx, []string{"one"}); err != nil {
panic(err)
}
}
Output:
func (*Store) CheckDocuments ¶ added in v0.59.0
func (*Store) CheckQuery ¶ added in v0.59.0
func (s *Store) CheckQuery(ctx context.Context, space vectorstore.SpaceID, options vectorstore.SearchOptions) error
func (*Store) Query ¶ added in v0.59.0
func (s *Store) Query(ctx context.Context, request *vectorstore.Query) (*vectorstore.SearchResponse, error)
type StoreConfig ¶
type StoreConfig struct {
Pool *pgxpool.Pool
SchemaName string
TableName string
IndexName string
MetadataColumn string
// Space is the Host-owned immutable binding for this physical collection.
Space vectorstore.SpaceID
// Dimensions seeds only a newly created native column; existing native width is authoritative.
Dimensions int
DistanceMetric postgres.DistanceMetric
IndexType IndexType
InitializeSchema bool
}
func (StoreConfig) Validate ¶
func (s StoreConfig) Validate() error
Click to show internal directories.
Click to hide internal directories.