core

package
v2.15.1 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2026 License: MIT Imports: 23 Imported by: 2

Documentation

Overview

Package core provides advanced search capabilities

Package core provides the core storage and retrieval engine for cortexdb.

It implements vector storage using SQLite as the primary backend, supported by specialized in-memory indexes (HNSW, IVF) for high-performance approximate nearest neighbor (ANN) search.

Key Components

  • SQLiteStore: The main entry point for data operations, managing both persistent SQL data and memory indexes.
  • Store Interface: Defines the standard operations for vector storage, document management, and chat memory.
  • DimensionAdapter: Automatically handles vector dimension mismatches based on configurable policies.
  • Hybrid Search: Combines HNSW/IVF vector search with SQLite FTS5 keyword search.
  • Metadata Filtering: Efficiently filters results using JSON-extract SQL push-down.
  • ACL: Provides row-level security for multi-user/department environments.

Observability

Since v2.0.0, the core engine supports pluggable structured logging through the Logger interface.

Package core provides faceted search capabilities

Package core provides multi-vector entity support

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidDimension is returned when vector dimension doesn't match expected
	ErrInvalidDimension = errors.New("invalid vector dimension")

	// ErrNotFound is returned when an embedding is not found
	ErrNotFound = errors.New("embedding not found")

	// ErrInvalidVector is returned when vector data is invalid
	ErrInvalidVector = errors.New("invalid vector data")

	// ErrStoreClosed is returned when trying to use a closed store
	ErrStoreClosed = errors.New("store is closed")

	// ErrInvalidConfig is returned when configuration is invalid
	ErrInvalidConfig = errors.New("invalid configuration")

	// ErrEmptyQuery is returned when search query is empty
	ErrEmptyQuery = errors.New("empty query vector")
)

Common errors

View Source
var (
	// CosineSimilarity calculates cosine similarity between two vectors
	CosineSimilarity = cosineSimilarity

	// DotProduct calculates dot product between two vectors
	DotProduct = dotProduct

	// EuclideanDist calculates negative Euclidean distance (higher = more similar)
	EuclideanDist = euclideanDistance
)

Predefined similarity functions for backward compatibility

Functions

func BuildSQLFromFilter

func BuildSQLFromFilter(filter *FilterExpression, paramIndex *int) (string, []interface{})

BuildSQLFromFilter converts FilterExpression to SQL WHERE clause

func MergeStreamResults

func MergeStreamResults(ctx context.Context, channels ...<-chan StreamingResult) <-chan StreamingResult

MergeStreamResults merges multiple streaming result channels into one

Types

type AdaptPolicy

type AdaptPolicy int

AdaptPolicy defines how to handle vector dimension mismatches

const (
	StrictMode   AdaptPolicy = iota // Error on dimension mismatch (default)
	SmartAdapt                      // Intelligent adaptation based on data distribution
	AutoTruncate                    // Always truncate to smaller dimension
	AutoPad                         // Always pad to larger dimension
	WarnOnly                        // Only warn, don't auto-adapt
)

type AdvancedSearchOptions

type AdvancedSearchOptions struct {
	SearchOptions
	PreFilter     *FilterExpression // Applied before vector search
	PostFilter    *FilterExpression // Applied after vector search
	ArraySupport  bool              // Enable array field filtering
	NumericRanges bool              // Enable numeric range optimization
}

AdvancedSearchOptions extends SearchOptions with advanced filtering

type AggregationMethod

type AggregationMethod string

AggregationMethod for combining multi-vector scores

const (
	AggregateMax      AggregationMethod = "max"
	AggregateMin      AggregationMethod = "min"
	AggregateAverage  AggregationMethod = "average"
	AggregateSum      AggregationMethod = "sum"
	AggregateWeighted AggregationMethod = "weighted"
)

type AggregationRequest

type AggregationRequest struct {
	Type       AggregationType        `json:"type"`
	Field      string                 `json:"field"`      // Metadata field to aggregate
	GroupBy    []string               `json:"group_by"`   // Fields to group by
	Filters    map[string]interface{} `json:"filters"`    // Optional filters
	Collection string                 `json:"collection"` // Optional collection filter
	Having     map[string]interface{} `json:"having"`     // Post-aggregation filters
	OrderBy    string                 `json:"order_by"`   // Field to order results by
	Limit      int                    `json:"limit"`      // Max results
}

AggregationRequest defines parameters for aggregation queries

type AggregationResponse

type AggregationResponse struct {
	Request AggregationRequest  `json:"request"`
	Results []AggregationResult `json:"results"`
	Total   int                 `json:"total"`
}

AggregationResponse contains the aggregation results

type AggregationResult

type AggregationResult struct {
	GroupKeys map[string]interface{} `json:"group_keys"` // Group by field values
	Value     interface{}            `json:"value"`      // Aggregated value
	Count     int                    `json:"count"`      // Number of items in group
}

AggregationResult represents a single aggregation result

type AggregationType

type AggregationType string

AggregationType defines the type of aggregation

const (
	AggregationCount   AggregationType = "count"
	AggregationSum     AggregationType = "sum"
	AggregationAvg     AggregationType = "avg"
	AggregationMin     AggregationType = "min"
	AggregationMax     AggregationType = "max"
	AggregationGroupBy AggregationType = "group_by"
)

type AutoSaveConfig added in v2.8.0

type AutoSaveConfig struct {
	Enabled     bool          `json:"enabled"`     // Enable auto-save (default: true)
	Interval    time.Duration `json:"interval"`    // Save interval (default: 5 minutes)
	SaveOnClose bool          `json:"saveOnClose"` // Save on database close (default: true)
	MinChanges  int           `json:"minChanges"`  // Minimum changes before saving (default: 100)
}

AutoSaveConfig defines configuration for automatic index snapshot saving

func DefaultAutoSaveConfig added in v2.8.0

func DefaultAutoSaveConfig() AutoSaveConfig

DefaultAutoSaveConfig returns default auto-save configuration

type Collection

type Collection struct {
	ID          int                    `json:"id"`
	Name        string                 `json:"name"`
	Dimensions  int                    `json:"dimensions"`
	Description string                 `json:"description,omitempty"`
	Metadata    map[string]interface{} `json:"metadata,omitempty"`
	CreatedAt   time.Time              `json:"created_at"`
	UpdatedAt   time.Time              `json:"updated_at"`
}

Collection represents a logical grouping of embeddings

type CollectionStats

type CollectionStats struct {
	Name           string    `json:"name"`
	Count          int64     `json:"count"`
	Dimensions     int       `json:"dimensions"`
	Size           int64     `json:"size"`
	CreatedAt      time.Time `json:"created_at"`
	LastInsertedAt time.Time `json:"last_inserted_at,omitempty"`
}

CollectionStats represents statistics for a collection

type Config

type Config struct {
	Path           string               `json:"path"`                     // Database file path
	VectorDim      int                  `json:"vectorDim"`                // Expected vector dimension, 0 = auto-detect
	AutoDimAdapt   AdaptPolicy          `json:"autoDimAdapt"`             // How to handle dimension mismatches
	SimilarityFn   SimilarityFunc       `json:"-"`                        // Similarity function
	IndexType      IndexType            `json:"indexType"`                // Index type to use
	HNSW           HNSWConfig           `json:"hnsw,omitempty"`           // HNSW index configuration
	IVF            IVFConfig            `json:"ivf,omitempty"`            // IVF index configuration
	TextSimilarity TextSimilarityConfig `json:"textSimilarity,omitempty"` // Text similarity configuration
	Quantization   QuantizationConfig   `json:"quantization,omitempty"`   // Quantization configuration
	Logger         Logger               `json:"-"`                        // Logger instance (defaults to nop logger)
	AutoSave       AutoSaveConfig       `json:"autoSave,omitempty"`       // Auto-save configuration
}

Config represents configuration options for the vector store

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns a default configuration

type CustomReranker

type CustomReranker struct {
	// ScoreFunc computes a custom score for each result
	ScoreFunc func(ctx context.Context, query string, result ScoredEmbedding) float64
}

CustomReranker allows users to provide a custom scoring function

func NewCustomReranker

func NewCustomReranker(scoreFunc func(ctx context.Context, query string, result ScoredEmbedding) float64) *CustomReranker

NewCustomReranker creates a new custom reranker

func (*CustomReranker) Rerank

func (r *CustomReranker) Rerank(ctx context.Context, query string, results []ScoredEmbedding) ([]ScoredEmbedding, error)

Rerank applies custom scoring function

type DimensionAdapter

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

DimensionAdapter handles vector dimension adaptation

func NewDimensionAdapter

func NewDimensionAdapter(policy AdaptPolicy) *DimensionAdapter

NewDimensionAdapter creates a new dimension adapter with the given policy

func (*DimensionAdapter) AdaptVector

func (da *DimensionAdapter) AdaptVector(vector []float32, sourceDim, targetDim int) ([]float32, error)

AdaptVector adapts a vector from source dimension to target dimension

type DimensionAnalysis

type DimensionAnalysis struct {
	PrimaryDim     int         `json:"primaryDim"`     // Most common dimension
	PrimaryCount   int         `json:"primaryCount"`   // Count of primary dimension
	Dimensions     map[int]int `json:"dimensions"`     // Map of dimension -> count
	TotalVectors   int         `json:"totalVectors"`   // Total number of vectors
	NeedsMigration bool        `json:"needsMigration"` // Whether migration is recommended
}

DimensionAnalysis contains information about vector dimensions in the store

func AnalyzeDimensions

func AnalyzeDimensions(vectors [][]float32) *DimensionAnalysis

AnalyzeDimensions analyzes dimension distribution in the given vectors

type DiversityMethod

type DiversityMethod string

DiversityMethod for result diversification

const (
	// Maximal Marginal Relevance
	DiversityMMR DiversityMethod = "mmr"

	// Determinantal Point Process
	DiversityDPP DiversityMethod = "dpp"

	// Simple distance-based
	DiversityDistance DiversityMethod = "distance"

	// Random sampling
	DiversityRandom DiversityMethod = "random"
)

type DiversityReranker

type DiversityReranker struct {
	// Lambda controls the diversity vs relevance trade-off
	// 0.0 = maximum diversity, 1.0 = maximum relevance
	Lambda float64
	// SimilarityFunc computes similarity between two embeddings
	SimilarityFunc SimilarityFunc
}

DiversityReranker promotes diverse results using Maximal Marginal Relevance (MMR)

func NewDiversityReranker

func NewDiversityReranker(lambda float64, simFunc SimilarityFunc) *DiversityReranker

NewDiversityReranker creates a new diversity-based reranker

func (*DiversityReranker) Rerank

func (r *DiversityReranker) Rerank(ctx context.Context, query string, results []ScoredEmbedding) ([]ScoredEmbedding, error)

Rerank applies MMR to promote diverse results

type DiversitySearchOptions

type DiversitySearchOptions struct {
	// Lambda parameter for MMR (0 = max diversity, 1 = max relevance)
	Lambda float32

	// Diversity method
	Method DiversityMethod

	// Minimum distance between results
	MinDistance float32

	// Base search options
	SearchOptions
}

DiversitySearchOptions for diverse result sampling

type Document

type Document struct {
	ID        string                 `json:"id"`
	Title     string                 `json:"title"`
	SourceURL string                 `json:"source_url,omitempty"`
	Content   string                 `json:"content,omitempty"` // Full document content
	Version   int                    `json:"version"`
	Author    string                 `json:"author,omitempty"`
	Metadata  map[string]interface{} `json:"metadata,omitempty"`
	ACL       []string               `json:"acl,omitempty"` // Allowed user IDs or groups
	CreatedAt time.Time              `json:"created_at"`
	UpdatedAt time.Time              `json:"updated_at"`
}

Document represents a high-level document containing multiple embeddings (chunks)

type DocumentInfo

type DocumentInfo struct {
	DocID          string  `json:"docId"`
	EmbeddingCount int     `json:"embeddingCount"`
	FirstCreated   *string `json:"firstCreated,omitempty"`
	LastUpdated    *string `json:"lastUpdated,omitempty"`
}

DocumentInfo provides information about a document in the store

type DumpFormat

type DumpFormat string

DumpFormat represents the format for data export

const (
	// DumpFormatJSON exports data as JSON
	DumpFormatJSON DumpFormat = "json"
	// DumpFormatJSONL exports data as JSON Lines (one JSON object per line)
	DumpFormatJSONL DumpFormat = "jsonl"
	// DumpFormatCSV exports data as CSV (vectors as base64 encoded strings)
	DumpFormatCSV DumpFormat = "csv"
)

type DumpOptions

type DumpOptions struct {
	Format         DumpFormat      // Export format
	IncludeVectors bool            // Include vector data (can be large)
	IncludeIndex   bool            // Include index data (HNSW, IVF)
	Filter         *MetadataFilter // Optional filter for selective export
	BatchSize      int             // Batch size for export (default: 1000)
}

DumpOptions defines options for data export

func DefaultDumpOptions

func DefaultDumpOptions() DumpOptions

DefaultDumpOptions returns default dump options

type DumpStats

type DumpStats struct {
	TotalEmbeddings  int   `json:"total_embeddings"`
	TotalDocuments   int   `json:"total_documents"`
	TotalCollections int   `json:"total_collections"`
	BytesWritten     int64 `json:"bytes_written"`
}

DumpStats provides statistics about the export operation

type Embedding

type Embedding struct {
	ID           string            `json:"id"`
	CollectionID int               `json:"collection_id,omitempty"`
	Collection   string            `json:"collection,omitempty"`
	Vector       []float32         `json:"vector"`
	Content      string            `json:"content"`
	DocID        string            `json:"docId,omitempty"`
	Metadata     map[string]string `json:"metadata,omitempty"`
	ACL          []string          `json:"acl,omitempty"` // Allowed user IDs or groups
}

Embedding represents a vector embedding with associated metadata

type ExportMetadata

type ExportMetadata struct {
	Version    string `json:"version"`
	Dimensions int    `json:"dimensions"`
	Count      int    `json:"count"`
	ExportedAt string `json:"exported_at"`
	Config     Config `json:"config"`
}

ExportMetadata contains metadata about the export

type FacetFilter

type FacetFilter struct {
	// Type of filter
	Type FacetFilterType

	// Values for equality/inclusion filters
	Values []interface{}

	// Range for numeric filters
	Min interface{}
	Max interface{}

	// Pattern for text filters
	Pattern string

	// Nested filters for complex conditions
	Nested []FacetFilter

	// Logical operator for nested filters
	Operator LogicalOperator
}

FacetFilter defines filtering for a specific facet

type FacetFilterType

type FacetFilterType string

FacetFilterType defines the type of facet filter

const (
	FilterTypeEquals   FacetFilterType = "equals"
	FilterTypeIn       FacetFilterType = "in"
	FilterTypeRange    FacetFilterType = "range"
	FilterTypeContains FacetFilterType = "contains"
	FilterTypePrefix   FacetFilterType = "prefix"
	FilterTypeExists   FacetFilterType = "exists"
	FilterTypeNested   FacetFilterType = "nested"
)

type FacetResult

type FacetResult struct {
	Field  string
	Values map[string]int
	Total  int
}

FacetResult contains facet counts

type FacetedSearchOptions

type FacetedSearchOptions struct {
	SearchOptions

	// Facets to filter by
	Facets map[string]FacetFilter

	// Whether to return facet counts
	ReturnFacets bool

	// Maximum number of facet values to return
	MaxFacetValues int
}

FacetedSearchOptions extends SearchOptions with faceted filtering

type FilterExpression

type FilterExpression struct {
	Operator FilterOperator
	Field    string
	Value    interface{}
	Children []*FilterExpression
}

FilterExpression represents a complex filter expression

func ParseFilterString

func ParseFilterString(filterStr string) (*FilterExpression, error)

ParseFilterString parses a string filter expression into FilterExpression Example: "(tag:ai OR tag:ml) AND date>2024 AND price BETWEEN 100 AND 500"

type FilterOperator

type FilterOperator string

FilterOperator represents logical operators for filters

const (
	FilterAND     FilterOperator = "AND"
	FilterOR      FilterOperator = "OR"
	FilterNOT     FilterOperator = "NOT"
	FilterEQ      FilterOperator = "="
	FilterNE      FilterOperator = "!="
	FilterGT      FilterOperator = ">"
	FilterGTE     FilterOperator = ">="
	FilterLT      FilterOperator = "<"
	FilterLTE     FilterOperator = "<="
	FilterIN      FilterOperator = "IN"
	FilterBETWEEN FilterOperator = "BETWEEN"
	FilterLIKE    FilterOperator = "LIKE"
	FilterREGEX   FilterOperator = "REGEX"
)

type HNSWConfig

type HNSWConfig struct {
	Enabled        bool `json:"enabled"`
	M              int  `json:"m"`              // Maximum connections per node (default: 16)
	EfConstruction int  `json:"efConstruction"` // Candidates during construction (default: 64)
	EfSearch       int  `json:"efSearch"`       // Candidates during search (default: 50)
	NumWorkers     int  `json:"numWorkers"`     // Number of parallel workers for index building (default: 4)
	Incremental    bool `json:"incremental"`    // Enable incremental indexing (default: true)
}

HNSWConfig represents configuration options for HNSW indexing

func DefaultHNSWConfig

func DefaultHNSWConfig() HNSWConfig

DefaultHNSWConfig returns default HNSW configuration

type HybridReranker

type HybridReranker struct {
	Rerankers []Reranker
	Weights   []float64
}

HybridReranker combines multiple rerankers with weighted scores

func NewHybridReranker

func NewHybridReranker(rerankers []Reranker, weights []float64) *HybridReranker

NewHybridReranker creates a new hybrid reranker

func (*HybridReranker) Rerank

func (r *HybridReranker) Rerank(ctx context.Context, query string, results []ScoredEmbedding) ([]ScoredEmbedding, error)

Rerank combines multiple rerankers

type HybridSearchOptions

type HybridSearchOptions struct {
	SearchOptions
	// Fusion parameter for RRF (default 60)
	RRFK float64
}

HybridSearchOptions for combined vector + keyword search

type IVFConfig

type IVFConfig struct {
	Enabled    bool `json:"enabled"`
	NCentroids int  `json:"nCentroids"` // Number of centroids (default: 100)
	NProbe     int  `json:"nProbe"`     // Number of clusters to search (default: 10)
}

IVFConfig represents configuration options for IVF indexing

func DefaultIVFConfig

func DefaultIVFConfig() IVFConfig

DefaultIVFConfig returns default IVF configuration

type ImportStats

type ImportStats struct {
	TotalEmbeddings int `json:"total_embeddings"`
	TotalDocuments  int `json:"total_documents"`
	FailedCount     int `json:"failed_count"`
	SkippedCount    int `json:"skipped_count"`
}

ImportStats provides statistics about the import operation

func (*ImportStats) String

func (s *ImportStats) String() string

Helper to convert import stats to string

type IncrementalIndex

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

IncrementalIndex allows adding vectors while searching continues

func NewIncrementalIndex

func NewIncrementalIndex(store *SQLiteStore) *IncrementalIndex

NewIncrementalIndex creates a new incremental index

func (*IncrementalIndex) AddAsync

func (idx *IncrementalIndex) AddAsync(emb *Embedding) error

AddAsync adds a vector asynchronously

func (*IncrementalIndex) Close

func (idx *IncrementalIndex) Close()

Close shuts down the incremental index

func (*IncrementalIndex) SearchWithUpdates

func (idx *IncrementalIndex) SearchWithUpdates(ctx context.Context, query []float32, opts SearchOptions) ([]ScoredEmbedding, error)

SearchWithUpdates performs search while considering ongoing updates

type IndexType

type IndexType int

IndexType defines the type of index to use

const (
	IndexTypeHNSW IndexType = iota
	IndexTypeIVF
	IndexTypeFlat
)

type KeywordMatchReranker

type KeywordMatchReranker struct {
	// Boost is the score multiplier for keyword matches
	Boost float64
	// CaseSensitive enables case-sensitive matching
	CaseSensitive bool
}

KeywordMatchReranker boosts results that contain the query keywords

func NewKeywordMatchReranker

func NewKeywordMatchReranker(boost float64) *KeywordMatchReranker

NewKeywordMatchReranker creates a new keyword match reranker

func (*KeywordMatchReranker) Rerank

func (r *KeywordMatchReranker) Rerank(ctx context.Context, query string, results []ScoredEmbedding) ([]ScoredEmbedding, error)

Rerank boosts results containing query keywords

type LoadOptions

type LoadOptions struct {
	Format       DumpFormat // Import format
	SkipExisting bool       // Skip existing embeddings (by ID)
	Replace      bool       // Replace existing embeddings
	BatchSize    int        // Batch size for import (default: 100)
	Upsert       bool       // Use upsert instead of insert
}

LoadOptions defines options for data import

func DefaultLoadOptions

func DefaultLoadOptions() LoadOptions

DefaultLoadOptions returns default load options

type LogLevel

type LogLevel int

LogLevel represents the severity level of a log message

const (
	// LevelDebug is for detailed debugging information
	LevelDebug LogLevel = iota
	// LevelInfo is for general informational messages
	LevelInfo
	// LevelWarn is for warning messages
	LevelWarn
	// LevelError is for error messages
	LevelError
)

func (LogLevel) String

func (l LogLevel) String() string

String returns the string representation of the log level

type Logger

type Logger interface {
	// Debug logs a debug message
	Debug(msg string, keyvals ...any)
	// Info logs an informational message
	Info(msg string, keyvals ...any)
	// Warn logs a warning message
	Warn(msg string, keyvals ...any)
	// Error logs an error message
	Error(msg string, keyvals ...any)
	// With returns a new logger with additional key-value pairs
	With(keyvals ...any) Logger
}

Logger is the interface for logging operations

func NewLogger

func NewLogger(writer io.Writer, minLevel LogLevel) Logger

NewLogger creates a new logger that writes to the given writer

func NewStdLogger

func NewStdLogger(minLevel LogLevel) Logger

NewStdLogger creates a new logger that writes to stdout

func NopLogger

func NopLogger() Logger

NopLogger returns a logger that discards all messages

type LogicalOperator

type LogicalOperator string

LogicalOperator for combining filters

const (
	OperatorAND LogicalOperator = "AND"
	OperatorOR  LogicalOperator = "OR"
	OperatorNOT LogicalOperator = "NOT"
)

type Message

type Message struct {
	ID        string                 `json:"id"`
	SessionID string                 `json:"session_id"`
	Role      string                 `json:"role"` // 'user', 'assistant', 'system'
	Content   string                 `json:"content"`
	Vector    []float32              `json:"vector,omitempty"` // Embedding for long-term memory
	Metadata  map[string]interface{} `json:"metadata,omitempty"`
	CreatedAt time.Time              `json:"created_at"`
}

Message represents a single message in a chat session

type MetadataFilter

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

MetadataFilter helper for building filter expressions

func NewMetadataFilter

func NewMetadataFilter() *MetadataFilter

NewMetadataFilter creates a new metadata filter builder

func (*MetadataFilter) And

And combines with another filter using AND

func (*MetadataFilter) Between

func (f *MetadataFilter) Between(field string, min, max interface{}) *MetadataFilter

Between adds a BETWEEN condition

func (*MetadataFilter) Build

func (f *MetadataFilter) Build() *FilterExpression

Build returns the underlying expression (for tests)

func (*MetadataFilter) BuildSQL

func (f *MetadataFilter) BuildSQL() (string, []interface{})

BuildSQL returns the SQL WHERE clause for the filter

func (*MetadataFilter) Equal

func (f *MetadataFilter) Equal(field string, value interface{}) *MetadataFilter

Equal adds an equality condition

func (*MetadataFilter) GreaterThan

func (f *MetadataFilter) GreaterThan(field string, value interface{}) *MetadataFilter

GreaterThan adds a greater than condition

func (*MetadataFilter) GreaterThanOrEqual

func (f *MetadataFilter) GreaterThanOrEqual(field string, value interface{}) *MetadataFilter

GreaterThanOrEqual adds a greater than or equal condition

func (*MetadataFilter) In

func (f *MetadataFilter) In(field string, values ...interface{}) *MetadataFilter

In adds an IN condition

func (*MetadataFilter) IsEmpty

func (f *MetadataFilter) IsEmpty() bool

IsEmpty checks if the filter is empty

func (*MetadataFilter) LessThan

func (f *MetadataFilter) LessThan(field string, value interface{}) *MetadataFilter

LessThan adds a less than condition

func (*MetadataFilter) LessThanOrEqual

func (f *MetadataFilter) LessThanOrEqual(field string, value interface{}) *MetadataFilter

LessThanOrEqual adds a less than or equal condition

func (*MetadataFilter) Like

func (f *MetadataFilter) Like(field string, pattern string) *MetadataFilter

Like adds a LIKE condition

func (*MetadataFilter) NotEqual

func (f *MetadataFilter) NotEqual(field string, value interface{}) *MetadataFilter

NotEqual adds a non-equality condition

func (*MetadataFilter) NotIn

func (f *MetadataFilter) NotIn(field string, values ...interface{}) *MetadataFilter

NotIn adds a NOT IN condition

func (*MetadataFilter) Or

Or combines with another filter using OR

func (*MetadataFilter) StringIn

func (f *MetadataFilter) StringIn(field string, values ...string) *MetadataFilter

StringIn is alias for In for string values

func (*MetadataFilter) ToSQL

func (f *MetadataFilter) ToSQL() (string, []interface{})

ToSQL is an alias for BuildSQL

type MultiVectorEntity

type MultiVectorEntity struct {
	// Entity ID
	ID string

	// Vectors associated with this entity
	Vectors map[string][]float32

	// Metadata for the entity
	Metadata map[string]interface{}

	// Content/text for the entity
	Content string
}

MultiVectorEntity represents an entity with multiple vectors

type MultiVectorSearchOptions

type MultiVectorSearchOptions struct {
	// Which vector fields to search
	VectorFields []string

	// Weights for each vector field
	FieldWeights map[string]float32

	// Aggregation method for combining scores
	Aggregation AggregationMethod

	// Standard search options
	SearchOptions
}

MultiVectorSearchOptions for multi-vector search

type NegativeSearchOptions

type NegativeSearchOptions struct {
	// Positive examples (find similar to these)
	PositiveVectors [][]float32

	// Negative examples (avoid similar to these)
	NegativeVectors [][]float32

	// Weight for negative examples (higher = stronger avoidance)
	NegativeWeight float32

	// Base search options
	SearchOptions
}

NegativeSearchOptions for "not like this" queries

type QuantizationConfig

type QuantizationConfig struct {
	Enabled bool   `json:"enabled"` // Enable quantization
	Type    string `json:"type"`    // "scalar" (SQ8) or "binary" (BQ)
	NBits   int    `json:"nBits"`   // Bits per component (default 8 for SQ8)
}

QuantizationConfig represents configuration for vector quantization

func DefaultQuantizationConfig

func DefaultQuantizationConfig() QuantizationConfig

DefaultQuantizationConfig returns default quantization configuration

type ReciprocalRankFusionReranker

type ReciprocalRankFusionReranker struct {
	// K is the RRF constant (typically 60)
	K float64
	// VectorWeight is the weight for vector similarity scores
	VectorWeight float64
	// TextWeight is the weight for text match scores
	TextWeight float64
}

ReciprocalRankFusionReranker combines multiple ranking signals using RRF

func NewReciprocalRankFusionReranker

func NewReciprocalRankFusionReranker(k float64) *ReciprocalRankFusionReranker

NewReciprocalRankFusionReranker creates a new RRF reranker

func (*ReciprocalRankFusionReranker) Rerank

Rerank combines vector and text ranking using RRF

type RerankOptions

type RerankOptions struct {
	// TopK is the number of results to return after reranking
	TopK int
	// Threshold is the minimum score threshold after reranking
	Threshold float64
	// PreserveOriginalScore keeps the original vector similarity score
	// If false, the score is replaced by the reranker's score
	PreserveOriginalScore bool
}

RerankOptions defines options for reranking

func DefaultRerankOptions

func DefaultRerankOptions() RerankOptions

DefaultRerankOptions returns default reranking options

type Reranker

type Reranker interface {
	// Rerank reorders the scored embeddings based on the query
	// Returns a new slice with the same embeddings, but potentially different scores/order
	Rerank(ctx context.Context, query string, results []ScoredEmbedding) ([]ScoredEmbedding, error)
}

Reranker defines the interface for re-ranking search results A reranker takes the initial search results and reorders them based on additional relevance signals beyond vector similarity

type RerankerFunc

type RerankerFunc func(ctx context.Context, query string, results []ScoredEmbedding) ([]ScoredEmbedding, error)

RerankerFunc is a function adapter that implements Reranker interface

func (RerankerFunc) Rerank

func (f RerankerFunc) Rerank(ctx context.Context, query string, results []ScoredEmbedding) ([]ScoredEmbedding, error)

Rerank implements the Reranker interface

type SQLiteStore

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

SQLiteStore implements the Store interface using SQLite as backend

func New

func New(path string, vectorDim int) (*SQLiteStore, error)

New creates a new SQLite vector store with the given configuration

func NewWithConfig

func NewWithConfig(config Config) (*SQLiteStore, error)

NewWithConfig creates a new SQLite vector store with custom configuration

func (*SQLiteStore) AddMessage

func (s *SQLiteStore) AddMessage(ctx context.Context, msg *Message) error

AddMessage adds a message to a session If vector is provided, it can be used for semantic search over chat history

func (*SQLiteStore) Aggregate

Aggregate performs aggregation queries on embeddings metadata

func (*SQLiteStore) Backup

func (s *SQLiteStore) Backup(ctx context.Context, filepath string) error

Backup creates a full backup of the database to a file

func (*SQLiteStore) BatchRangeSearch

func (s *SQLiteStore) BatchRangeSearch(ctx context.Context, queries [][]float32, radius float32, opts SearchOptions) ([][]ScoredEmbedding, error)

BatchRangeSearch performs range search for multiple queries

func (*SQLiteStore) Clear

func (s *SQLiteStore) Clear(ctx context.Context) error

Clear removes all embeddings from the store

func (*SQLiteStore) ClearByDocID

func (s *SQLiteStore) ClearByDocID(ctx context.Context, docIDs []string) error

ClearByDocID removes all embeddings for specific document IDs

func (*SQLiteStore) Close

func (s *SQLiteStore) Close() error

Close closes the database connection and releases resources

func (*SQLiteStore) Config

func (s *SQLiteStore) Config() Config

Config returns the current configuration of the store

func (*SQLiteStore) CreateCollection

func (s *SQLiteStore) CreateCollection(ctx context.Context, name string, dimensions int) (*Collection, error)

CreateCollection creates a new collection

func (*SQLiteStore) CreateDocument

func (s *SQLiteStore) CreateDocument(ctx context.Context, doc *Document) error

CreateDocument creates a new document record

func (*SQLiteStore) CreateSession

func (s *SQLiteStore) CreateSession(ctx context.Context, session *Session) error

CreateSession creates a new chat session

func (*SQLiteStore) Delete

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

Delete removes an embedding by ID

func (*SQLiteStore) DeleteBatch

func (s *SQLiteStore) DeleteBatch(ctx context.Context, ids []string) error

DeleteBatch removes multiple embeddings by their IDs in a single operation

func (*SQLiteStore) DeleteByDocID

func (s *SQLiteStore) DeleteByDocID(ctx context.Context, docID string) error

DeleteByDocID removes all embeddings for a document

func (*SQLiteStore) DeleteByFilter

func (s *SQLiteStore) DeleteByFilter(ctx context.Context, filter *MetadataFilter) error

DeleteByFilter removes embeddings matching the given metadata filter

func (*SQLiteStore) DeleteCollection

func (s *SQLiteStore) DeleteCollection(ctx context.Context, name string) error

DeleteCollection deletes a collection and all its embeddings

func (*SQLiteStore) DeleteDocument

func (s *SQLiteStore) DeleteDocument(ctx context.Context, id string) error

DeleteDocument deletes a document and all its associated embeddings (chunks)

func (*SQLiteStore) DeleteMultiVectorEntity

func (s *SQLiteStore) DeleteMultiVectorEntity(ctx context.Context, entityID string) error

DeleteMultiVectorEntity deletes all vectors for an entity

func (*SQLiteStore) Dump

func (s *SQLiteStore) Dump(ctx context.Context, w io.Writer, opts DumpOptions) (*DumpStats, error)

Dump exports all embeddings to a writer in the specified format

func (*SQLiteStore) DumpToFile

func (s *SQLiteStore) DumpToFile(ctx context.Context, filepath string, opts DumpOptions) (*DumpStats, error)

DumpToFile exports data to a file

func (*SQLiteStore) ExportIndex

func (s *SQLiteStore) ExportIndex(ctx context.Context, filepath string) error

ExportIndex exports the index data (HNSW/IVF) to a file

func (*SQLiteStore) FindAnomalies

func (s *SQLiteStore) FindAnomalies(ctx context.Context, opts SearchOptions) ([]ScoredEmbedding, error)

FindAnomalies finds vectors that are outliers

func (*SQLiteStore) GetByDocID

func (s *SQLiteStore) GetByDocID(ctx context.Context, docID string) ([]*Embedding, error)

GetByDocID returns all embeddings for a specific document ID

func (*SQLiteStore) GetByID

func (s *SQLiteStore) GetByID(ctx context.Context, id string) (*Embedding, error)

GetByID gets an embedding by its ID

func (*SQLiteStore) GetCollection

func (s *SQLiteStore) GetCollection(ctx context.Context, name string) (*Collection, error)

GetCollection retrieves a collection by name

func (*SQLiteStore) GetCollectionStats

func (s *SQLiteStore) GetCollectionStats(ctx context.Context, name string) (*CollectionStats, error)

GetCollectionStats returns statistics for a collection

func (*SQLiteStore) GetDB

func (s *SQLiteStore) GetDB() *sql.DB

GetDB returns the underlying database connection

func (*SQLiteStore) GetDocument

func (s *SQLiteStore) GetDocument(ctx context.Context, id string) (*Document, error)

GetDocument retrieves a document by ID

func (*SQLiteStore) GetDocumentsByType

func (s *SQLiteStore) GetDocumentsByType(ctx context.Context, docType string) ([]*Embedding, error)

GetDocumentsByType returns documents filtered by metadata type

func (*SQLiteStore) GetMultiVectorEntity

func (s *SQLiteStore) GetMultiVectorEntity(ctx context.Context, entityID string) (*MultiVectorEntity, error)

GetMultiVectorEntity retrieves a multi-vector entity

func (*SQLiteStore) GetSession

func (s *SQLiteStore) GetSession(ctx context.Context, id string) (*Session, error)

GetSession retrieves a session by ID

func (*SQLiteStore) GetSessionHistory

func (s *SQLiteStore) GetSessionHistory(ctx context.Context, sessionID string, limit int) ([]*Message, error)

GetSessionHistory retrieves recent messages from a session

func (*SQLiteStore) GetSimilarityFunc

func (s *SQLiteStore) GetSimilarityFunc() SimilarityFunc

GetSimilarityFunc returns the similarity function

func (*SQLiteStore) HybridSearch

func (s *SQLiteStore) HybridSearch(ctx context.Context, vectorQuery []float32, textQuery string, opts HybridSearchOptions) ([]ScoredEmbedding, error)

HybridSearch performs combined vector and keyword search using RRF fusion

func (*SQLiteStore) ImportIndex

func (s *SQLiteStore) ImportIndex(ctx context.Context, filepath string) error

ImportIndex imports index data from a file

func (*SQLiteStore) IncrementChanges added in v2.8.0

func (s *SQLiteStore) IncrementChanges()

IncrementChanges increments the change counter for auto-save tracking

func (*SQLiteStore) Init

func (s *SQLiteStore) Init(ctx context.Context) error

Init initializes the SQLite database and creates necessary tables

func (*SQLiteStore) KeywordSearchMessages

func (s *SQLiteStore) KeywordSearchMessages(ctx context.Context, query, userID, excludeSessionID string, limit int) ([]*Message, error)

KeywordSearchMessages performs BM25 full-text search over all messages belonging to a user. It uses the SQLite FTS5 virtual table (messages_fts) for efficient keyword matching. excludeSessionID may be empty to search across all sessions.

func (*SQLiteStore) ListCollections

func (s *SQLiteStore) ListCollections(ctx context.Context) ([]*Collection, error)

ListCollections lists all collections

func (*SQLiteStore) ListDocuments

func (s *SQLiteStore) ListDocuments(ctx context.Context) ([]string, error)

ListDocuments returns all unique document IDs in the store

func (*SQLiteStore) ListDocumentsWithFilter

func (s *SQLiteStore) ListDocumentsWithFilter(ctx context.Context, author string, limit int) ([]*Document, error)

ListDocumentsWithFilter lists documents matching specific criteria TODO: Add more filter options as needed

func (*SQLiteStore) ListDocumentsWithInfo

func (s *SQLiteStore) ListDocumentsWithInfo(ctx context.Context) ([]DocumentInfo, error)

ListDocumentsWithInfo returns detailed information about documents

func (*SQLiteStore) Load

func (s *SQLiteStore) Load(ctx context.Context, r io.Reader, opts LoadOptions) (*ImportStats, error)

Load imports embeddings from a reader

func (*SQLiteStore) LoadFromFile

func (s *SQLiteStore) LoadFromFile(ctx context.Context, filepath string, opts LoadOptions) (*ImportStats, error)

LoadFromFile imports data from a file

func (*SQLiteStore) ParallelStreamSearch

func (s *SQLiteStore) ParallelStreamSearch(ctx context.Context, queries [][]float32, opts StreamingOptions) ([]<-chan StreamingResult, error)

ParallelStreamSearch performs parallel streaming search across multiple queries

func (*SQLiteStore) RangeSearch

func (s *SQLiteStore) RangeSearch(ctx context.Context, query []float32, radius float32, opts SearchOptions) ([]ScoredEmbedding, error)

RangeSearch performs range-based vector search

func (*SQLiteStore) RecommendSimilar

func (s *SQLiteStore) RecommendSimilar(ctx context.Context, positiveIDs []string, negativeIDs []string, opts SearchOptions) ([]ScoredEmbedding, error)

RecommendSimilar finds items similar to given examples

func (*SQLiteStore) Search

func (s *SQLiteStore) Search(ctx context.Context, query []float32, opts SearchOptions) ([]ScoredEmbedding, error)

Search performs vector similarity search

func (*SQLiteStore) SearchChatHistory

func (s *SQLiteStore) SearchChatHistory(ctx context.Context, queryVec []float32, sessionID string, limit int) ([]*Message, error)

SearchChatHistory performs semantic search over messages This requires messages to have vectors stored

func (*SQLiteStore) SearchMessagesByUser

func (s *SQLiteStore) SearchMessagesByUser(ctx context.Context, userID string, queryVec []float32, excludeSessionID string, limit int) ([]*Message, error)

SearchMessagesByUser performs semantic (vector similarity) search across all sessions for a user, optionally excluding a specific session (e.g., current session already covered by short-term memory).

func (*SQLiteStore) SearchMultiVector

func (s *SQLiteStore) SearchMultiVector(ctx context.Context, queryVectors map[string][]float32, opts MultiVectorSearchOptions) ([]ScoredEmbedding, error)

SearchMultiVector performs multi-vector search

func (*SQLiteStore) SearchWithACL

func (s *SQLiteStore) SearchWithACL(ctx context.Context, query []float32, acl []string, opts SearchOptions) ([]ScoredEmbedding, error)

SearchWithACL performs vector search with access control filtering

func (*SQLiteStore) SearchWithAdvancedFilter

func (s *SQLiteStore) SearchWithAdvancedFilter(ctx context.Context, query []float32, opts AdvancedSearchOptions) ([]ScoredEmbedding, error)

SearchWithAdvancedFilter performs vector search with advanced filtering

func (*SQLiteStore) SearchWithDiversity

func (s *SQLiteStore) SearchWithDiversity(ctx context.Context, query []float32, opts DiversitySearchOptions) ([]ScoredEmbedding, error)

SearchWithDiversity performs search with result diversification

func (*SQLiteStore) SearchWithFacets

func (s *SQLiteStore) SearchWithFacets(ctx context.Context, query []float32, opts FacetedSearchOptions) ([]ScoredEmbedding, []FacetResult, error)

SearchWithFacets performs vector search with faceted filtering

func (*SQLiteStore) SearchWithFilter

func (s *SQLiteStore) SearchWithFilter(ctx context.Context, query []float32, opts SearchOptions, metadataFilters map[string]interface{}) ([]ScoredEmbedding, error)

SearchWithFilter performs vector similarity search with advanced metadata filtering

func (*SQLiteStore) SearchWithNegatives

func (s *SQLiteStore) SearchWithNegatives(ctx context.Context, opts NegativeSearchOptions) ([]ScoredEmbedding, error)

SearchWithNegatives performs search with negative examples

func (*SQLiteStore) SearchWithReranker

func (s *SQLiteStore) SearchWithReranker(ctx context.Context, queryVec []float32, queryText string, reranker Reranker, opts RerankOptions) ([]ScoredEmbedding, error)

SearchWithReranker performs vector search and then reranks the results

func (*SQLiteStore) SetAutoDimAdapt

func (s *SQLiteStore) SetAutoDimAdapt(policy AdaptPolicy)

SetAutoDimAdapt sets the dimension adaptation policy

func (*SQLiteStore) SetLogger

func (s *SQLiteStore) SetLogger(logger Logger)

SetLogger sets the logger for the store

func (*SQLiteStore) Stats

func (s *SQLiteStore) Stats(ctx context.Context) (StoreStats, error)

Stats returns statistics about the store

func (*SQLiteStore) StreamSearch

func (s *SQLiteStore) StreamSearch(ctx context.Context, query []float32, opts StreamingOptions) (<-chan StreamingResult, error)

StreamSearch performs incremental vector search with results streaming

func (*SQLiteStore) SyncDeletedEmbeddingIDs added in v2.14.1

func (s *SQLiteStore) SyncDeletedEmbeddingIDs(_ context.Context, ids []string)

SyncDeletedEmbeddingIDs removes committed embedding deletions from in-memory indexes.

func (*SQLiteStore) SyncUpsertedEmbeddings added in v2.14.1

func (s *SQLiteStore) SyncUpsertedEmbeddings(_ context.Context, embs []*Embedding)

SyncUpsertedEmbeddings updates in-memory indexes after embeddings were committed through UpsertBatchTx.

func (*SQLiteStore) TrainIndex

func (s *SQLiteStore) TrainIndex(ctx context.Context, numCentroids int) error

TrainIndex trains the index with existing data

func (*SQLiteStore) TrainQuantizer

func (s *SQLiteStore) TrainQuantizer(ctx context.Context) error

TrainQuantizer trains the quantizer on existing vectors

func (*SQLiteStore) UpdateDocument

func (s *SQLiteStore) UpdateDocument(ctx context.Context, doc *Document) error

UpdateDocument updates an existing document's metadata and other fields

func (*SQLiteStore) Upsert

func (s *SQLiteStore) Upsert(ctx context.Context, emb *Embedding) error

Upsert inserts or updates a single embedding

func (*SQLiteStore) UpsertBatch

func (s *SQLiteStore) UpsertBatch(ctx context.Context, embs []*Embedding) error

UpsertBatch inserts or updates multiple embeddings in a transaction

func (*SQLiteStore) UpsertBatchTx added in v2.14.1

func (s *SQLiteStore) UpsertBatchTx(ctx context.Context, tx *sql.Tx, embs []*Embedding) error

UpsertBatchTx writes embeddings inside an existing transaction. Call SyncUpsertedEmbeddings after commit.

func (*SQLiteStore) UpsertBatchWithAdapt added in v2.13.0

func (s *SQLiteStore) UpsertBatchWithAdapt(ctx context.Context, embs []*Embedding) error

UpsertBatchWithAdapt inserts or updates multiple embeddings with automatic dimension adaptation. Unlike UpsertBatch, this function handles dimension mismatches by adapting vectors to match the store's configured dimension before insertion.

func (*SQLiteStore) UpsertMultiVector

func (s *SQLiteStore) UpsertMultiVector(ctx context.Context, entity *MultiVectorEntity) error

UpsertMultiVector inserts or updates a multi-vector entity

type ScoreNormalizationReranker

type ScoreNormalizationReranker struct {
	MinScore float64
	MaxScore float64
}

ScoreNormalizationReranker normalizes scores to a specific range

func NewScoreNormalizationReranker

func NewScoreNormalizationReranker(min, max float64) *ScoreNormalizationReranker

NewScoreNormalizationReranker creates a new score normalizer

func (*ScoreNormalizationReranker) Rerank

func (norm *ScoreNormalizationReranker) Rerank(ctx context.Context, query string, results []ScoredEmbedding) ([]ScoredEmbedding, error)

Rerank normalizes all scores to the specified range

type ScoredEmbedding

type ScoredEmbedding struct {
	Embedding
	Score float64 `json:"score"`
}

ScoredEmbedding represents an embedding with similarity score

func CollectTopKFromStream

func CollectTopKFromStream(ctx context.Context, stream <-chan StreamingResult, k int) ([]ScoredEmbedding, error)

CollectTopKFromStream collects top-k results from a streaming channel

type SearchOptions

type SearchOptions struct {
	Collection string            `json:"collection,omitempty"` // Collection name to search in
	TopK       int               `json:"topK"`
	Filter     map[string]string `json:"filter,omitempty"`
	Threshold  float64           `json:"threshold,omitempty"`
	QueryText  string            `json:"queryText,omitempty"`  // Optional query text for enhanced matching
	TextWeight float64           `json:"textWeight,omitempty"` // Weight for text similarity (0.0-1.0, default 0.3)
}

SearchOptions defines options for vector search

type Session

type Session struct {
	ID        string                 `json:"id"`
	UserID    string                 `json:"user_id"`
	Metadata  map[string]interface{} `json:"metadata,omitempty"`
	CreatedAt time.Time              `json:"created_at"`
	UpdatedAt time.Time              `json:"updated_at"`
}

Session represents a chat session or conversation thread

type SimilarityFunc

type SimilarityFunc func(a, b []float32) float64

SimilarityFunc defines a function that calculates similarity between two vectors

func GetCosineSimilarity

func GetCosineSimilarity() SimilarityFunc

GetCosineSimilarity returns the cosine similarity function

func GetDotProduct

func GetDotProduct() SimilarityFunc

GetDotProduct returns the dot product function

func GetEuclideanDist

func GetEuclideanDist() SimilarityFunc

GetEuclideanDist returns the euclidean distance function

type Store

type Store interface {
	// Init initializes the store, creates necessary tables, and builds/loads indexes.
	// It must be called before any other operation.
	Init(ctx context.Context) error

	// Upsert inserts or updates a single embedding.
	// If the vector dimension doesn't match the store's dimension, it applies the adaptation policy.
	Upsert(ctx context.Context, emb *Embedding) error

	// UpsertBatch inserts or updates multiple embeddings in a single database transaction.
	// This is significantly faster than calling Upsert multiple times.
	UpsertBatch(ctx context.Context, embs []*Embedding) error

	// Search performs a vector similarity search.
	// It uses the configured index (HNSW or IVF) if available, otherwise falls back to linear search.
	Search(ctx context.Context, query []float32, opts SearchOptions) ([]ScoredEmbedding, error)

	// RangeSearch finds all vectors within a specified distance (radius) from the query.
	RangeSearch(ctx context.Context, query []float32, radius float32, opts SearchOptions) ([]ScoredEmbedding, error)

	// Delete removes an embedding by its unique ID.
	Delete(ctx context.Context, id string) error

	// DeleteByDocID removes all embeddings associated with a specific document ID.
	DeleteByDocID(ctx context.Context, docID string) error

	// DeleteBatch removes multiple embeddings by their IDs in a single operation.
	DeleteBatch(ctx context.Context, ids []string) error

	// DeleteByFilter removes embeddings matching the given metadata filter criteria.
	DeleteByFilter(ctx context.Context, filter *MetadataFilter) error

	// Close closes the store, releases database connections, and persists memory indexes.
	Close() error

	// Stats returns global statistics about the vector store (count, dimensions, size).
	Stats(ctx context.Context) (StoreStats, error)

	// CreateCollection creates a new named collection for multi-tenant isolation.
	CreateCollection(ctx context.Context, name string, dimensions int) (*Collection, error)
	// GetCollection retrieves collection information by name.
	GetCollection(ctx context.Context, name string) (*Collection, error)
	// ListCollections lists all available collections.
	ListCollections(ctx context.Context) ([]*Collection, error)
	// DeleteCollection deletes a collection and all its associated data.
	DeleteCollection(ctx context.Context, name string) error
	// GetCollectionStats returns statistics for a specific collection.
	GetCollectionStats(ctx context.Context, name string) (*CollectionStats, error)

	// TrainIndex learns cluster centroids for IVF indexes from existing data.
	TrainIndex(ctx context.Context, numCentroids int) error
	// TrainQuantizer learns value ranges for scalar quantization from existing data.
	TrainQuantizer(ctx context.Context) error

	// CreateDocument creates a document record for source tracking and versioning.
	CreateDocument(ctx context.Context, doc *Document) error
	// GetDocument retrieves a document record by its ID.
	GetDocument(ctx context.Context, id string) (*Document, error)
	// DeleteDocument deletes a document and all its linked embeddings (cascading).
	DeleteDocument(ctx context.Context, id string) error
	// ListDocumentsWithFilter lists documents matching specific criteria like author.
	ListDocumentsWithFilter(ctx context.Context, author string, limit int) ([]*Document, error)

	// CreateSession starts a new conversation thread for chat memory.
	CreateSession(ctx context.Context, session *Session) error
	// GetSession retrieves a chat session by its ID.
	GetSession(ctx context.Context, id string) (*Session, error)
	// AddMessage appends a new message (user or assistant) to a session.
	AddMessage(ctx context.Context, msg *Message) error
	// GetSessionHistory returns the chronological message history for a session.
	GetSessionHistory(ctx context.Context, sessionID string, limit int) ([]*Message, error)
	// SearchChatHistory performs semantic search over previous messages in a session.
	SearchChatHistory(ctx context.Context, queryVec []float32, sessionID string, limit int) ([]*Message, error)

	// SearchWithACL performs vector search while enforcing access control rules.
	SearchWithACL(ctx context.Context, query []float32, acl []string, opts SearchOptions) ([]ScoredEmbedding, error)
	// HybridSearch combines vector similarity with FTS5 keyword matching using RRF fusion.
	HybridSearch(ctx context.Context, vectorQuery []float32, textQuery string, opts HybridSearchOptions) ([]ScoredEmbedding, error)
	// SearchWithAdvancedFilter performs vector search with complex boolean and range metadata filters.
	SearchWithAdvancedFilter(ctx context.Context, query []float32, opts AdvancedSearchOptions) ([]ScoredEmbedding, error)
}

Store defines the core interface for vector storage operations. It provides a high-level API for managing embeddings, documents, chat history, and collections.

type StoreError

type StoreError struct {
	Op  string // Operation name
	Err error  // Underlying error
}

StoreError wraps errors with operation context

func (*StoreError) Error

func (e *StoreError) Error() string

Error implements the error interface

func (*StoreError) Is

func (e *StoreError) Is(target error) bool

Is checks if the error matches the target

func (*StoreError) Unwrap

func (e *StoreError) Unwrap() error

Unwrap returns the underlying error

type StoreStats

type StoreStats struct {
	Count      int64 `json:"count"`
	Dimensions int   `json:"dimensions"`
	Size       int64 `json:"size"`
}

StoreStats provides statistics about the vector store

type StreamingOptions

type StreamingOptions struct {
	SearchOptions
	BatchSize        int                        // Number of vectors to process per batch
	MaxLatency       time.Duration              // Maximum time to wait before sending partial results
	EarlyTerminate   bool                       // Stop when enough good results are found
	QualityThreshold float64                    // Score threshold for early termination
	ProgressCallback func(processed, total int) // Optional progress reporting
}

StreamingOptions configures streaming search behavior

type StreamingResult

type StreamingResult struct {
	ScoredEmbedding
	Timestamp time.Time
	BatchID   int
}

StreamingResult represents a single result in streaming search

type TextSimilarity

type TextSimilarity interface {
	CalculateSimilarity(query, text string) float64
}

TextSimilarity interface for text-based similarity calculations

type TextSimilarityConfig

type TextSimilarityConfig struct {
	Enabled       bool    `json:"enabled"`       // Enable text similarity matching
	DefaultWeight float64 `json:"defaultWeight"` // Default weight for text similarity (0.0-1.0)
}

TextSimilarityConfig represents configuration for text-based similarity

func DefaultTextSimilarityConfig

func DefaultTextSimilarityConfig() TextSimilarityConfig

DefaultTextSimilarityConfig returns default text similarity configuration

Jump to

Keyboard shortcuts

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