Documentation
¶
Overview ¶
Package faiss provides bindings to Faiss, a library for vector similarity search. More detailed documentation can be found at the Faiss wiki: https://github.com/facebookresearch/faiss/wiki.
Index ¶
Constants ¶
const ( MetricInnerProduct = C.METRIC_INNER_PRODUCT MetricL2 = C.METRIC_L2 MetricL1 = C.METRIC_L1 MetricLinf = C.METRIC_Linf MetricLp = C.METRIC_Lp MetricCanberra = C.METRIC_Canberra MetricBrayCurtis = C.METRIC_BrayCurtis MetricJensenShannon = C.METRIC_JensenShannon )
Metric type
const ( IOFlagMmap = C.FAISS_IO_FLAG_MMAP IOFlagReadOnly = C.FAISS_IO_FLAG_READ_ONLY )
IO flags
Variables ¶
This section is empty.
Functions ¶
func WriteIndex ¶ added in v0.2.0
WriteIndex writes an index to a file.
Types ¶
type IDSelector ¶
type IDSelector struct {
// contains filtered or unexported fields
}
IDSelector represents a set of IDs to remove.
func NewIDSelectorBatch ¶
func NewIDSelectorBatch(indices []int64) (*IDSelector, error)
NewIDSelectorBatch creates a new batch selector.
func NewIDSelectorRange ¶
func NewIDSelectorRange(imin, imax int64) (*IDSelector, error)
NewIDSelectorRange creates a selector that removes IDs on [imin, imax).
func (*IDSelector) Delete ¶
func (s *IDSelector) Delete()
Delete frees the memory associated with s.
type Index ¶
type Index interface {
// D returns the dimension of the indexed vectors.
D() int
// IsTrained returns true if the index has been trained or does not require
// training.
IsTrained() bool
// Ntotal returns the number of indexed vectors.
Ntotal() int64
// MetricType returns the metric type of the index.
MetricType() int
// Train trains the index on a representative set of vectors.
Train(x []float32) error
// Add adds vectors to the index.
Add(x []float32) error
// AddWithIDs is like Add, but stores xids instead of sequential IDs.
AddWithIDs(x []float32, xids []int64) error
// Search queries the index with the vectors in x.
// Returns the IDs of the k nearest neighbors for each query vector and the
// corresponding distances.
Search(x []float32, k int64) (distances []float32, labels []int64, err error)
// RangeSearch queries the index with the vectors in x.
// Returns all vectors with distance < radius.
RangeSearch(x []float32, radius float32) (*RangeSearchResult, error)
// Reset removes all vectors from the index.
Reset() error
// RemoveIDs removes the vectors specified by sel from the index.
// Returns the number of elements removed and error.
RemoveIDs(sel *IDSelector) (int, error)
// Delete frees the memory used by the index.
Delete()
// contains filtered or unexported methods
}
Index is a Faiss index.
Note that some index implementations do not support all methods. Check the Faiss wiki to see what operations an index supports.
type IndexFlat ¶
type IndexFlat struct {
Index
}
IndexFlat is an index that stores the full vectors and performs exhaustive search.
func NewIndexFlat ¶
NewIndexFlat creates a new flat index.
func NewIndexFlatIP ¶
NewIndexFlatIP creates a new flat index with the inner product metric type.
func NewIndexFlatL2 ¶
NewIndexFlatL2 creates a new flat index with the L2 metric type.
type IndexImpl ¶ added in v0.2.0
type IndexImpl struct {
Index
}
IndexImpl is an abstract structure for an index.
func IndexFactory ¶
IndexFactory builds a composite index. description is a comma-separated list of components.
type ParameterSpace ¶
type ParameterSpace struct {
// contains filtered or unexported fields
}
func NewParameterSpace ¶
func NewParameterSpace() (*ParameterSpace, error)
NewParameterSpace creates a new ParameterSpace.
func (*ParameterSpace) Delete ¶
func (p *ParameterSpace) Delete()
Delete frees the memory associated with p.
func (*ParameterSpace) SetIndexParameter ¶
func (p *ParameterSpace) SetIndexParameter(idx Index, name string, val float64) error
SetIndexParameter sets one of the parameters.
type RangeSearchResult ¶
type RangeSearchResult struct {
// contains filtered or unexported fields
}
RangeSearchResult is the result of a range search.
func (*RangeSearchResult) Delete ¶
func (r *RangeSearchResult) Delete()
Delete frees the memory associated with r.
func (*RangeSearchResult) Labels ¶
func (r *RangeSearchResult) Labels() (labels []int64, distances []float32)
Labels returns the unsorted IDs and respective distances for each query. The result for query i is labels[lims[i]:lims[i+1]].
func (*RangeSearchResult) Lims ¶
func (r *RangeSearchResult) Lims() []int
Lims returns a slice containing start and end indices for queries in the distances and labels slices returned by Labels.
func (*RangeSearchResult) Nq ¶
func (r *RangeSearchResult) Nq() int
Nq returns the number of queries.