Documentation
¶
Index ¶
- Constants
- type CompositeSearch
- func (c *CompositeSearch) Clear(ctx context.Context) error
- func (c *CompositeSearch) Delete(ctx context.Context, postIDs []string) error
- func (c *CompositeSearch) DeleteOrphaned(ctx context.Context, nowTime, batchSize int64) (int64, error)
- func (c *CompositeSearch) Search(ctx context.Context, query string, opts SearchOptions) ([]SearchResult, error)
- func (c *CompositeSearch) Store(ctx context.Context, docs []PostDocument) error
- type EmbeddingProvider
- type EmbeddingSearch
- type EmbeddingSearchConfig
- type PostDocument
- type SearchOptions
- type SearchResult
- type UpstreamConfig
- type VectorStore
Constants ¶
const ( ProviderTypeOpenAI = "openai" ProviderTypeOpenAICompatible = "openai-compatible" ProviderTypeMock = "mock" )
Provider types
const (
SearchTypeComposite = "composite"
)
Search types
const (
VectorStoreTypePGVector = "pgvector"
)
Vector store types
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CompositeSearch ¶
type CompositeSearch struct {
// contains filtered or unexported fields
}
CompositeSearch implements EmbeddingSearch using separate vector store and embedding provider
func NewCompositeSearch ¶
func NewCompositeSearch(store VectorStore, provider EmbeddingProvider, options chunking.Options) *CompositeSearch
NewCompositeSearch creates a new CompositeSearch with required chunking options
func (*CompositeSearch) Clear ¶
func (c *CompositeSearch) Clear(ctx context.Context) error
Clear removes all documents and chunks
func (*CompositeSearch) Delete ¶
func (c *CompositeSearch) Delete(ctx context.Context, postIDs []string) error
Delete removes documents and their chunks
func (*CompositeSearch) DeleteOrphaned ¶ added in v1.14.0
func (c *CompositeSearch) DeleteOrphaned(ctx context.Context, nowTime, batchSize int64) (int64, error)
DeleteOrphaned removes embeddings whose posts no longer exist or are past retention.
func (*CompositeSearch) Search ¶
func (c *CompositeSearch) Search(ctx context.Context, query string, opts SearchOptions) ([]SearchResult, error)
Search performs a semantic search and merges results from chunks of the same document
func (*CompositeSearch) Store ¶
func (c *CompositeSearch) Store(ctx context.Context, docs []PostDocument) error
Store chunks documents, generates embeddings, and stores them
type EmbeddingProvider ¶
type EmbeddingProvider interface {
// CreateEmbedding generates embedding for the given text
CreateEmbedding(ctx context.Context, text string) ([]float32, error)
// BatchCreateEmbeddings generates embeddings for multiple texts
BatchCreateEmbeddings(ctx context.Context, texts []string) ([][]float32, error)
// Dimensions returns the dimensionality of the embeddings
Dimensions() int
}
EmbeddingProvider defines the interface for embedding generation
func NewMockEmbeddingProvider ¶ added in v1.7.0
func NewMockEmbeddingProvider(dimensions int) EmbeddingProvider
NewMockEmbeddingProvider creates a new mock embedding provider that produces repeatable vectors.
type EmbeddingSearch ¶
type EmbeddingSearch interface {
// Store stores documents and handles embedding generation internally
Store(ctx context.Context, docs []PostDocument) error
// Search performs a similarity search using the query text
Search(ctx context.Context, query string, opts SearchOptions) ([]SearchResult, error)
// Delete removes documents
Delete(ctx context.Context, postIDs []string) error
// Clear removes all documents
Clear(ctx context.Context) error
// DeleteOrphaned removes embeddings whose posts no longer exist or are past retention.
// nowTime is the retention cutoff (Unix millis), batchSize limits rows deleted per call.
// Returns the number of rows deleted.
DeleteOrphaned(ctx context.Context, nowTime, batchSize int64) (int64, error)
}
EmbeddingSearch defines the high-level interface for storing and searching using embeddings
type EmbeddingSearchConfig ¶
type EmbeddingSearchConfig struct {
Type string `json:"type"`
VectorStore UpstreamConfig `json:"vectorStore"`
EmbeddingProvider UpstreamConfig `json:"embeddingProvider"`
Parameters json.RawMessage `json:"parameters"`
Dimensions int `json:"dimensions"`
ChunkingOptions chunking.Options `json:"chunkingOptions"`
}
ServiceConfig holds configuration for the embedding search service
func (*EmbeddingSearchConfig) GetModelName ¶ added in v1.14.0
func (c *EmbeddingSearchConfig) GetModelName() string
GetModelName extracts the model name from the embedding provider parameters
func (*EmbeddingSearchConfig) GetProviderType ¶ added in v1.14.0
func (c *EmbeddingSearchConfig) GetProviderType() string
GetProviderType returns the embedding provider type
type PostDocument ¶
type PostDocument struct {
PostID string // ID of the Mattermost post
CreateAt int64 // Creation timestamp of the referenced post, not when this was indexed
TeamID string
ChannelID string
UserID string
Content string
// Embed chunk info to track if this is a chunk
chunking.ChunkInfo
}
PostDocument represents a Mattermost post with its metadata
type SearchOptions ¶
type SearchOptions struct {
Limit int
Offset int
MinScore float32
TeamID string
ChannelID string
UserID string // User ID for permission checks
CreatedAfter int64
CreatedBefore int64
}
SearchOptions contains parameters for search operations
type SearchResult ¶
type SearchResult struct {
Document PostDocument
Score float32
}
SearchResult represents a single search result with its similarity score
type UpstreamConfig ¶
type UpstreamConfig struct {
Type string `json:"type"`
Parameters json.RawMessage `json:"parameters"`
}
UpstreamConfig holds configuration for the upstream service
type VectorStore ¶
type VectorStore interface {
// Store stores documents and their embeddings
Store(ctx context.Context, docs []PostDocument, embeddings [][]float32) error
// Search performs a similarity search using the provided embedding
Search(ctx context.Context, embedding []float32, opts SearchOptions) ([]SearchResult, error)
// Delete removes documents from the vector store
Delete(ctx context.Context, postIDs []string) error
// Clear removes all documents from the vector store
Clear(ctx context.Context) error
// DeleteOrphaned removes embeddings whose posts no longer exist or are past retention.
// nowTime is the retention cutoff (Unix millis), batchSize limits rows deleted per call.
// Returns the number of rows deleted.
DeleteOrphaned(ctx context.Context, nowTime, batchSize int64) (int64, error)
}
VectorStore defines the interface for vector storage and search operations