Documentation
¶
Index ¶
- Constants
- func Init(cfg OpenSearchConfig) error
- type OpenSearchConfig
- type OpenSearchStore
- func (s *OpenSearchStore) Close() error
- func (s *OpenSearchStore) Count(ctx context.Context, filters map[string]any) (int, error)
- func (s *OpenSearchStore) Delete(ctx context.Context, id string) error
- func (s *OpenSearchStore) DeleteByQuery(ctx context.Context, filters map[string]any) (int, error)
- func (s *OpenSearchStore) Get(ctx context.Context, id string) (map[string]any, error)
- func (s *OpenSearchStore) Search(ctx context.Context, query SearchQuery) ([]map[string]any, error)
- func (s *OpenSearchStore) Store(ctx context.Context, id string, doc map[string]any) error
- func (s *OpenSearchStore) Update(ctx context.Context, id string, doc map[string]any) error
- func (s *OpenSearchStore) UpdateFields(ctx context.Context, id string, fields map[string]any) error
- type SearchQuery
- type VectorStore
Constants ¶
const ( StatusActive = "active" StatusArchived = "archived" StatusDeleted = "deleted" )
Document status constants for soft delete
Variables ¶
This section is empty.
Functions ¶
func Init ¶
func Init(cfg OpenSearchConfig) error
Init initializes the OpenSearch store singleton with config.
Types ¶
type OpenSearchConfig ¶
type OpenSearchConfig struct {
Addresses []string `toml:"addresses"`
Username string `toml:"username"`
Password string `toml:"password"`
IndexName string `toml:"index"`
EmbeddingDim int `toml:"embedding_dim"`
InsecureSSL bool `toml:"insecure_ssl"`
}
OpenSearchConfig holds OpenSearch configuration
func (*OpenSearchConfig) Validate ¶
func (c *OpenSearchConfig) Validate() error
Validate checks OpenSearch configuration
type OpenSearchStore ¶
type OpenSearchStore struct {
// contains filtered or unexported fields
}
OpenSearchStore implements a generic vector store using OpenSearch k-NN
func NewOpenSearchStore ¶
func NewOpenSearchStore(cfg OpenSearchConfig) (*OpenSearchStore, error)
NewOpenSearchStore creates a new OpenSearch store
func NewStore ¶
func NewStore() *OpenSearchStore
NewStore returns the singleton OpenSearch store instance.
func (*OpenSearchStore) Close ¶
func (s *OpenSearchStore) Close() error
Close closes the OpenSearch connection
func (*OpenSearchStore) Delete ¶
func (s *OpenSearchStore) Delete(ctx context.Context, id string) error
Delete deletes a document by ID
func (*OpenSearchStore) DeleteByQuery ¶
DeleteByQuery deletes documents matching the filters
func (*OpenSearchStore) Search ¶
func (s *OpenSearchStore) Search(ctx context.Context, query SearchQuery) ([]map[string]any, error)
Search searches for documents based on query
func (*OpenSearchStore) Store ¶
Store stores a document with the given ID The doc map should contain all fields including "embedding" as []float32
func (*OpenSearchStore) UpdateFields ¶
UpdateFields updates specific fields using a script
type SearchQuery ¶
type SearchQuery struct {
// Filters for exact match (field -> value)
Filters map[string]any
// TermsFilters for multi-value match (field -> []values)
TermsFilters map[string][]string
// RangeFilters for range queries (field -> {gte/lte/gt/lt -> value})
RangeFilters map[string]map[string]any
// Embedding vector for k-NN search
Embedding []float32
// TextQuery for full-text search (searches raw_content and content fields)
TextQuery string
// HybridSearch enables combining vector and text search
// When true and both Embedding and TextQuery are provided, uses hybrid search
HybridSearch bool
// Score threshold for filtering results
ScoreThreshold float64
// Limit on results
Limit int
}
SearchQuery represents a generic search query
type VectorStore ¶
type VectorStore interface {
// Store stores a document with the given ID
Store(ctx context.Context, id string, doc map[string]any) error
// Get retrieves a document by ID
Get(ctx context.Context, id string) (map[string]any, error)
// Search searches for documents based on query
Search(ctx context.Context, query SearchQuery) ([]map[string]any, error)
// Delete deletes a document by ID
Delete(ctx context.Context, id string) error
// DeleteByQuery deletes documents matching the filters
DeleteByQuery(ctx context.Context, filters map[string]any) (int, error)
// Count counts documents matching the filters
Count(ctx context.Context, filters map[string]any) (int, error)
// Update updates a document (upsert)
Update(ctx context.Context, id string, doc map[string]any) error
// UpdateFields updates specific fields of a document
UpdateFields(ctx context.Context, id string, fields map[string]any) error
// Close closes the storage connection
Close() error
}
VectorStore defines the generic interface for vector storage backends. All methods work with map[string]any for maximum flexibility. Domain-specific types should be converted at the application layer.