memory

package
v0.2.31 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2025 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const ConversationIDKey contextKey = "conversation_id"

ConversationIDKey is the key used to store conversation ID in context

Variables

This section is empty.

Functions

func BuildInlineHistoryPrompt added in v0.0.58

func BuildInlineHistoryPrompt(ctx context.Context, prompt string, memory interfaces.Memory, logger logging.Logger) string

BuildInlineHistoryPrompt builds a prompt with conversation history for prompt-based models This is a generic implementation for models that don't have native conversation support

func GetConversationID

func GetConversationID(ctx context.Context) (string, bool)

GetConversationID retrieves the conversation ID from the context

func NewMemoryFromConfig added in v0.2.4

func NewMemoryFromConfig(config map[string]interface{}, llmClient interfaces.LLM) (interfaces.Memory, error)

NewMemoryFromConfig is a convenience function to create memory from config map

func WithConversationID

func WithConversationID(ctx context.Context, conversationID string) context.Context

WithConversationID adds a conversation ID to the context

Types

type ConversationBuffer

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

ConversationBuffer implements a simple in-memory conversation buffer

func NewConversationBuffer

func NewConversationBuffer(options ...Option) *ConversationBuffer

NewConversationBuffer creates a new conversation buffer

func (*ConversationBuffer) AddMessage

func (c *ConversationBuffer) AddMessage(ctx context.Context, message interfaces.Message) error

AddMessage adds a message to the buffer

func (*ConversationBuffer) Clear

func (c *ConversationBuffer) Clear(ctx context.Context) error

Clear clears the buffer for a conversation

func (*ConversationBuffer) GetAllConversations added in v0.1.7

func (c *ConversationBuffer) GetAllConversations(ctx context.Context) ([]string, error)

GetAllConversations returns all conversation IDs

func (*ConversationBuffer) GetAllConversationsAcrossOrgs added in v0.1.7

func (c *ConversationBuffer) GetAllConversationsAcrossOrgs() (map[string][]string, error)

GetAllConversationsAcrossOrgs returns all conversation IDs from all organizations

func (*ConversationBuffer) GetConversationMessages added in v0.1.7

func (c *ConversationBuffer) GetConversationMessages(ctx context.Context, conversationID string) ([]interfaces.Message, error)

GetConversationMessages gets all messages for a specific conversation

func (*ConversationBuffer) GetConversationMessagesAcrossOrgs added in v0.1.7

func (c *ConversationBuffer) GetConversationMessagesAcrossOrgs(conversationID string) ([]interfaces.Message, string, error)

GetConversationMessagesAcrossOrgs finds conversation in any org and returns messages

func (*ConversationBuffer) GetMemoryStatistics added in v0.1.7

func (c *ConversationBuffer) GetMemoryStatistics(ctx context.Context) (totalConversations, totalMessages int, err error)

GetMemoryStatistics returns basic memory statistics

func (*ConversationBuffer) GetMemoryStatisticsAcrossOrgs added in v0.1.7

func (c *ConversationBuffer) GetMemoryStatisticsAcrossOrgs() (totalConversations, totalMessages int, err error)

GetMemoryStatisticsAcrossOrgs returns memory statistics across all organizations

func (*ConversationBuffer) GetMessages

GetMessages retrieves messages from the buffer

type ConversationSummary

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

ConversationSummary implements a memory that summarizes old messages

func NewConversationSummary

func NewConversationSummary(llmClient interfaces.LLM, options ...SummaryOption) *ConversationSummary

NewConversationSummary creates a new conversation summary memory

func (*ConversationSummary) AddMessage

func (c *ConversationSummary) AddMessage(ctx context.Context, message interfaces.Message) error

AddMessage adds a message to the memory

func (*ConversationSummary) Clear

func (c *ConversationSummary) Clear(ctx context.Context) error

Clear clears the memory

func (*ConversationSummary) GetMessages

GetMessages retrieves messages from the memory

type MemoryFactory added in v0.2.4

type MemoryFactory struct{}

MemoryFactory provides factory functions to create memory instances from configuration

func NewMemoryFactory added in v0.2.4

func NewMemoryFactory() *MemoryFactory

NewMemoryFactory creates a new memory factory

func (*MemoryFactory) CreateMemory added in v0.2.4

func (f *MemoryFactory) CreateMemory(config map[string]interface{}, llmClient interfaces.LLM) (interfaces.Memory, error)

CreateMemory creates a memory instance from configuration map

type Option

type Option func(*ConversationBuffer)

Option represents an option for configuring the conversation buffer

func WithMaxSize

func WithMaxSize(size int) Option

WithMaxSize sets the maximum number of messages to store

type RedisConfig added in v0.0.2

type RedisConfig struct {
	// URL is the Redis URL (e.g., "localhost:6379")
	URL string

	// Password is the Redis password
	Password string

	// DB is the Redis database number
	DB int
}

RedisConfig contains configuration for Redis

type RedisMemory

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

RedisMemory implements a Redis-backed memory store

func NewRedisMemory

func NewRedisMemory(client *redis.Client, options ...RedisOption) *RedisMemory

NewRedisMemory creates a new Redis-backed memory store

func NewRedisMemoryFromConfig added in v0.0.2

func NewRedisMemoryFromConfig(config RedisConfig, options ...RedisOption) (*RedisMemory, error)

NewRedisMemoryFromConfig creates a new Redis memory from configuration

func (*RedisMemory) AddMessage

func (r *RedisMemory) AddMessage(ctx context.Context, message interfaces.Message) error

AddMessage adds a message to the memory with improved error handling and retry logic

func (*RedisMemory) Clear

func (r *RedisMemory) Clear(ctx context.Context) error

Clear clears the memory for a conversation

func (*RedisMemory) Close added in v0.0.2

func (r *RedisMemory) Close() error

Close closes the underlying Redis connection

func (*RedisMemory) GetAllConversations added in v0.1.7

func (r *RedisMemory) GetAllConversations(ctx context.Context) ([]string, error)

GetAllConversations returns all conversation IDs for the current org

func (*RedisMemory) GetAllConversationsAcrossOrgs added in v0.1.7

func (r *RedisMemory) GetAllConversationsAcrossOrgs() (map[string][]string, error)

GetAllConversationsAcrossOrgs returns all conversation IDs from all organizations

func (*RedisMemory) GetConversationMessages added in v0.1.7

func (r *RedisMemory) GetConversationMessages(ctx context.Context, conversationID string) ([]interfaces.Message, error)

GetConversationMessages gets all messages for a specific conversation in current org

func (*RedisMemory) GetConversationMessagesAcrossOrgs added in v0.1.7

func (r *RedisMemory) GetConversationMessagesAcrossOrgs(conversationID string) ([]interfaces.Message, string, error)

GetConversationMessagesAcrossOrgs finds conversation in any org and returns messages

func (*RedisMemory) GetMemoryStatistics added in v0.1.7

func (r *RedisMemory) GetMemoryStatistics(ctx context.Context) (totalConversations, totalMessages int, err error)

GetMemoryStatistics returns basic memory statistics for current org

func (*RedisMemory) GetMemoryStatisticsAcrossOrgs added in v0.1.7

func (r *RedisMemory) GetMemoryStatisticsAcrossOrgs() (totalConversations, totalMessages int, err error)

GetMemoryStatisticsAcrossOrgs returns memory statistics across all organizations

func (*RedisMemory) GetMessages

func (r *RedisMemory) GetMessages(ctx context.Context, options ...interfaces.GetMessagesOption) ([]interfaces.Message, error)

GetMessages retrieves messages from the memory with improved filtering and pagination

type RedisOption

type RedisOption func(*RedisMemory)

RedisOption represents an option for configuring the Redis memory

func WithCompression added in v0.0.2

func WithCompression(enabled bool) RedisOption

WithCompression enables compression for stored messages

func WithEncryption added in v0.0.2

func WithEncryption(key []byte) RedisOption

WithEncryption enables encryption for stored messages

func WithKeyPrefix added in v0.0.2

func WithKeyPrefix(prefix string) RedisOption

WithKeyPrefix sets a custom prefix for Redis keys

func WithMaxMessageSize added in v0.0.2

func WithMaxMessageSize(size int) RedisOption

WithMaxMessageSize sets the maximum size for stored messages

func WithRetryOptions added in v0.0.2

func WithRetryOptions(options *RetryOptions) RedisOption

WithRetryOptions configures retry behavior for Redis operations

func WithSummarization added in v0.0.25

func WithSummarization(llm interfaces.LLM, messageThreshold int, summaryCount int) RedisOption

WithSummarization enables automatic summarization of old messages

func WithTTL

func WithTTL(ttl time.Duration) RedisOption

WithTTL sets the TTL for Redis keys

type RetrieverOption

type RetrieverOption func(*VectorStoreRetriever)

RetrieverOption represents an option for configuring the vector store retriever

type RetryOptions added in v0.0.2

type RetryOptions struct {
	MaxRetries    int
	RetryInterval time.Duration
	BackoffFactor float64
}

RetryOptions configures retry behavior for Redis operations

type SummaryOption

type SummaryOption func(*ConversationSummary)

SummaryOption represents an option for configuring the conversation summary

func WithMaxBufferSize

func WithMaxBufferSize(size int) SummaryOption

WithMaxBufferSize sets the maximum number of messages before summarizing

func WithSummaryLength added in v0.0.2

func WithSummaryLength(wordCount int) SummaryOption

WithSummaryLength sets the maximum word count target for summaries

type VectorStoreRetriever

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

VectorStoreRetriever implements a memory that stores messages in a vector store

func NewVectorStoreRetriever

func NewVectorStoreRetriever(vectorStore interfaces.VectorStore, options ...RetrieverOption) *VectorStoreRetriever

NewVectorStoreRetriever creates a new vector store retriever memory

func (*VectorStoreRetriever) AddMessage

func (v *VectorStoreRetriever) AddMessage(ctx context.Context, message interfaces.Message) error

AddMessage adds a message to the memory

func (*VectorStoreRetriever) Clear

func (v *VectorStoreRetriever) Clear(ctx context.Context) error

Clear clears the memory

func (*VectorStoreRetriever) GetMessages

GetMessages retrieves messages from the memory

Jump to

Keyboard shortcuts

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