search

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Index type threshold
	MaxFlatSize int // Use flat index below this size (default: 50000)

	// IVF parameters
	NList  int // Number of clusters (default: 4096)
	NProbe int // Number of clusters to search (default: 8)

	// PQ parameters
	M     int // Number of subquantizers (default: 64)
	NBits int // Bits per subquantizer (default: 8)

	// HNSW parameters
	HNSWEnabled bool // Use HNSW for centroid routing (default: true)
	HNSWM       int  // HNSW connections (default: 16)
	HNSWEfC     int  // HNSW construction parameter (default: 200)

	// Search parameters
	RerankSize  int  // Number of candidates to rerank (default: 128)
	UseParallel bool // Use parallel search (default: true)
}

Config holds engine configuration

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns default configuration

type Engine

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

Engine is the main search engine combining IVF-HNSW-PQ with reranking

func NewEngine

func NewEngine(config Config) *Engine

NewEngine creates a new search engine

func (*Engine) Add

func (e *Engine) Add(vec simd.Vec512, scale float32, id int) error

Add adds a vector to the index

func (*Engine) AddBatch

func (e *Engine) AddBatch(vectors []simd.Vec512, scales []float32, ids []int) error

AddBatch adds multiple vectors efficiently

func (*Engine) Search

func (e *Engine) Search(query *simd.Vec512, k int) ([]SearchResult, error)

Search performs k-NN search

func (*Engine) SetTrained

func (e *Engine) SetTrained(trained bool)

SetTrained sets the trained flag (used when loading from cache)

func (*Engine) Stats

func (e *Engine) Stats() IndexStats

Stats returns index statistics

func (*Engine) Train

func (e *Engine) Train(vectors []simd.Vec512, scales []float32) error

Train trains the index on sample data

type IndexStats

type IndexStats struct {
	Size        int
	IndexType   string
	MemoryUsage int64
	NLists      int
	ListSizes   []int
	PQEnabled   bool
	PQM         int
	PQBits      int
	HNSWEnabled bool
}

IndexStats contains index statistics

type SearchResult

type SearchResult struct {
	ID       int
	Score    float32
	Distance float32
}

SearchResult represents a search result

Jump to

Keyboard shortcuts

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