Documentation
¶
Overview ¶
Package store defines constants used for storage and persistence systems.
Index ¶
- Constants
- type EventType
- type InMemoryLangGraphStore
- func (s *InMemoryLangGraphStore) Close() error
- func (s *InMemoryLangGraphStore) Delete(ctx context.Context, namespace []string, key string) error
- func (s *InMemoryLangGraphStore) Get(ctx context.Context, namespace []string, key string) (*StoreValue, error)
- func (s *InMemoryLangGraphStore) List(ctx context.Context, namespace []string) ([]string, error)
- func (s *InMemoryLangGraphStore) ListWithPrefix(ctx context.Context, namespace []string, prefix string) ([]string, error)
- func (s *InMemoryLangGraphStore) Put(ctx context.Context, namespace []string, key string, value interface{}) error
- func (s *InMemoryLangGraphStore) PutWithTTL(ctx context.Context, namespace []string, key string, value interface{}, ...) error
- func (s *InMemoryLangGraphStore) Search(ctx context.Context, namespace []string, query string, limit int) ([]*StoreValue, error)
- func (s *InMemoryLangGraphStore) Update(ctx context.Context, namespace []string, key string, ...) error
- func (s *InMemoryLangGraphStore) Watch(ctx context.Context, namespace []string) (<-chan StoreEvent, error)
- type LangGraphStore
- type Store
- type StoreEvent
- type StoreValue
- type StoreWithCache
- func (s *StoreWithCache) Close() error
- func (s *StoreWithCache) Delete(ctx context.Context, namespace []string, key string) error
- func (s *StoreWithCache) Get(ctx context.Context, namespace []string, key string) (*StoreValue, error)
- func (s *StoreWithCache) List(ctx context.Context, namespace []string) ([]string, error)
- func (s *StoreWithCache) ListWithPrefix(ctx context.Context, namespace []string, prefix string) ([]string, error)
- func (s *StoreWithCache) Put(ctx context.Context, namespace []string, key string, value interface{}) error
- func (s *StoreWithCache) PutWithTTL(ctx context.Context, namespace []string, key string, value interface{}, ...) error
- func (s *StoreWithCache) Search(ctx context.Context, namespace []string, query string, limit int) ([]*StoreValue, error)
- func (s *StoreWithCache) Update(ctx context.Context, namespace []string, key string, ...) error
- func (s *StoreWithCache) Watch(ctx context.Context, namespace []string) (<-chan StoreEvent, error)
- type Value
Constants ¶
const ( // StoreTypeMemory represents in-memory storage StoreTypeMemory = "memory" // StoreTypeRedis represents Redis storage StoreTypeRedis = "redis" // StoreTypePostgres represents PostgreSQL storage StoreTypePostgres = "postgres" // StoreTypeMySQL represents MySQL storage StoreTypeMySQL = "mysql" // StoreTypeSQLite represents SQLite storage StoreTypeSQLite = "sqlite" // StoreTypeMongoDB represents MongoDB storage StoreTypeMongoDB = "mongodb" // StoreTypeFile represents file-based storage StoreTypeFile = "file" // StoreTypeS3 represents AWS S3 storage StoreTypeS3 = "s3" )
Store Types define the available storage backend types.
const ( // OpGet represents a get/read operation OpGet = "get" // OpSet represents a set/write operation OpSet = "set" // OpDelete represents a delete operation OpDelete = "delete" // OpList represents a list operation OpList = "list" // OpUpdate represents an update operation OpUpdate = "update" // OpExists represents an exists check operation OpExists = "exists" // OpClear represents a clear/flush operation OpClear = "clear" )
Store Operations define common storage operations.
const ( // FieldKey represents a database key field FieldKey = "key" // FieldValue represents a database value field FieldValue = "value" // FieldNamespace represents a namespace field FieldNamespace = "namespace" // FieldExpiry represents an expiration time field FieldExpiry = "expiry" // FieldTTL represents time-to-live field FieldTTL = "ttl" // FieldCreatedAt represents creation timestamp FieldCreatedAt = "created_at" // FieldUpdatedAt represents update timestamp FieldUpdatedAt = "updated_at" )
Database Field Names
const ( // DefaultMaxConnections is the default maximum number of connections DefaultMaxConnections = 10 // DefaultMinConnections is the default minimum number of connections DefaultMinConnections = 2 // DefaultConnectionTimeout is the default connection timeout in seconds DefaultConnectionTimeout = 30 // DefaultIdleTimeout is the default idle connection timeout in seconds DefaultIdleTimeout = 300 )
Connection Pool Constants
const ( // RedisDefaultDB is the default Redis database number RedisDefaultDB = 0 // RedisDefaultPort is the default Redis port RedisDefaultPort = 6379 // RedisDefaultMaxRetries is the default maximum retry attempts RedisDefaultMaxRetries = 3 )
Redis-specific Constants
const ( // PostgresDefaultPort is the default PostgreSQL port PostgresDefaultPort = 5432 // PostgresDefaultSSLMode is the default SSL mode PostgresDefaultSSLMode = "disable" )
PostgreSQL-specific Constants
const ( // TxStateActive represents an active transaction TxStateActive = "active" // TxStateCommitted represents a committed transaction TxStateCommitted = "committed" // TxStateRolledBack represents a rolled back transaction TxStateRolledBack = "rolled_back" // TxStateFailed represents a failed transaction TxStateFailed = "failed" )
Transaction States
const ( // SerializationJSON represents JSON serialization SerializationJSON = "json" // SerializationMsgpack represents MessagePack serialization SerializationMsgpack = "msgpack" // SerializationGob represents Go's gob serialization SerializationGob = "gob" // SerializationProtobuf represents Protocol Buffers serialization SerializationProtobuf = "protobuf" )
Serialization Formats
const ( // ErrTypeConnection represents a connection error ErrTypeConnection = "connection_error" // ErrTypeTimeout represents a timeout error ErrTypeTimeout = "timeout_error" // ErrTypeNotFound represents a not found error ErrTypeNotFound = "not_found" // ErrTypeDuplicate represents a duplicate key error ErrTypeDuplicate = "duplicate_error" // ErrTypeSerialization represents a serialization error ErrTypeSerialization = "serialization_error" // ErrTypeTransaction represents a transaction error ErrTypeTransaction = "transaction_error" )
Error Types
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type InMemoryLangGraphStore ¶
type InMemoryLangGraphStore struct {
// contains filtered or unexported fields
}
InMemoryLangGraphStore for development and testing
func NewInMemoryLangGraphStore ¶
func NewInMemoryLangGraphStore() *InMemoryLangGraphStore
NewInMemoryLangGraphStore creates a new in-memory store
func (*InMemoryLangGraphStore) Close ¶
func (s *InMemoryLangGraphStore) Close() error
Close closes the store
func (*InMemoryLangGraphStore) Get ¶
func (s *InMemoryLangGraphStore) Get(ctx context.Context, namespace []string, key string) (*StoreValue, error)
Get retrieves a value
func (*InMemoryLangGraphStore) ListWithPrefix ¶
func (s *InMemoryLangGraphStore) ListWithPrefix(ctx context.Context, namespace []string, prefix string) ([]string, error)
ListWithPrefix returns keys with a specific prefix
func (*InMemoryLangGraphStore) Put ¶
func (s *InMemoryLangGraphStore) Put(ctx context.Context, namespace []string, key string, value interface{}) error
Put stores a value
func (*InMemoryLangGraphStore) PutWithTTL ¶
func (s *InMemoryLangGraphStore) PutWithTTL(ctx context.Context, namespace []string, key string, value interface{}, ttl time.Duration) error
PutWithTTL stores a value with TTL
func (*InMemoryLangGraphStore) Search ¶
func (s *InMemoryLangGraphStore) Search(ctx context.Context, namespace []string, query string, limit int) ([]*StoreValue, error)
Search performs similarity search (simplified for in-memory)
func (*InMemoryLangGraphStore) Update ¶
func (s *InMemoryLangGraphStore) Update(ctx context.Context, namespace []string, key string, updateFunc func(*StoreValue) (*StoreValue, error)) error
Update atomically updates a value
func (*InMemoryLangGraphStore) Watch ¶
func (s *InMemoryLangGraphStore) Watch(ctx context.Context, namespace []string) (<-chan StoreEvent, error)
Watch watches for changes in a namespace
type LangGraphStore ¶
type LangGraphStore interface {
// Put stores a value at the specified namespace and key
Put(ctx context.Context, namespace []string, key string, value interface{}) error
// PutWithTTL stores a value with TTL
PutWithTTL(ctx context.Context, namespace []string, key string, value interface{}, ttl time.Duration) error
// Get retrieves a value from the specified namespace and key
Get(ctx context.Context, namespace []string, key string) (*StoreValue, error)
// Search performs similarity search within a namespace
Search(ctx context.Context, namespace []string, query string, limit int) ([]*StoreValue, error)
// Delete removes a value
Delete(ctx context.Context, namespace []string, key string) error
// List returns all keys in a namespace
List(ctx context.Context, namespace []string) ([]string, error)
// ListWithPrefix returns keys with a specific prefix
ListWithPrefix(ctx context.Context, namespace []string, prefix string) ([]string, error)
// Update atomically updates a value
Update(ctx context.Context, namespace []string, key string, updateFunc func(*StoreValue) (*StoreValue, error)) error
// Watch watches for changes in a namespace
Watch(ctx context.Context, namespace []string) (<-chan StoreEvent, error)
// Close closes the store
Close() error
}
LangGraphStore interface for long-term memory
type Store ¶
type Store interface {
// Put stores a value with the given namespace and key.
Put(ctx context.Context, namespace []string, key string, value interface{}) error
// Get retrieves a value by namespace and key.
Get(ctx context.Context, namespace []string, key string) (*Value, error)
// Delete removes a value by namespace and key.
Delete(ctx context.Context, namespace []string, key string) error
// Search finds values matching the filter within a namespace.
Search(ctx context.Context, namespace []string, filter map[string]interface{}) ([]*Value, error)
// List returns all keys within a namespace.
List(ctx context.Context, namespace []string) ([]string, error)
// Clear removes all values within a namespace.
Clear(ctx context.Context, namespace []string) error
}
Store defines the interface for namespace-based persistent storage.
NOTE: This is a legacy interface with namespace support. For new code, consider using interfaces.Store for simpler key-value storage, or this NamespaceStore for namespace-organized storage.
Inspired by LangChain's Store, it provides:
- Namespace-based organization
- Key-value storage with metadata
- Search capabilities
- Timestamp tracking
Use cases:
- User preferences and settings
- Historical conversation data
- Application-specific persistent data
type StoreEvent ¶
type StoreEvent struct {
Type EventType `json:"type"`
Namespace []string `json:"namespace"`
Key string `json:"key"`
Value *StoreValue `json:"value,omitempty"`
Timestamp time.Time `json:"timestamp"`
Metadata map[string]interface{} `json:"metadata,omitempty"`
}
StoreEvent represents a change event in the store
type StoreValue ¶
type StoreValue struct {
Value interface{} `json:"value"`
Metadata map[string]interface{} `json:"metadata,omitempty"`
Timestamp time.Time `json:"timestamp"`
TTL *time.Duration `json:"ttl,omitempty"`
Version int `json:"version"`
}
StoreValue represents a stored value with metadata
func (*StoreValue) IsExpired ¶
func (v *StoreValue) IsExpired() bool
IsExpired checks if the value has expired
type StoreWithCache ¶
type StoreWithCache struct {
// contains filtered or unexported fields
}
StoreWithCache wraps a store with caching
func NewStoreWithCache ¶
func NewStoreWithCache(backend LangGraphStore, ttl time.Duration) *StoreWithCache
NewStoreWithCache creates a cached store
func (*StoreWithCache) Close ¶
func (s *StoreWithCache) Close() error
Close closes both cache and backend
func (*StoreWithCache) Get ¶
func (s *StoreWithCache) Get(ctx context.Context, namespace []string, key string) (*StoreValue, error)
Get retrieves with cache
func (*StoreWithCache) ListWithPrefix ¶
func (s *StoreWithCache) ListWithPrefix(ctx context.Context, namespace []string, prefix string) ([]string, error)
ListWithPrefix returns keys with prefix from backend
func (*StoreWithCache) Put ¶
func (s *StoreWithCache) Put(ctx context.Context, namespace []string, key string, value interface{}) error
Put stores in both cache and backend
func (*StoreWithCache) PutWithTTL ¶
func (s *StoreWithCache) PutWithTTL(ctx context.Context, namespace []string, key string, value interface{}, ttl time.Duration) error
PutWithTTL stores with TTL in both cache and backend
func (*StoreWithCache) Search ¶
func (s *StoreWithCache) Search(ctx context.Context, namespace []string, query string, limit int) ([]*StoreValue, error)
Search performs search on backend
func (*StoreWithCache) Update ¶
func (s *StoreWithCache) Update(ctx context.Context, namespace []string, key string, updateFunc func(*StoreValue) (*StoreValue, error)) error
Update atomically updates in backend and invalidates cache
func (*StoreWithCache) Watch ¶
func (s *StoreWithCache) Watch(ctx context.Context, namespace []string) (<-chan StoreEvent, error)
Watch watches backend for changes
type Value ¶
type Value struct {
// Value is the stored data
Value interface{} `json:"value"`
// Metadata holds additional information about the value
Metadata map[string]interface{} `json:"metadata"`
// Created is when the value was first created
Created time.Time `json:"created"`
// Updated is when the value was last updated
Updated time.Time `json:"updated"`
// Namespace is the hierarchical namespace path
Namespace []string `json:"namespace"`
// Key is the unique identifier within the namespace
Key string `json:"key"`
}
Value represents a value stored in the Store.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package adapters provides example usage of store adapters
|
Package adapters provides example usage of store adapters |
|
example
command
Package main demonstrates real-world usage of store adapters with common options
|
Package main demonstrates real-world usage of store adapters with common options |