Documentation
¶
Overview ¶
Package backends provides database backend implementations.
Package backends provides database backend implementations.
Package backends provides database backend implementations.
Index ¶
- func GetPostgreSQLSchema() string
- func GetSQLiteSchema() string
- type InMemoryVectorStore
- type PgVectorStore
- func (s *PgVectorStore) Count(collection string) (int, error)
- func (s *PgVectorStore) Delete(collection string, id string) error
- func (s *PgVectorStore) DeleteCollection(collection string) error
- func (s *PgVectorStore) Insert(collection string, id string, vector []float32, metadata map[string]any, ...) error
- func (s *PgVectorStore) Search(collection string, vector []float32, k int, filter map[string]any) ([]SearchResult, error)
- func (s *PgVectorStore) SupportsVector() bool
- type PostgreSQLBackend
- type PostgreSQLConfig
- type PostgreSQLHealthChecker
- type PostgreSQLMigrator
- type SQLiteBackend
- type SQLiteConfig
- type SQLiteHealthChecker
- type SQLiteMigrator
- type SearchResult
- type VectorConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetPostgreSQLSchema ¶
func GetPostgreSQLSchema() string
GetPostgreSQLSchema returns the PostgreSQL schema DDL.
Types ¶
type InMemoryVectorStore ¶
type InMemoryVectorStore struct {
// contains filtered or unexported fields
}
InMemoryVectorStore provides in-memory vector search for SQLite.
func NewInMemoryVectorStore ¶
func NewInMemoryVectorStore() *InMemoryVectorStore
NewInMemoryVectorStore creates a new in-memory vector store.
func (*InMemoryVectorStore) Count ¶
func (s *InMemoryVectorStore) Count() int
Count returns the number of vectors in the store.
func (*InMemoryVectorStore) Delete ¶
func (s *InMemoryVectorStore) Delete(id string) error
Delete removes a vector from the store.
func (*InMemoryVectorStore) Insert ¶
func (s *InMemoryVectorStore) Insert(id string, vector []float32, metadata map[string]any, text string) error
Insert adds a vector to the store.
func (*InMemoryVectorStore) Search ¶
func (s *InMemoryVectorStore) Search(vector []float32, k int) ([]SearchResult, error)
Search performs a similarity search.
type PgVectorStore ¶
type PgVectorStore struct {
// contains filtered or unexported fields
}
PgVectorStore implements vector operations using pgvector extension.
func NewPgVectorStore ¶
func NewPgVectorStore(db *sql.DB, config VectorConfig, logger *slog.Logger) (*PgVectorStore, error)
NewPgVectorStore creates a new pgvector store.
func (*PgVectorStore) Count ¶
func (s *PgVectorStore) Count(collection string) (int, error)
Count returns the number of vectors in a collection.
func (*PgVectorStore) Delete ¶
func (s *PgVectorStore) Delete(collection string, id string) error
Delete removes a vector.
func (*PgVectorStore) DeleteCollection ¶
func (s *PgVectorStore) DeleteCollection(collection string) error
DeleteCollection removes all vectors from a collection.
func (*PgVectorStore) Insert ¶
func (s *PgVectorStore) Insert(collection string, id string, vector []float32, metadata map[string]any, text string) error
Insert adds a vector with metadata.
func (*PgVectorStore) Search ¶
func (s *PgVectorStore) Search(collection string, vector []float32, k int, filter map[string]any) ([]SearchResult, error)
Search performs a similarity search.
func (*PgVectorStore) SupportsVector ¶
func (s *PgVectorStore) SupportsVector() bool
SupportsVector returns true.
type PostgreSQLBackend ¶
type PostgreSQLBackend struct {
DB *sql.DB
Config PostgreSQLConfig
// Migrator handles schema migrations
Migrator *PostgreSQLMigrator
// Health checker
Health *PostgreSQLHealthChecker
// Vector store (pgvector)
Vector *PgVectorStore
// contains filtered or unexported fields
}
PostgreSQLBackend wraps the PostgreSQL database connection.
func OpenPostgreSQL ¶
func OpenPostgreSQL(config PostgreSQLConfig, logger *slog.Logger) (*PostgreSQLBackend, error)
OpenPostgreSQL opens or creates a PostgreSQL database connection.
func (*PostgreSQLBackend) Close ¶
func (b *PostgreSQLBackend) Close() error
Close closes the database connection.
type PostgreSQLConfig ¶
type PostgreSQLConfig struct {
Host string
Port int
Database string
User string
Password string
SSLMode string
MaxOpenConns int
MaxIdleConns int
ConnMaxLifetime time.Duration
ConnMaxIdleTime time.Duration
// Supabase-specific
SupabaseURL string
SupabaseAnonKey string
// Vector config
Vector VectorConfig
}
PostgreSQLConfig holds PostgreSQL-specific configuration.
type PostgreSQLHealthChecker ¶
type PostgreSQLHealthChecker struct {
// contains filtered or unexported fields
}
PostgreSQLHealthChecker monitors PostgreSQL database health.
func NewPostgreSQLHealthChecker ¶
func NewPostgreSQLHealthChecker(db *sql.DB) *PostgreSQLHealthChecker
NewPostgreSQLHealthChecker creates a new health checker.
func (*PostgreSQLHealthChecker) Ping ¶
func (h *PostgreSQLHealthChecker) Ping() error
Ping checks database connectivity.
type PostgreSQLMigrator ¶
type PostgreSQLMigrator struct {
// contains filtered or unexported fields
}
PostgreSQLMigrator handles schema migrations for PostgreSQL.
func NewPostgreSQLMigrator ¶
func NewPostgreSQLMigrator(db *sql.DB) *PostgreSQLMigrator
NewPostgreSQLMigrator creates a new PostgreSQL migrator.
func (*PostgreSQLMigrator) CurrentVersion ¶
func (m *PostgreSQLMigrator) CurrentVersion() (int, error)
CurrentVersion returns the current schema version.
func (*PostgreSQLMigrator) Migrate ¶
func (m *PostgreSQLMigrator) Migrate(target int) error
Migrate applies migrations up to the target version.
func (*PostgreSQLMigrator) NeedsMigration ¶
func (m *PostgreSQLMigrator) NeedsMigration() (bool, error)
NeedsMigration returns true if schema is outdated.
type SQLiteBackend ¶
type SQLiteBackend struct {
DB *sql.DB
Config SQLiteConfig
// Migrator handles schema migrations
Migrator *SQLiteMigrator
// Health checker
Health *SQLiteHealthChecker
// Vector store (in-memory)
Vector *InMemoryVectorStore
}
SQLiteBackend wraps the SQLite database connection with additional functionality.
func OpenSQLite ¶
func OpenSQLite(config SQLiteConfig) (*SQLiteBackend, error)
OpenSQLite opens or creates a SQLite database with the given configuration.
func (*SQLiteBackend) Close ¶
func (b *SQLiteBackend) Close() error
Close closes the database connection.
type SQLiteConfig ¶
SQLiteConfig holds SQLite-specific configuration.
type SQLiteHealthChecker ¶
type SQLiteHealthChecker struct {
// contains filtered or unexported fields
}
SQLiteHealthChecker monitors SQLite database health.
func NewSQLiteHealthChecker ¶
func NewSQLiteHealthChecker(db *sql.DB) *SQLiteHealthChecker
NewSQLiteHealthChecker creates a new health checker.
func (*SQLiteHealthChecker) Ping ¶
func (h *SQLiteHealthChecker) Ping() error
Ping checks database connectivity.
type SQLiteMigrator ¶
type SQLiteMigrator struct {
// contains filtered or unexported fields
}
SQLiteMigrator handles schema migrations for SQLite.
func NewSQLiteMigrator ¶
func NewSQLiteMigrator(db *sql.DB) *SQLiteMigrator
NewSQLiteMigrator creates a new SQLite migrator.
func (*SQLiteMigrator) CurrentVersion ¶
func (m *SQLiteMigrator) CurrentVersion() (int, error)
CurrentVersion returns the current schema version.
func (*SQLiteMigrator) Migrate ¶
func (m *SQLiteMigrator) Migrate(target int) error
Migrate applies migrations up to the target version.
func (*SQLiteMigrator) NeedsMigration ¶
func (m *SQLiteMigrator) NeedsMigration() (bool, error)
NeedsMigration returns true if schema is outdated.
type SearchResult ¶
type SearchResult struct {
ID string `json:"id"`
Score float64 `json:"score"`
Metadata map[string]any `json:"metadata,omitempty"`
Text string `json:"text,omitempty"`
}
SearchResult represents a single vector search result with score and metadata.
type VectorConfig ¶
type VectorConfig struct {
// Enabled activates vector search support
Enabled bool
// Dimensions of the embedding vectors (default: 1536 for OpenAI embeddings)
Dimensions int
// IndexType specifies the index algorithm: "hnsw" or "ivfflat"
IndexType string
// IVFLists is the number of lists for IVFFlat index (default: 100)
IVFLists int
// HNSWM is the M parameter for HNSW index (default: 16)
HNSWM int
}
VectorConfig configures vector search capabilities for database backends. Used by PostgreSQL (pgvector) and future vector-enabled backends.
func DefaultVectorConfig ¶
func DefaultVectorConfig() VectorConfig
DefaultVectorConfig returns the default vector configuration.
func (VectorConfig) Effective ¶
func (c VectorConfig) Effective() VectorConfig
Effective returns a copy with defaults applied for zero fields.