Documentation
¶
Overview ¶
Package vectorstore provides a generic interface for vector stores.
Index ¶
- Variables
- type ClusterCursor
- type Config
- type RedisClusterConfig
- type RedisClusterStore
- func (s *RedisClusterStore) Add(ctx context.Context, key string, value string, ttl time.Duration) error
- func (s *RedisClusterStore) Close(ctx context.Context) error
- func (s *RedisClusterStore) Delete(ctx context.Context, keys []string) error
- func (s *RedisClusterStore) GetAll(ctx context.Context, pattern string, cursor *string, count int64) ([]string, *string, error)
- func (s *RedisClusterStore) GetChunk(ctx context.Context, contextKey string) (string, error)
- func (s *RedisClusterStore) GetChunks(ctx context.Context, chunkKeys []string) ([]any, error)
- type RedisConfig
- type RedisStore
- func (s *RedisStore) Add(ctx context.Context, key string, value string, ttl time.Duration) error
- func (s *RedisStore) Close(_ context.Context) error
- func (s *RedisStore) Delete(ctx context.Context, keys []string) error
- func (s *RedisStore) GetAll(ctx context.Context, pattern string, cursor *string, count int64) ([]string, *string, error)
- func (s *RedisStore) GetChunk(ctx context.Context, contextKey string) (string, error)
- func (s *RedisStore) GetChunks(ctx context.Context, chunkKeys []string) ([]any, error)
- type VectorStore
- type VectorStoreType
Constants ¶
This section is empty.
Variables ¶
var ErrNotFound = errors.New("vectorstore: not found")
Functions ¶
This section is empty.
Types ¶
type ClusterCursor ¶
ClusterCursor represents the cursor for a Redis Cluster scan operation.
type Config ¶
type Config struct {
Enabled bool `json:"enabled"`
Type VectorStoreType `json:"type"`
Config any `json:"config"`
}
Config represents the configuration for the vector store.
func (*Config) UnmarshalJSON ¶
UnmarshalJSON unmarshals the config from JSON.
type RedisClusterConfig ¶
type RedisClusterConfig struct {
// Connection settings
Addrs []string `json:"addrs"` // Redis cluster node addresses (host:port) - REQUIRED
Username string `json:"username,omitempty"` // Username for Redis AUTH (optional)
Password string `json:"password,omitempty"` // Password for Redis AUTH (optional)
// Cluster specific settings
MaxRedirects int `json:"max_redirects,omitempty"` // Maximum number of retries for cluster redirects (optional)
ReadOnly bool `json:"read_only,omitempty"` // Enable read-only mode (optional)
RouteByLatency bool `json:"route_by_latency,omitempty"` // Route read-only commands by latency (optional)
RouteRandomly bool `json:"route_randomly,omitempty"` // Route read-only commands randomly (optional)
// Connection pool and timeout settings (passed directly to Redis client)
PoolSize int `json:"pool_size,omitempty"` // Maximum number of socket connections (optional)
MinIdleConns int `json:"min_idle_conns,omitempty"` // Minimum number of idle connections (optional)
MaxIdleConns int `json:"max_idle_conns,omitempty"` // Maximum number of idle connections (optional)
ConnMaxLifetime time.Duration `json:"conn_max_lifetime,omitempty"` // Connection maximum lifetime (optional)
ConnMaxIdleTime time.Duration `json:"conn_max_idle_time,omitempty"` // Connection maximum idle time (optional)
DialTimeout time.Duration `json:"dial_timeout,omitempty"` // Timeout for socket connection (optional)
ReadTimeout time.Duration `json:"read_timeout,omitempty"` // Timeout for socket reads (optional)
WriteTimeout time.Duration `json:"write_timeout,omitempty"` // Timeout for socket writes (optional)
ContextTimeout time.Duration `json:"context_timeout,omitempty"` // Timeout for Redis operations (optional)
}
type RedisClusterStore ¶
type RedisClusterStore struct {
// contains filtered or unexported fields
}
RedisClusterStore represents the Redis Cluster vector store.
func (*RedisClusterStore) Add ¶
func (s *RedisClusterStore) Add(ctx context.Context, key string, value string, ttl time.Duration) error
Add adds a value to Redis Cluster.
func (*RedisClusterStore) Close ¶
func (s *RedisClusterStore) Close(ctx context.Context) error
Close closes the Redis Cluster connection.
func (*RedisClusterStore) Delete ¶
func (s *RedisClusterStore) Delete(ctx context.Context, keys []string) error
Delete deletes values from Redis Cluster. Note: When using hash tags like {tag}key1, {tag}key2, all keys will hash to the same slot and multi-key operations will work. Otherwise, handle keys individually.
func (*RedisClusterStore) GetAll ¶
func (s *RedisClusterStore) GetAll(ctx context.Context, pattern string, cursor *string, count int64) ([]string, *string, error)
GetAll retrieves all keys matching a pattern from Redis Cluster. Note: In Redis Cluster, SCAN operations need to be performed on each node
type RedisConfig ¶
type RedisConfig struct {
// Connection settings
Addr string `json:"addr"` // Redis server address (host:port) - REQUIRED
Username string `json:"username,omitempty"` // Username for Redis AUTH (optional)
Password string `json:"password,omitempty"` // Password for Redis AUTH (optional)
DB int `json:"db,omitempty"` // Redis database number (default: 0)
// Connection pool and timeout settings (passed directly to Redis client)
PoolSize int `json:"pool_size,omitempty"` // Maximum number of socket connections (optional)
MinIdleConns int `json:"min_idle_conns,omitempty"` // Minimum number of idle connections (optional)
MaxIdleConns int `json:"max_idle_conns,omitempty"` // Maximum number of idle connections (optional)
ConnMaxLifetime time.Duration `json:"conn_max_lifetime,omitempty"` // Connection maximum lifetime (optional)
ConnMaxIdleTime time.Duration `json:"conn_max_idle_time,omitempty"` // Connection maximum idle time (optional)
DialTimeout time.Duration `json:"dial_timeout,omitempty"` // Timeout for socket connection (optional)
ReadTimeout time.Duration `json:"read_timeout,omitempty"` // Timeout for socket reads (optional)
WriteTimeout time.Duration `json:"write_timeout,omitempty"` // Timeout for socket writes (optional)
ContextTimeout time.Duration `json:"context_timeout,omitempty"` // Timeout for Redis operations (optional)
}
type RedisStore ¶
type RedisStore struct {
// contains filtered or unexported fields
}
RedisStore represents the Redis vector store.
func (*RedisStore) Close ¶
func (s *RedisStore) Close(_ context.Context) error
Close closes the Redis connection.
func (*RedisStore) Delete ¶
func (s *RedisStore) Delete(ctx context.Context, keys []string) error
Delete deletes a value from Redis.
func (*RedisStore) GetAll ¶
func (s *RedisStore) GetAll(ctx context.Context, pattern string, cursor *string, count int64) ([]string, *string, error)
GetAll retrieves all keys matching a pattern from Redis.
type VectorStore ¶
type VectorStore interface {
GetChunk(ctx context.Context, contextKey string) (string, error)
GetChunks(ctx context.Context, chunkKeys []string) ([]any, error)
Add(ctx context.Context, key string, value string, ttl time.Duration) error
Delete(ctx context.Context, keys []string) error
GetAll(ctx context.Context, pattern string, cursor *string, count int64) ([]string, *string, error)
Close(ctx context.Context) error
}
VectorStore represents the interface for the vector store.
func NewVectorStore ¶
func NewVectorStore(ctx context.Context, config *Config, logger schemas.Logger) (VectorStore, error)
NewVectorStore returns a new vector store based on the configuration.
type VectorStoreType ¶
type VectorStoreType string
const ( VectorStoreTypeRedis VectorStoreType = "redis" VectorStoreTypeRedisCluster VectorStoreType = "redis_cluster" )