vector

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package vector defines the interface for pluggable vector storage backends.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Backend

type Backend interface {
	// EmbeddingDimension returns the number of dimensions this backend expects.
	EmbeddingDimension() int

	// Store persists a chunk's embedding.
	Store(ctx context.Context, id string, embedding []float64, metadata map[string]any) error

	// Delete removes a chunk's embedding.
	Delete(ctx context.Context, id string) error

	// Search returns chunk IDs ranked by similarity to the query vector.
	Search(ctx context.Context, query []float64, filter Filter, topK int) ([]SearchResult, error)

	// StoreBatch persists multiple embeddings.
	StoreBatch(ctx context.Context, items []StoreItem) error

	// DeleteBatch removes multiple embeddings.
	DeleteBatch(ctx context.Context, ids []string) error

	// Ping checks backend connectivity.
	Ping(ctx context.Context) error
}

Backend is the interface that all vector store implementations must satisfy.

type Factory added in v0.7.0

type Factory func(config map[string]any) (Backend, error)

Factory creates a Backend from a configuration map.

type Filter

type Filter struct {
	// ChunkIDs restricts search to specific chunks (used for ACL filtering).
	ChunkIDs []string
	// Metadata filters on chunk metadata fields.
	Metadata map[string]any
}

Filter constrains a similarity search.

type Registry added in v0.7.0

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

Registry manages lazy-initialized vector backends keyed by config ID. It holds a fallback backend used when no per-topic config is specified.

func NewRegistry added in v0.7.0

func NewRegistry(fallback Backend) *Registry

NewRegistry creates a new backend registry with the given fallback backend.

func (*Registry) Fallback added in v0.7.0

func (r *Registry) Fallback() Backend

Fallback returns the registry's fallback backend.

func (*Registry) Get added in v0.7.0

func (r *Registry) Get(configID *string) (Backend, error)

Get returns a backend for the given config ID. If configID is nil or empty, the fallback backend is returned.

func (*Registry) GetOrCreate added in v0.7.0

func (r *Registry) GetOrCreate(configID, backendType string, config map[string]any) (Backend, error)

GetOrCreate returns a cached backend for the config ID, or creates one using the registered factory for the given backend type and config map.

func (*Registry) Put added in v0.7.0

func (r *Registry) Put(configID string, backend Backend)

Put registers a live backend for a config ID.

func (*Registry) RegisterFactory added in v0.7.0

func (r *Registry) RegisterFactory(backendType string, factory Factory)

RegisterFactory registers a factory for a backend type (e.g. "pgvector", "qdrant").

func (*Registry) Remove added in v0.7.0

func (r *Registry) Remove(configID string)

Remove evicts a cached backend for a config ID.

type SearchResult

type SearchResult struct {
	ChunkID string
	Score   float64
}

SearchResult is a single result from a similarity search.

type StoreItem

type StoreItem struct {
	ID        string
	Embedding []float64
	Metadata  map[string]any
}

StoreItem represents a single embedding to store in a batch operation.

Directories

Path Synopsis
Package pgvector implements the vector.Backend interface using PostgreSQL with pgvector.
Package pgvector implements the vector.Backend interface using PostgreSQL with pgvector.
Package vectortest provides a reusable conformance test suite for vector backends.
Package vectortest provides a reusable conformance test suite for vector backends.

Jump to

Keyboard shortcuts

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