redis

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package redis 提供基于 RediSearch 的消息检索 依赖 Redis Stack(>= 7.0)的 RediSearch 模块

Package redis 提供基于 Redis 的消息存储 纯 Hash 存储,不涉及检索逻辑

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DocStore

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

DocStore 基于 Redis 的通用文档存储

func NewDocStore

func NewDocStore(store *Store) *DocStore

NewDocStore 创建通用文档存储

func (*DocStore) Close

func (d *DocStore) Close() error

func (*DocStore) DeleteCollection

func (d *DocStore) DeleteCollection(ctx context.Context, collection string) error

func (*DocStore) GetDocuments

func (d *DocStore) GetDocuments(ctx context.Context, collection string) ([]*schema.Document, error)

func (*DocStore) RecallDocuments

func (d *DocStore) RecallDocuments(ctx context.Context, collection string, query string, topK int) ([]*schema.Document, error)

func (*DocStore) SaveDocuments

func (d *DocStore) SaveDocuments(ctx context.Context, collection string, docs []*schema.Document) error

type EmbeddingFunc

type EmbeddingFunc func(ctx context.Context, text string) ([]float32, error)

type IndexItem

type IndexItem struct {
	ID        string
	SessionID string
	Role      string
	Content   string
	Timestamp int64
	Embedding []float32
}

IndexItem 用于重建索引的数据项

type Retriever

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

Retriever 基于 RediSearch 的检索器

func NewRetriever

func NewRetriever(config *RetrieverConfig, embedding EmbeddingFunc) (*Retriever, error)

func NewRetrieverFromStore

func NewRetrieverFromStore(store *Store, config *RetrieverConfig, embedding EmbeddingFunc) (*Retriever, error)

NewRetrieverFromStore 从已有 Store 创建 Retriever(共享连接)

func (*Retriever) AddToIndex

func (r *Retriever) AddToIndex(ctx context.Context, id string, content string, embedding []float32) error

func (*Retriever) Close

func (r *Retriever) Close() error

func (*Retriever) IndexReady

func (r *Retriever) IndexReady() bool

func (*Retriever) RebuildIndex

func (r *Retriever) RebuildIndex(ctx context.Context, msgs []IndexItem) error

func (*Retriever) Recall

func (r *Retriever) Recall(ctx context.Context, sessionID string, query string, topK int) ([]*schema.Message, error)

func (*Retriever) RemoveFromIndex

func (r *Retriever) RemoveFromIndex(ctx context.Context, sessionID string) error

type RetrieverConfig

type RetrieverConfig struct {
	Addr      string
	Password  string
	DB        int
	KeyPrefix string // 默认 "pulse:"
	IndexName string // 默认 "pulse:idx"
	VectorDim int    // 默认 768
}

RetrieverConfig RediSearch 检索配置

func DefaultRetrieverConfig

func DefaultRetrieverConfig() *RetrieverConfig

type Store

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

Store 纯 Redis Hash 消息存储

func NewStore

func NewStore(config *StoreConfig) (*Store, error)

func (*Store) ClearSession

func (s *Store) ClearSession(ctx context.Context, sessionID string) error

func (*Store) Close

func (s *Store) Close() error

func (*Store) GetClient

func (s *Store) GetClient() *redis.Client

GetClient 获取底层 Redis 客户端(供 Retriever 使用)

func (*Store) GetKeyPrefix

func (s *Store) GetKeyPrefix() string

GetKeyPrefix 获取键前缀

func (*Store) GetSession

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

func (*Store) Save

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

type StoreConfig

type StoreConfig struct {
	Addr      string // 默认 "localhost:6379"
	Password  string
	DB        int
	KeyPrefix string // 默认 "pulse:"
}

StoreConfig Redis 存储配置

func DefaultStoreConfig

func DefaultStoreConfig() *StoreConfig

Jump to

Keyboard shortcuts

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