storage

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
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) Count

func (s *OpenSearchStore) Count(ctx context.Context, filters map[string]any) (int, error)

Count counts documents matching the filters

func (*OpenSearchStore) Delete

func (s *OpenSearchStore) Delete(ctx context.Context, id string) error

Delete deletes a document by ID

func (*OpenSearchStore) DeleteByQuery

func (s *OpenSearchStore) DeleteByQuery(ctx context.Context, filters map[string]any) (int, error)

DeleteByQuery deletes documents matching the filters

func (*OpenSearchStore) Get

func (s *OpenSearchStore) Get(ctx context.Context, id string) (map[string]any, error)

Get retrieves a document by ID

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

func (s *OpenSearchStore) Store(ctx context.Context, id string, doc map[string]any) error

Store stores a document with the given ID The doc map should contain all fields including "embedding" as []float32

func (*OpenSearchStore) Update

func (s *OpenSearchStore) Update(ctx context.Context, id string, doc map[string]any) error

Update updates a document (upsert)

func (*OpenSearchStore) UpdateFields

func (s *OpenSearchStore) UpdateFields(ctx context.Context, id string, fields map[string]any) error

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.

Jump to

Keyboard shortcuts

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