pgvector

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package pgvector provides a PostgreSQL + pgvector store for memoryrails.

It uses GORM for database operations and pgvector for vector similarity search with HNSW indexing. Requires PostgreSQL with the pgvector extension installed.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MemoryRecord

type MemoryRecord struct {
	ID             string          `gorm:"primaryKey;size:64"`
	Content        string          `gorm:"type:text;not null"`
	Type           string          `gorm:"size:50;not null;index"`
	Embedding      pgvector.Vector `gorm:"type:vector"`
	Metadata       string          `gorm:"type:jsonb"` // JSON string
	Importance     float64         `gorm:"default:0.5"`
	AccessCount    int             `gorm:"default:0"`
	LastAccessedAt *time.Time
	CreatedAt      time.Time `gorm:"index"`
	UpdatedAt      time.Time
}

MemoryRecord is the GORM model for the memories table.

func (MemoryRecord) TableName

func (MemoryRecord) TableName() string

TableName returns the table name.

type Option

type Option func(*Store)

Option configures the store.

func WithDimensions

func WithDimensions(dims int) Option

WithDimensions sets the vector dimensions for the embedding column. Default: 1536.

type Store

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

Store implements memoryrails.Store using PostgreSQL with pgvector.

func New

func New(db *gorm.DB, opts ...Option) (*Store, error)

New creates a new pgvector store. It auto-migrates the table and creates the pgvector extension and HNSW index if they don't exist.

func (*Store) Close

func (s *Store) Close() error

Close is a no-op; the caller manages the gorm.DB lifecycle.

func (*Store) Delete

func (s *Store) Delete(ctx context.Context, id string) error

func (*Store) Get

func (s *Store) Get(ctx context.Context, id string) (*memoryrails.Memory, error)

func (*Store) List

func (*Store) Put

func (s *Store) Put(ctx context.Context, mem *memoryrails.Memory) error

func (*Store) Search

func (s *Store) Search(ctx context.Context, embedding []float64, opts memoryrails.SearchOptions) ([]memoryrails.SearchResult, error)

Jump to

Keyboard shortcuts

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