search

package
v0.0.0-...-b8e807e Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package search provides interfaces and implementations for search operations

Package search provides interfaces and implementations for search operations

Package search provides interfaces and implementations for search operations

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EmbeddingService

type EmbeddingService interface {
	// GenerateEmbedding generates an embedding for the given text
	GenerateEmbedding(ctx context.Context, text string, model string) ([]float32, error)
	// GenerateBatch generates embeddings for multiple texts
	GenerateBatch(ctx context.Context, texts []string, model string) ([][]float32, error)
}

EmbeddingService defines the interface for generating embeddings

type Filter

type Filter map[string]any

Filter defines a filter map for repository operations This avoids importing pkg/repository to prevent import cycles

func FilterFromContentHash

func FilterFromContentHash(contentHash string) Filter

FilterFromContentHash creates a filter for content hash

func FilterFromContentType

func FilterFromContentType(contentType string) Filter

FilterFromContentType creates a filter for content type

type MockRepository

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

MockRepository provides an in-memory implementation of the Repository interface for testing

func (*MockRepository) AddDocument

func (m *MockRepository) AddDocument(id string, content string, docType string, metadata map[string]interface{})

AddDocument adds a document to the mock repository

func (*MockRepository) Create

func (m *MockRepository) Create(ctx context.Context, result *SearchResult) error

Create stores a new search result (standardized Repository method)

func (*MockRepository) Delete

func (m *MockRepository) Delete(ctx context.Context, id string) error

Delete removes a search result by its ID (standardized Repository method)

func (*MockRepository) Get

func (m *MockRepository) Get(ctx context.Context, id string) (*SearchResult, error)

Get retrieves a search result by its ID (standardized Repository method)

func (*MockRepository) GetSearchStats

func (m *MockRepository) GetSearchStats(ctx context.Context) (map[string]interface{}, error)

GetSearchStats retrieves statistics about the search index

func (*MockRepository) GetSupportedModels

func (m *MockRepository) GetSupportedModels(ctx context.Context) ([]string, error)

GetSupportedModels returns a list of models with embeddings

func (*MockRepository) List

func (m *MockRepository) List(ctx context.Context, filter Filter) ([]*SearchResult, error)

List retrieves search results matching the provided filter (standardized Repository method)

func (*MockRepository) SearchByContentID

func (m *MockRepository) SearchByContentID(ctx context.Context, contentID string, options *SearchOptions) (*SearchResults, error)

SearchByContentID performs a "more like this" search

func (*MockRepository) SearchByText

func (m *MockRepository) SearchByText(ctx context.Context, query string, options *SearchOptions) (*SearchResults, error)

SearchByText performs a vector search using text

func (*MockRepository) SearchByVector

func (m *MockRepository) SearchByVector(ctx context.Context, vector []float32, options *SearchOptions) (*SearchResults, error)

SearchByVector performs a vector search using a pre-computed vector

func (*MockRepository) Update

func (m *MockRepository) Update(ctx context.Context, result *SearchResult) error

Update modifies an existing search result (standardized Repository method)

type Repository

type Repository interface {
	// Core repository methods - aligned with generic Repository[T] interface
	// Create stores a new search result
	Create(ctx context.Context, result *SearchResult) error
	// Get retrieves a search result by its ID
	Get(ctx context.Context, id string) (*SearchResult, error)
	// List retrieves search results matching the provided filter
	List(ctx context.Context, filter Filter) ([]*SearchResult, error)
	// Update modifies an existing search result
	Update(ctx context.Context, result *SearchResult) error
	// Delete removes a search result by its ID
	Delete(ctx context.Context, id string) error

	// Search-specific methods
	// SearchByText performs a vector search using text
	SearchByText(ctx context.Context, query string, options *SearchOptions) (*SearchResults, error)

	// SearchByVector performs a vector search using a pre-computed vector
	SearchByVector(ctx context.Context, vector []float32, options *SearchOptions) (*SearchResults, error)

	// SearchByContentID performs a "more like this" search
	SearchByContentID(ctx context.Context, contentID string, options *SearchOptions) (*SearchResults, error)

	// GetSupportedModels returns a list of models with embeddings
	GetSupportedModels(ctx context.Context) ([]string, error)

	// GetSearchStats retrieves statistics about the search index
	GetSearchStats(ctx context.Context) (map[string]any, error)
}

Repository defines the interface for search operations

func NewMockRepository

func NewMockRepository() Repository

NewMockRepository creates a new mock repository

func NewRepository

func NewRepository(db *sqlx.DB) Repository

NewRepository creates a new search repository with the given database

func NewRepositoryWithEmbedding

func NewRepositoryWithEmbedding(db *sqlx.DB, embeddingService EmbeddingService, defaultModel string) Repository

NewRepositoryWithEmbedding creates a new search repository with embedding service

type SQLRepository

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

SQLRepository implements the Repository interface using a SQL database

func (*SQLRepository) Create

func (r *SQLRepository) Create(ctx context.Context, result *SearchResult) error

Create stores a new search result (standardized Repository method)

func (*SQLRepository) Delete

func (r *SQLRepository) Delete(ctx context.Context, id string) error

Delete removes a search result by its ID (standardized Repository method)

func (*SQLRepository) Get

func (r *SQLRepository) Get(ctx context.Context, id string) (*SearchResult, error)

Get retrieves a search result by its ID (standardized Repository method)

func (*SQLRepository) GetSearchStats

func (r *SQLRepository) GetSearchStats(ctx context.Context) (map[string]any, error)

GetSearchStats retrieves statistics about the search index

func (*SQLRepository) GetSupportedModels

func (r *SQLRepository) GetSupportedModels(ctx context.Context) ([]string, error)

GetSupportedModels returns a list of models with embeddings

func (*SQLRepository) List

func (r *SQLRepository) List(ctx context.Context, filter Filter) ([]*SearchResult, error)

List retrieves search results matching the provided filter (standardized Repository method)

func (*SQLRepository) SearchByContentID

func (r *SQLRepository) SearchByContentID(ctx context.Context, contentID string, options *SearchOptions) (*SearchResults, error)

SearchByContentID performs a "more like this" search

func (*SQLRepository) SearchByText

func (r *SQLRepository) SearchByText(ctx context.Context, query string, options *SearchOptions) (*SearchResults, error)

SearchByText performs a vector search using text

func (*SQLRepository) SearchByVector

func (r *SQLRepository) SearchByVector(ctx context.Context, vector []float32, options *SearchOptions) (*SearchResults, error)

SearchByVector performs a vector search using a pre-computed vector

func (*SQLRepository) Update

func (r *SQLRepository) Update(ctx context.Context, result *SearchResult) error

Update modifies an existing search result (standardized Repository method)

type SearchFilter

type SearchFilter struct {
	Field    string
	Operator string
	Value    any
}

SearchFilter defines a filter for search operations

type SearchOptions

type SearchOptions struct {
	Limit               int                    // Maximum number of results to return
	Offset              int                    // Number of results to skip
	MinSimilarity       float32                // Minimum similarity score (0-1)
	SimilarityThreshold float32                // Alias for MinSimilarity for backward compatibility
	MetadataFilters     map[string]interface{} // JSONB metadata filters
	HybridSearch        bool                   // Combine text + vector search
	RankingAlgorithm    string                 // "cosine", "euclidean", "dot_product"
	MaxResults          int                    // Alias for Limit for backward compatibility
	Filters             []SearchFilter         // Structured filters
	Sorts               []SearchSort           // Sort criteria
	ContentTypes        []string               // Filter by content types
	WeightFactors       map[string]float32     // Weights for hybrid search
}

SearchOptions defines options for search operations

type SearchResult

type SearchResult struct {
	ID          string
	Score       float32
	Distance    float32
	Content     string
	Type        string
	Metadata    map[string]any
	ContentHash string
}

SearchResult represents a single result item from a search

type SearchResults

type SearchResults struct {
	Results []*SearchResult
	Total   int
	HasMore bool
}

SearchResults contains results from a search operation

type SearchSort

type SearchSort struct {
	Field     string
	Direction string
}

SearchSort defines a sort order for search operations

Jump to

Keyboard shortcuts

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