Documentation
¶
Index ¶
- Constants
- Variables
- func CosDistance(t T, t2 T) (float64, error)
- func Encode(appendTo []byte, t T) ([]byte, error)
- func InnerProduct(t T, t2 T) (float64, error)
- func L1Distance(t T, t2 T) (float64, error)
- func L2Distance(t T, t2 T) (float64, error)
- func NegInnerProduct(t T, t2 T) (float64, error)
- func Norm(t T) float64
- type Set
- func (vs *Set) Add(v T)
- func (vs *Set) AddSet(vectors Set)
- func (vs *Set) AddUndefined(count int)
- func (vs *Set) AsMatrix() num32.Matrix
- func (vs *Set) At(offset int) T
- func (vs *Set) Centroid(centroid T) T
- func (vs *Set) Clear()
- func (vs *Set) Clone() Set
- func (*Set) Descriptor() ([]byte, []int)
- func (vs *Set) EnsureCapacity(capacity int)
- func (vs *Set) Equal(other *Set) bool
- func (m *Set) Marshal() (dAtA []byte, err error)
- func (m *Set) MarshalTo(dAtA []byte) (int, error)
- func (m *Set) MarshalToSizedBuffer(dAtA []byte) (int, error)
- func (*Set) ProtoMessage()
- func (vs *Set) ReplaceWithLast(offset int)
- func (m *Set) Reset()
- func (m *Set) Size() (n int)
- func (vs *Set) Slice(offset, count int) Set
- func (vs *Set) SplitAt(offset int) Set
- func (m *Set) String() string
- func (m *Set) Unmarshal(dAtA []byte) error
- func (m *Set) XXX_DiscardUnknown()
- func (m *Set) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (m *Set) XXX_Merge(src proto.Message)
- func (m *Set) XXX_Size() int
- func (m *Set) XXX_Unmarshal(b []byte) error
- type T
Constants ¶
const MaxDim = 16000
MaxDim is the maximum number of dimensions a vector can have.
Variables ¶
Functions ¶
func CosDistance ¶
CosDistance returns the cosine distance between t and t2. This represents the similarity between the two vectors, ranging from 0 (most similar) to 2 (least similar). Only the angle between the vectors matters; the norms (magnitudes) are irrelevant.
func InnerProduct ¶
InnerProduct returns the inner product of t1 and t2.
func L1Distance ¶
L1Distance returns the L1 (Manhattan) distance between t and t2.
func L2Distance ¶
L2Distance returns the Euclidean distance between t and t2.
func NegInnerProduct ¶
NegInnerProduct returns the negative inner product of t1 and t2.
Types ¶
type Set ¶
type Set struct { // Dims is the number of dimensions of each vector in the set. Dims int `protobuf:"varint,1,opt,name=dims,proto3,casttype=int" json:"dims,omitempty"` // Count is the number of vectors in the set. Count int `protobuf:"varint,2,opt,name=count,proto3,casttype=int" json:"count,omitempty"` // Data is a float32 slice that contains all vectors, laid out contiguously in // row-wise order in memory. // NB: Avoid using this field directly, instead preferring to use the At // function to access individual vectors. Data []float32 `protobuf:"fixed32,3,rep,packed,name=data,proto3" json:"data,omitempty"` }
Set is a set of float32 vectors of equal dimension. Vectors in the set are stored contiguously in a slice, in row-wise order. They are assumed to be unordered; some methods do not preserve ordering.
func MakeSet ¶
MakeSet constructs a new empty vector set with the given number of dimensions. New vectors can be added via the Add or AddSet methods.
func MakeSetFromRawData ¶
MakeSetFromRawData constructs a new vector set from a raw slice of vectors. The vectors in the slice have the given number of dimensions and are laid out contiguously in row-wise order. NB: The data slice is directly used rather than copied; do not use it outside the context of this vector set after this point.
func (*Set) AddUndefined ¶
AddUndefined adds the given number of vectors to this set. The vectors should be set to defined values before use.
func (*Set) AsMatrix ¶
AsMatrix returns this set as a matrix, to be used with the num32 package. NB: The underlying float32 slice is shared by the resulting matrix, so any changes will affect both the vector set and matrix.
func (*Set) At ¶
At returns the vector at the given offset in the set. The returned vector is intended for transient use, since mutations to the vector set can invalidate the reference.
func (*Set) Centroid ¶
Centroid calculates the mean of each dimension across all vectors in the set and writes the resulting averages to the provided centroid slice. The slice must be pre-allocated by the caller, with its length set to the number of dimensions (Dims field) of the vectors in the set.
func (*Set) Clone ¶
Clone performs a deep copy of the vector set. Changes to the original or clone will not affect the other.
func (*Set) Descriptor ¶
func (*Set) EnsureCapacity ¶
EnsureCapacity grows the underlying data slice if needed to ensure the requested capacity. This is useful to prevent unnecessary resizing when it's known up-front how big the vector set will need to get.
func (*Set) Equal ¶
Equal returns true if this set is equal to the other set. Two sets are equal if they have the same number of dimensions, the same number of vectors, and the same values in the same order.
func (*Set) ProtoMessage ¶
func (*Set) ProtoMessage()
func (*Set) ReplaceWithLast ¶
ReplaceWithLast removes the vector at the given offset from the set, replacing it with the last vector in the set. The modified set has one less element and the last vector's position changes.
func (*Set) Slice ¶
Slice returns a vector set that contains a subset of "count" vectors, starting at the given offset.
NOTE: Slice returns a set that references the same memory as this set. Modifications to one set may be visible in the other set, so callers should typically ensure that both sets are immutable after calling Slice.
func (*Set) SplitAt ¶
SplitAt divides the vector set into two subsets at the given offset. This vector set is updated to contain only the vectors before the split point, and the returned set contains only the vectors on or after the split point.
func (*Set) XXX_DiscardUnknown ¶
func (m *Set) XXX_DiscardUnknown()
func (*Set) XXX_Unmarshal ¶
type T ¶
type T []float32
T is the type of a PGVector-like vector.
func ParseVector ¶
ParseVector parses the Postgres string representation of a vector.