search

package
v0.2.6 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MatchAny = "any"
	MatchAll = "all"
)
View Source
const (
	HybridStrategyRRF      = "rrf"
	HybridStrategyWeighted = "weighted"
)

Variables

This section is empty.

Functions

func InferKeywords

func InferKeywords(text string) []string

func MatchesKeywords

func MatchesKeywords(text string, keywords []string, match string) (int, bool)

func NormalizeMatch

func NormalizeMatch(match string) string

func SearchText

func SearchText(msg *Message) string

Types

type GormVectorStore

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

func NewGormVectorStore

func NewGormVectorStore(db *gorm.DB, tableName string) (*GormVectorStore, error)

func (*GormVectorStore) Search

func (s *GormVectorStore) Search(ctx context.Context, q *SearchQuery, vector []float64, limit int) ([]*SearchHit, error)

func (*GormVectorStore) Upsert

func (s *GormVectorStore) Upsert(ctx context.Context, msg *Message, vector []float64) error

type HybridConfig

type HybridConfig struct {
	Strategy string
	RRFK     int
	Weights  HybridWeights
}

type HybridSearcher

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

func NewHybridSearcher

func NewHybridSearcher(keyword Searcher, vector Searcher, cfg HybridConfig) *HybridSearcher

func (*HybridSearcher) Index

func (s *HybridSearcher) Index(ctx context.Context, msg *Message) error

func (*HybridSearcher) Reindex

func (s *HybridSearcher) Reindex(ctx context.Context, sessionID, userID string) error

func (*HybridSearcher) Search

func (s *HybridSearcher) Search(ctx context.Context, q *SearchQuery) ([]*SearchHit, error)

type HybridWeights

type HybridWeights struct {
	Keyword float64
	Vector  float64
}

type KeywordSearcher

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

func NewKeywordSearcher

func NewKeywordSearcher(store KeywordStore) *KeywordSearcher

func (*KeywordSearcher) Index

func (*KeywordSearcher) Reindex

func (*KeywordSearcher) Search

func (s *KeywordSearcher) Search(ctx context.Context, q *SearchQuery) ([]*SearchHit, error)

type KeywordStore

type KeywordStore interface {
	MessageSource
	SearchMessagesByKeywords(ctx context.Context, q *SearchQuery) ([]*Message, error)
}

type Message

type Message struct {
	ID        string
	SessionID string
	UserID    string
	Role      string
	Content   string
	Parts     []schema.MessageInputPart
	CreatedAt time.Time
}

func CloneMessage

func CloneMessage(msg *Message) *Message

type MessageSource

type MessageSource interface {
	ListMessages(ctx context.Context, sessionID, userID string) ([]*Message, error)
}

type SearchHit

type SearchHit struct {
	Message *Message
	Score   float64
	Snippet string
}

type SearchMode

type SearchMode string
const (
	ModeKeyword SearchMode = "keyword"
	ModeVector  SearchMode = "vector"
	ModeHybrid  SearchMode = "hybrid"
)

type SearchQuery

type SearchQuery struct {
	SessionID string
	UserID    string

	Since *time.Time
	Until *time.Time
	Role  string
	Limit int

	Keywords []string
	Match    string

	Query string
}

type Searcher

type Searcher interface {
	Search(ctx context.Context, q *SearchQuery) ([]*SearchHit, error)
	Index(ctx context.Context, msg *Message) error
	Reindex(ctx context.Context, sessionID, userID string) error
}

type VectorSearcher

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

func NewVectorSearcher

func NewVectorSearcher(embedder embedding.Embedder, store VectorStore, source MessageSource) (*VectorSearcher, error)

func (*VectorSearcher) Index

func (s *VectorSearcher) Index(ctx context.Context, msg *Message) error

func (*VectorSearcher) Reindex

func (s *VectorSearcher) Reindex(ctx context.Context, sessionID, userID string) error

func (*VectorSearcher) Search

func (s *VectorSearcher) Search(ctx context.Context, q *SearchQuery) ([]*SearchHit, error)

type VectorStore

type VectorStore interface {
	Upsert(ctx context.Context, msg *Message, vector []float64) error
	Search(ctx context.Context, q *SearchQuery, vector []float64, limit int) ([]*SearchHit, error)
}

Jump to

Keyboard shortcuts

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