memory

package
v0.0.0-...-6c2c167 Latest Latest
Warning

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

Go to latest
Published: May 8, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeMessages

func DecodeMessages(b []byte) ([]*schema.Message, error)

DecodeMessages deserializes messages previously encoded by EncodeMessages.

func EncodeMessages

func EncodeMessages(msgs []*schema.Message) ([]byte, error)

EncodeMessages serializes messages using Gob.

func NewMiniRedisClient

func NewMiniRedisClient() (*redis.Client, func(), error)

NewMiniRedisClient starts an embedded Redis server for local demos/tests.

Types

type InMemoryStore

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

InMemoryStore keeps serialized messages in a process-local map. Suitable for demos/tests; not shared across processes.

func NewInMemoryStore

func NewInMemoryStore() *InMemoryStore

func (*InMemoryStore) Query

func (s *InMemoryStore) Query(ctx context.Context, sessionID, text string, limit int) ([]*schema.Message, error)

Query performs a simple substring search on message contents for the session.

func (*InMemoryStore) Read

func (s *InMemoryStore) Read(ctx context.Context, sessionID string) ([]*schema.Message, error)

Read returns decoded messages for the given session; returns nil if absent.

func (*InMemoryStore) Write

func (s *InMemoryStore) Write(ctx context.Context, sessionID string, msgs []*schema.Message) error

Write encodes and stores messages for the given key.

type MemoryStore

type MemoryStore interface {
	Write(ctx context.Context, sessionID string, msgs []*schema.Message) error
	Read(ctx context.Context, sessionID string) ([]*schema.Message, error)
	Query(ctx context.Context, sessionID, text string, limit int) ([]*schema.Message, error)
}

MemoryStore persists and restores short-term conversation history. Implementations are responsible for storing a slice of messages under a session key.

type RedisStore

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

RedisStore persists serialized messages in Redis under the provided session key.

func NewRedisStore

func NewRedisStore(cli *redis.Client) *RedisStore

func (*RedisStore) Query

func (s *RedisStore) Query(ctx context.Context, sessionID, text string, limit int) ([]*schema.Message, error)

func (*RedisStore) Read

func (s *RedisStore) Read(ctx context.Context, sessionID string) ([]*schema.Message, error)

Read returns decoded messages from Redis GET; returns nil if not found.

func (*RedisStore) Write

func (s *RedisStore) Write(ctx context.Context, sessionID string, msgs []*schema.Message) error

Write encodes and stores messages using Redis SET.

Jump to

Keyboard shortcuts

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