core

package
v0.0.0-...-1f21b64 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2025 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CosineSimilarity

func CosineSimilarity(a, b []float64) (float64, error)

Types

type Client

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

func NewClient

func NewClient(options ...ClientOption) (*Client, error)

func (*Client) Close

func (c *Client) Close() error

func (*Client) DeleteOne

func (c *Client) DeleteOne(ctx context.Context, tableName string, keys Row) error

func (*Client) Find

func (c *Client) Find(ctx context.Context, tableName string, query Query, options ...FindOption) (MultiResult, error)

func (*Client) FindStream

func (c *Client) FindStream(ctx context.Context, tableName string, query Query, ch chan Row, options ...FindOption) error

func (*Client) Get

func (c *Client) Get(ctx context.Context, tableName string, keys Row) (SingleResult, error)

func (*Client) GetTable

func (c *Client) GetTable(tableName string) (Table, error)

func (*Client) SetTable

func (c *Client) SetTable(table Table) error

func (*Client) Tables

func (c *Client) Tables() (Tables, error)

func (*Client) UpsertOne

func (c *Client) UpsertOne(ctx context.Context, tableName string, row Row) error

func (*Client) VectorSearch

func (c *Client) VectorSearch(ctx context.Context, tableName string, query Query, options ...SearchOption) (MultiResult, error)

type ClientOption

type ClientOption func(*ClientOptions)

func WithDBPath

func WithDBPath(dbPath string) ClientOption

func WithLogger

func WithLogger(logger *slog.Logger) ClientOption

type ClientOptions

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

type Collector

type Collector[T any] struct {
	// contains filtered or unexported fields
}

func NewCollector

func NewCollector[T any](cmp func(T, T) int) Collector[T]

func (*Collector[T]) Insert

func (w *Collector[T]) Insert(item T)

func (*Collector[T]) Slice

func (w *Collector[T]) Slice() []T

func (*Collector[T]) TopK

func (w *Collector[T]) TopK(topK int) []T

type EmbeddedQuery

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

func (*EmbeddedQuery) GetPrimary

func (q *EmbeddedQuery) GetPrimary() QuickMap

func (*EmbeddedQuery) GetVector

func (q *EmbeddedQuery) GetVector() []float64

func (*EmbeddedQuery) Match

func (q *EmbeddedQuery) Match(r Row) bool

func (*EmbeddedQuery) SetVector

func (q *EmbeddedQuery) SetVector(vector []float64)

func (*EmbeddedQuery) String

func (q *EmbeddedQuery) String() string

type FindOption

type FindOption func(*FindOptions)

func WithFindLimit

func WithFindLimit(limit int) FindOption

func WithFindOrder

func WithFindOrder(order func(Row, Row) int) FindOption

func WithFindStartAtIndex

func WithFindStartAtIndex(startAtIndex Row) FindOption

type FindOptions

type FindOptions struct {
	Limit               int
	StartAtIndex        *Row
	SimilarityThreshold float64
	Order               func(Row, Row) int
}

type IndexFields

type IndexFields []string

func (IndexFields) FullKey

func (i IndexFields) FullKey(prefix string, row Row) ([]byte, error)

func (IndexFields) PartialKey

func (i IndexFields) PartialKey(prefix string, query Query) ([]byte, error)

type Metrics

type Metrics struct {
	QueryStart    time.Time     `yaml:"queryStart"`
	QueryDuration time.Duration `yaml:"queryDuration"`
}

func (*Metrics) End

func (m *Metrics) End()

func (*Metrics) Start

func (m *Metrics) Start()

func (*Metrics) String

func (m *Metrics) String() string

type MultiResult

type MultiResult struct {
	Rows    Rows
	Metrics Metrics
	Err     error
}

func NewMultiResult

func NewMultiResult() MultiResult

func (*MultiResult) ToYAML

func (i *MultiResult) ToYAML() []byte

type Query

type Query interface {
	GetPrimary() QuickMap
	Match(r Row) bool
	GetVector() []float64
	SetVector(vector []float64)
	String() string
}

func NewEmbeddedQuery

func NewEmbeddedQuery(primary QuickMap, match func(row Row) bool) Query

type QuickMap

type QuickMap map[string]any

func NewQuickMap

func NewQuickMap(kv ...any) QuickMap

func (QuickMap) As

func (m QuickMap) As(t any) error

func (QuickMap) Get

func (m QuickMap) Get(key string) any

func (QuickMap) GetString

func (m QuickMap) GetString(key string) (string, bool)

func (QuickMap) MustGetString

func (m QuickMap) MustGetString(key string) string

type Row

type Row struct {
	Index           []byte    `yaml:"-" json:"-"`
	Data            QuickMap  `yaml:"data" json:"data"`
	Vector          []float64 `yaml:"-" json:"vector"`
	SimilarityScore float64   `yaml:"similarityScore,omitempty" json:"similarityScore,omitempty"`
}

func NewRow

func NewRow(data map[string]any, options ...RowOption) Row

func RowFromItem

func RowFromItem(item *badger.Item) (Row, error)

func (*Row) FromBytes

func (r *Row) FromBytes(data []byte) error

func (*Row) FromItem

func (r *Row) FromItem(item *badger.Item) error

func (*Row) GetVector

func (r *Row) GetVector() []float64

func (*Row) Matches

func (r *Row) Matches(row Row) bool

func (*Row) Set

func (r *Row) Set(key string, value any)

func (*Row) SetSimilarityScore

func (r *Row) SetSimilarityScore(score float64)

func (*Row) String

func (r *Row) String() string

func (*Row) ToBytes

func (r *Row) ToBytes() ([]byte, error)

type RowOption

type RowOption func(options *RowOptions)

func WithVector

func WithVector(vector []float64) RowOption

type RowOptions

type RowOptions struct {
	Index  []byte
	Vector []float64
}

type Rows

type Rows []Row

func (Rows) Data

func (r Rows) Data() []QuickMap

type SearchOption

type SearchOption func(*SearchOptions)

func WithSearchLimit

func WithSearchLimit(limit int) SearchOption

func WithSearchSimilarityThreshold

func WithSearchSimilarityThreshold(threshold float64) SearchOption

type SearchOptions

type SearchOptions struct {
	Limit               int
	SimilarityThreshold float64
}

type SingleResult

type SingleResult struct {
	Row     Row
	Metrics Metrics
	Err     error
}

func NewSingleResult

func NewSingleResult() SingleResult

func (*SingleResult) ToYAML

func (i *SingleResult) ToYAML() []byte

type Table

type Table struct {
	Name               string      `yaml:"name"`
	PrimaryIndexFields IndexFields `yaml:"primaryIndexFields"`
}

func (*Table) FromBytes

func (t *Table) FromBytes(data []byte) error

func (*Table) PartialPrimaryKey

func (t *Table) PartialPrimaryKey(query Query) ([]byte, error)

func (*Table) PrimaryKey

func (t *Table) PrimaryKey(row Row) ([]byte, error)

func (*Table) String

func (t *Table) String() string

func (*Table) ToBytes

func (t *Table) ToBytes() ([]byte, error)

func (*Table) ToYAML

func (t *Table) ToYAML() []byte

type Tables

type Tables []Table

func (*Tables) String

func (t *Tables) String() string

Jump to

Keyboard shortcuts

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