Documentation
¶
Overview ¶
Package pgvector implements vector-store capabilities with the pgvector PostgreSQL extension. Documents live in a regular PostgreSQL table with a typed `vector(N)` column; metadata is stored in `jsonb`.
Requirements: PostgreSQL 13+ with the `vector` extension installed (the store runs `CREATE EXTENSION IF NOT EXISTS vector` under StoreConfig.InitializeSchema = true).
Distance metrics — three of pgvector's six operators are exposed:
- DistanceCosine (`<=>`) — cosine distance, `vector_cosine_ops`
- DistanceL2 (`<->`) — Euclidean distance, `vector_l2_ops`
- DistanceIP (`<#>`) — negative inner product, `vector_ip_ops`
Index types: HNSW (default, best query perf) / IVFFlat (faster builds) / none (exact sequential-scan). Vector binding uses pgvector-go's typed [pgvec.Vector]; the connection is a standard pgx pool.
Metadata filters compile to parameterized SQL; values flow through `$N` placeholders, while JSON numbers and booleans use explicit PostgreSQL casts.
See https://github.com/pgvector/pgvector for the extension docs.
Index ¶
- Constants
- type DistanceMetric
- type IndexType
- type Store
- func (s *Store) DeleteIDs(ctx context.Context, ids []string) error
- func (s *Store) DeleteWhere(ctx context.Context, predicate filter.Predicate) error
- func (s *Store) Index(ctx context.Context, request *vectorstore.IndexRequest) error
- func (s *Store) Search(ctx context.Context, request *vectorstore.SearchRequest) (*vectorstore.SearchResponse, error)
- type StoreConfig
Constants ¶
const ( DefaultSchemaName = "public" DefaultTableName = "vector_store" DefaultMetadataColumn = "metadata" DefaultIndexSuffix = "_embedding_idx" )
Exported defaults keep constructor behavior visible and overridable.
const Provider = "PgVector"
Provider is the stable backend name for host-side attribution.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DistanceMetric ¶
type DistanceMetric string
DistanceMetric selects the query operator and ANN-index opclass.
const ( // DistanceCosine uses cosine distance (`<=>` and vector_cosine_ops). DistanceCosine DistanceMetric = "cosine" // DistanceL2 uses Euclidean distance (`<->` and vector_l2_ops). DistanceL2 DistanceMetric = "l2" // DistanceIP uses negative inner product (`<#>` and vector_ip_ops). DistanceIP DistanceMetric = "ip" )
func (DistanceMetric) String ¶
func (d DistanceMetric) String() string
func (DistanceMetric) Valid ¶
func (d DistanceMetric) Valid() bool
type IndexType ¶
type IndexType string
IndexType selects the ANN index created during schema initialization.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store implements vector-store capabilities with PostgreSQL and pgvector.
func NewStore ¶
func NewStore(ctx context.Context, config StoreConfig) (*Store, error)
NewStore performs schema setup during construction, which is why it takes a context: a store returned before its backing schema exists would fail on the first index rather than at wiring, where the misconfiguration actually is.
func (*Store) DeleteWhere ¶
func (*Store) Index ¶
func (s *Store) Index(ctx context.Context, request *vectorstore.IndexRequest) error
func (*Store) Search ¶
func (s *Store) Search(ctx context.Context, request *vectorstore.SearchRequest) (*vectorstore.SearchResponse, error)
type StoreConfig ¶
type StoreConfig struct {
Pool *pgxpool.Pool
SchemaName string
TableName string
IndexName string
MetadataColumn string
EmbeddingModel embedding.Model
DocumentBatcher vectorstore.Batcher
Dimensions int
DistanceMetric DistanceMetric
IndexType IndexType
InitializeSchema bool
}
StoreConfig names every dependency explicitly rather than defaulting a client or connection, so a store cannot be built against a service the caller did not choose.
func (StoreConfig) Validate ¶
func (s StoreConfig) Validate() error