postgres

package
v0.0.14 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option struct {
	TopK    int
	Filters map[string]any
}

type Postgres

type Postgres struct {
	Embedding embedding.Embedder
	// contains filtered or unexported fields
}

func NewPostgres

func NewPostgres(config PostgresConfig) (*Postgres, error)

NewPostgres 使用现有GORM实例创建PostgreSQL向量数据库

func (*Postgres) Create

func (p *Postgres) Create() error

Create 创建向量表

func (*Postgres) Exists

func (p *Postgres) Exists() bool

Exists 检查表是否存在

func (*Postgres) GetType

func (p *Postgres) GetType() string

GetType 返回组件类型

func (*Postgres) Retrieve

func (p *Postgres) Retrieve(ctx context.Context, query string, opts ...retriever.Option) ([]*schema.Document, error)

Retrieve 实现retriever.Retriever接口

func (*Postgres) Search

func (p *Postgres) Search(ctx context.Context, queryVector []float32, limit int, filters map[string]interface{}, threshold float64) ([]*schema.Document, error)

Search 向量搜索

func (*Postgres) Store

func (p *Postgres) Store(ctx context.Context, docs []*schema.Document, opts ...indexer.Option) ([]string, error)

Store 存储文档(实现indexer.Indexer接口)

type PostgresConfig

type PostgresConfig struct {
	Client          *gorm.DB
	CollectionName  string // 集合名称
	VectorDimension int    // 向量维度
	Embedding       embedding.Embedder
}

PostgresConfig PostgreSQL配置

type PostgresVectorDocument

type PostgresVectorDocument struct {
	ID        string    `gorm:"column:id;primaryKey" json:"id"`
	Content   string    `gorm:"column:content;type:text" json:"content"`
	Vector    string    `gorm:"column:vector;type:vector" json:"vector"` // pgvector类型
	Metadata  string    `gorm:"column:metadata;type:text" json:"metadata"`
	CreatedAt time.Time `gorm:"column:created_at;autoCreateTime" json:"created_at"`
	UpdatedAt time.Time `gorm:"column:updated_at;autoUpdateTime" json:"updated_at"`
}

PostgresVectorDocument PostgreSQL向量文档模型

Jump to

Keyboard shortcuts

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