Documentation
¶
Index ¶
- Variables
- func ApplyFilters(docs []interfaces.Document, filterGroup MetadataFilterGroup) []interfaces.Document
- func CreateWeaviateAndFilter(conditions ...map[string]interface{}) map[string]interface{}
- func CreateWeaviateFilter(field string, operator string, value interface{}) map[string]interface{}
- func CreateWeaviateOrFilter(conditions ...map[string]interface{}) map[string]interface{}
- func FilterToMap(group MetadataFilterGroup) map[string]interface{}
- func FilterToWeaviateFormat(group MetadataFilterGroup) map[string]interface{}
- type Client
- type EmbeddingConfig
- type MetadataFilter
- type MetadataFilterGroup
- type OpenAIEmbedder
- func (e *OpenAIEmbedder) CalculateSimilarity(vec1, vec2 []float32, metric string) (float32, error)
- func (e *OpenAIEmbedder) Embed(ctx context.Context, text string) ([]float32, error)
- func (e *OpenAIEmbedder) EmbedBatch(ctx context.Context, texts []string) ([][]float32, error)
- func (e *OpenAIEmbedder) EmbedBatchWithConfig(ctx context.Context, texts []string, config EmbeddingConfig) ([][]float32, error)
- func (e *OpenAIEmbedder) EmbedWithConfig(ctx context.Context, text string, config EmbeddingConfig) ([]float32, error)
- func (e *OpenAIEmbedder) GetConfig() EmbeddingConfig
Constants ¶
This section is empty.
Variables ¶
var DefaultTimeFormats = []string{ time.RFC3339, "2006-01-02T15:04:05", "2006-01-02 15:04:05", "2006-01-02", }
DefaultTimeFormats provides a list of common time formats for parsing
Functions ¶
func ApplyFilters ¶
func ApplyFilters(docs []interfaces.Document, filterGroup MetadataFilterGroup) []interfaces.Document
ApplyFilters filters a list of documents based on metadata filters
func CreateWeaviateAndFilter ¶
CreateWeaviateAndFilter creates a Weaviate filter with AND logic for multiple conditions. This is a convenience function for common filter cases.
func CreateWeaviateFilter ¶
CreateWeaviateFilter creates a simple Weaviate filter for a single field. This is a convenience function for simple filter cases. For complex filters, use MetadataFilterGroup and FilterToWeaviateFormat.
func CreateWeaviateOrFilter ¶
CreateWeaviateOrFilter creates a Weaviate filter with OR logic for multiple conditions. This is a convenience function for common filter cases.
func FilterToMap ¶
func FilterToMap(group MetadataFilterGroup) map[string]interface{}
FilterToMap converts a MetadataFilterGroup to a map for use with vector store filters Deprecated: This function produces a format that may not be compatible with all vector stores. For Weaviate, use FilterToWeaviateFormat instead.
func FilterToWeaviateFormat ¶
func FilterToWeaviateFormat(group MetadataFilterGroup) map[string]interface{}
FilterToWeaviateFormat converts a MetadataFilterGroup to a Weaviate-compatible filter format. This is the recommended function to use for Weaviate vector store filters.
Types ¶
type Client ¶
type Client interface {
// Embed generates an embedding for the given text
Embed(ctx context.Context, text string) ([]float32, error)
// EmbedWithConfig generates an embedding with custom configuration
EmbedWithConfig(ctx context.Context, text string, config EmbeddingConfig) ([]float32, error)
// EmbedBatch generates embeddings for multiple texts
EmbedBatch(ctx context.Context, texts []string) ([][]float32, error)
// EmbedBatchWithConfig generates embeddings for multiple texts with custom configuration
EmbedBatchWithConfig(ctx context.Context, texts []string, config EmbeddingConfig) ([][]float32, error)
// CalculateSimilarity calculates the similarity between two embeddings
CalculateSimilarity(vec1, vec2 []float32, metric string) (float32, error)
}
Client defines the interface for an embedding client
type EmbeddingConfig ¶
type EmbeddingConfig struct {
// Model is the embedding model to use
Model string
// Dimensions specifies the dimensionality of the embedding vectors
// Only supported by some models (e.g., text-embedding-3-*)
Dimensions int
// EncodingFormat specifies the format of the embedding vectors
// Options: "float", "base64"
EncodingFormat string
// Truncation controls how the input text is handled if it exceeds the model's token limit
// Options: "none" (error on overflow), "truncate" (truncate to limit)
Truncation string
// SimilarityMetric specifies the similarity metric to use when comparing embeddings
// Options: "cosine" (default), "euclidean", "dot_product"
SimilarityMetric string
// SimilarityThreshold specifies the minimum similarity score for search results
SimilarityThreshold float32
// UserID is an optional identifier for tracking embedding usage
UserID string
}
EmbeddingConfig contains configuration options for embedding generation
func DefaultEmbeddingConfig ¶
func DefaultEmbeddingConfig(model string) EmbeddingConfig
DefaultEmbeddingConfig returns a default configuration for embedding generation
type MetadataFilter ¶
type MetadataFilter struct {
// Field is the metadata field to filter on
Field string
// Operator is the comparison operator
// Supported operators: "=", "!=", ">", ">=", "<", "<=", "contains", "in", "not_in"
Operator string
// Value is the value to compare against
Value interface{}
}
MetadataFilter represents a filter condition for document metadata. It defines a single condition to be applied on a specific field. Example: field="word_count", operator=">", value=10
func NewMetadataFilter ¶
func NewMetadataFilter(field, operator string, value interface{}) MetadataFilter
NewMetadataFilter creates a new metadata filter
type MetadataFilterGroup ¶
type MetadataFilterGroup struct {
// Filters is the list of filters in this group
Filters []MetadataFilter
// SubGroups is the list of sub-groups in this group
SubGroups []MetadataFilterGroup
// Operator is the logical operator to apply between filters
// Supported operators: "and", "or"
Operator string
}
MetadataFilterGroup represents a group of filters with a logical operator. It allows for complex nested conditions with AND/OR logic. Example: (word_count > 10 AND type = "article") OR (category IN ["news", "blog"])
func NewMetadataFilterGroup ¶
func NewMetadataFilterGroup(operator string, filters ...MetadataFilter) MetadataFilterGroup
NewMetadataFilterGroup creates a new metadata filter group
func (*MetadataFilterGroup) AddFilter ¶
func (g *MetadataFilterGroup) AddFilter(filter MetadataFilter)
AddFilter adds a filter to the group
func (*MetadataFilterGroup) AddSubGroup ¶
func (g *MetadataFilterGroup) AddSubGroup(subGroup MetadataFilterGroup)
AddSubGroup adds a sub-group to the group
type OpenAIEmbedder ¶
type OpenAIEmbedder struct {
// contains filtered or unexported fields
}
OpenAIEmbedder implements embedding generation using OpenAI API
func NewOpenAIEmbedder ¶
func NewOpenAIEmbedder(apiKey, model string) *OpenAIEmbedder
NewOpenAIEmbedder creates a new OpenAIEmbedder instance with default configuration
func NewOpenAIEmbedderWithConfig ¶
func NewOpenAIEmbedderWithConfig(apiKey string, config EmbeddingConfig) *OpenAIEmbedder
NewOpenAIEmbedderWithConfig creates a new OpenAIEmbedder with custom configuration
func (*OpenAIEmbedder) CalculateSimilarity ¶
func (e *OpenAIEmbedder) CalculateSimilarity(vec1, vec2 []float32, metric string) (float32, error)
CalculateSimilarity calculates the similarity between two embeddings
func (*OpenAIEmbedder) Embed ¶
Embed generates an embedding using OpenAI API with default configuration
func (*OpenAIEmbedder) EmbedBatch ¶
EmbedBatch generates embeddings for multiple texts using default configuration
func (*OpenAIEmbedder) EmbedBatchWithConfig ¶
func (e *OpenAIEmbedder) EmbedBatchWithConfig(ctx context.Context, texts []string, config EmbeddingConfig) ([][]float32, error)
EmbedBatchWithConfig generates embeddings for multiple texts with custom configuration
func (*OpenAIEmbedder) EmbedWithConfig ¶
func (e *OpenAIEmbedder) EmbedWithConfig(ctx context.Context, text string, config EmbeddingConfig) ([]float32, error)
EmbedWithConfig generates an embedding using OpenAI API with custom configuration
func (*OpenAIEmbedder) GetConfig ¶
func (e *OpenAIEmbedder) GetConfig() EmbeddingConfig
GetConfig returns the current configuration