vector

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: May 6, 2025 License: AGPL-3.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Score = func(x, y [][]float32) (float32, error) {
	var max float32
	for i := range x {
		for j := range y {
			similarity, err := cosineSimilarity(x[i], y[j])
			if err != nil {
				return 0, errors.Wrap(err, "calculate similarity")
			}
			if similarity > max {
				max = similarity
			}
		}
	}

	return max, nil
}

Functions

This section is empty.

Types

type Config

type Config struct {
	// M is the maximum number of neighbors to keep for each node.
	// The number of layer 0 is 2*M.
	M uint32

	// Ml is the level generation factor.
	Ml float32

	// EfSearch is the number of nodes to consider in the search phase.
	EfSearch uint32

	// EfConstruct is the number of nodes to consider in the construct phase.
	EfConstruct uint32
}

func (*Config) Validate

func (c *Config) Validate() error

type Dependencies

type Dependencies struct{}

type Factory

--- Factory code block ---

func NewFactory

func NewFactory(mockOn ...component.MockOption) Factory

type Index

type Index interface {
	component.Component
	index.Codec

	// Search returns feed IDs with vectors similar to the query vector.
	// If any chunk of the feed is similar to the query vector, the feed is returned.
	// And the score is the maximum score of the chunks.
	// But results may miss some similar feeds.
	// The result is a map of feed IDs to their similarity scores.
	// Score is in range [0, 1].
	Search(ctx context.Context, q []float32, threshold float32, limit int) (idWithScores map[uint64]float32, err error)

	// Add adds feed vectors to the index.
	// A feed may be split into multiple chunks, and each chunk is a vector.
	Add(ctx context.Context, id uint64, vectors [][]float32) (err error)
}

--- Interface code block ---

Jump to

Keyboard shortcuts

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