Documentation
¶
Overview ¶
Package postgres provides a hybrid index backed by PostgreSQL, combining native full-text search (tsvector + ts_rank) with vector similarity search (pgvector, cosine distance). Results from both legs are fused with Reciprocal Rank Fusion.
The vector leg is only active when an llm.Client is provided; without one the index degrades gracefully to full-text search only. In both cases the target database must have the `vector` and `unaccent` extensions available (creating them requires sufficient privileges, e.g. the pgvector/pgvector Docker images).
Index ¶
- Constants
- type Index
- func (i *Index) All(ctx context.Context, yield func(model.SectionID) bool) error
- func (i *Index) DeleteByID(ctx context.Context, ids ...model.SectionID) error
- func (i *Index) DeleteBySource(ctx context.Context, source *url.URL) error
- func (i *Index) GenerateSnapshot(ctx context.Context) (io.ReadCloser, error)
- func (i *Index) Index(ctx context.Context, document model.Document, funcs ...index.OptionFunc) error
- func (i *Index) RestoreSnapshot(ctx context.Context, r io.Reader) error
- func (i *Index) Search(ctx context.Context, query string, opts index.SearchOptions) ([]*index.SearchResult, error)
- func (i *Index) SearchFiltered(ctx context.Context, query string, filter index.Filter, ...) ([]*index.SearchResult, error)
- type OptionFunc
- type Options
- type SnapshottedMetadata
- type SnapshottedRecord
Constants ¶
const DefaultVectorSize int = 768
DefaultVectorSize is the default dimension of the pgvector column, consistent with the sqlitevec backend.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Index ¶
type Index struct {
// contains filtered or unexported fields
}
func NewIndex ¶
NewIndex creates a hybrid PostgreSQL index on top of the given pool. The pool remains owned by the caller. A nil llm.Client disables the vector leg (full-text search only).
func (*Index) DeleteByID ¶
DeleteByID implements index.Index.
func (*Index) DeleteBySource ¶
DeleteBySource implements index.Index.
func (*Index) GenerateSnapshot ¶
GenerateSnapshot implements backup.Snapshotable.
func (*Index) Index ¶
func (i *Index) Index(ctx context.Context, document model.Document, funcs ...index.OptionFunc) error
Index implements index.Index.
func (*Index) RestoreSnapshot ¶
RestoreSnapshot implements backup.Snapshotable.
func (*Index) Search ¶
func (i *Index) Search(ctx context.Context, query string, opts index.SearchOptions) ([]*index.SearchResult, error)
Search implements index.Index.
func (*Index) SearchFiltered ¶ added in v0.7.0
func (i *Index) SearchFiltered(ctx context.Context, query string, filter index.Filter, opts index.SearchOptions) ([]*index.SearchResult, error)
SearchFiltered implements index.FilterableIndex: the metadata filter is applied inside both legs, before their fusion. Filtering after the fusion would let a selective filter empty a leg's top-k — the very problem the capability exists to solve — so each leg returns its own k matching rows.
The translation is validated against the shared conformance suite (index/filtertest), which is what allows this index to advertise the capability.
type OptionFunc ¶
type OptionFunc func(opts *Options)
func WithEmbeddingsModel ¶
func WithEmbeddingsModel(model string) OptionFunc
func WithMaxWords ¶
func WithMaxWords(maxWords int) OptionFunc
func WithTextSearchConfig ¶
func WithTextSearchConfig(config string) OptionFunc
func WithVectorSize ¶
func WithVectorSize(size int) OptionFunc
type Options ¶
type Options struct {
// EmbeddingsModel identifies the embeddings model; snapshots generated
// with a different model are rejected on restore.
EmbeddingsModel string
// VectorSize is the dimension of the pgvector column. Larger embeddings
// are truncated then re-normalized (matryoshka-style).
VectorSize int
// MaxWords bounds the size of the chunks sent to the embeddings model.
MaxWords int
// TextSearchConfig is the regconfig used when language detection is
// inconclusive (default "simple").
TextSearchConfig string
}
func NewOptions ¶
func NewOptions(funcs ...OptionFunc) *Options