postgres

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EmbeddingModel

type EmbeddingModel interface {
	Embed(ctx context.Context, text string) ([]float32, error)
	Dimension() int
}

EmbeddingModel is an interface for generating embeddings from text.

type OpenAICompatibleEmbedding

type OpenAICompatibleEmbedding struct {
	BaseURL string // e.g., "https://api.openai.com/v1", "http://localhost:11434/v1"
	APIKey  string // optional, not required for local models
	Model   string // e.g., "text-embedding-3-small", "nomic-embed-text"

	// HTTPClient allows customizing the HTTP client used for requests.
	// If nil, http.DefaultClient is used.
	HTTPClient *http.Client
	// contains filtered or unexported fields
}

OpenAICompatibleEmbedding implements EmbeddingModel using the OpenAI embeddings API format. This is the de facto standard supported by: OpenAI, Ollama (/v1), Azure OpenAI, vLLM, LocalAI, LiteLLM, etc.

func NewOpenAICompatibleEmbedding

func NewOpenAICompatibleEmbedding(cfg OpenAICompatibleEmbeddingConfig) *OpenAICompatibleEmbedding

NewOpenAICompatibleEmbedding creates a new embedding model using OpenAI-compatible API. Works with OpenAI, Ollama, vLLM, LocalAI, LiteLLM, Azure OpenAI, etc.

func (*OpenAICompatibleEmbedding) Dimension

func (e *OpenAICompatibleEmbedding) Dimension() int

Dimension returns the embedding dimension. Returns 0 if not yet known (will be auto-detected on first Embed call).

func (*OpenAICompatibleEmbedding) Embed

func (e *OpenAICompatibleEmbedding) Embed(ctx context.Context, text string) ([]float32, error)

Embed generates an embedding vector for the given text.

type OpenAICompatibleEmbeddingConfig

type OpenAICompatibleEmbeddingConfig struct {
	BaseURL   string
	APIKey    string
	Model     string
	Dimension int // optional, will be auto-detected on first call if 0

	// HTTPClient allows customizing the HTTP client used for requests.
	// Useful for testing with mock servers.
	HTTPClient *http.Client
}

OpenAICompatibleEmbeddingConfig holds configuration for the embedding model.

type PostgresMemoryService

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

PostgresMemoryService implements memory.Service using PostgreSQL with pgvector.

func NewPostgresMemoryService

func NewPostgresMemoryService(ctx context.Context, cfg PostgresMemoryServiceConfig) (*PostgresMemoryService, error)

NewPostgresMemoryService creates a new PostgreSQL-backed memory service.

func (*PostgresMemoryService) AddSession

func (s *PostgresMemoryService) AddSession(ctx context.Context, sess session.Session) error

AddSession extracts memory entries from a session and stores them.

func (*PostgresMemoryService) Close

func (s *PostgresMemoryService) Close() error

Close closes the database connection.

func (*PostgresMemoryService) DB

func (s *PostgresMemoryService) DB() *sql.DB

DB returns the underlying database connection for testing purposes.

func (*PostgresMemoryService) DeleteMemory added in v0.2.0

func (s *PostgresMemoryService) DeleteMemory(ctx context.Context, appName, userID string, entryID int) error

DeleteMemory deletes a memory entry by ID, scoped to app and user.

func (*PostgresMemoryService) Search

Search finds relevant memory entries for a query.

func (*PostgresMemoryService) SearchWithID added in v0.2.0

SearchWithID finds relevant memory entries including their database IDs.

func (*PostgresMemoryService) UpdateMemory added in v0.2.0

func (s *PostgresMemoryService) UpdateMemory(ctx context.Context, appName, userID string, entryID int, newContent string) error

UpdateMemory updates the content of a memory entry by ID, scoped to app and user.

type PostgresMemoryServiceConfig

type PostgresMemoryServiceConfig struct {
	// ConnString is the PostgreSQL connection string
	// e.g., "postgres://user:pass@localhost:5432/dbname?sslmode=disable"
	ConnString string
	// EmbeddingModel is used to generate embeddings for semantic search (optional)
	EmbeddingModel EmbeddingModel
}

PostgresMemoryServiceConfig holds configuration for PostgresMemoryService.

Jump to

Keyboard shortcuts

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