vector

package
v0.61.0 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package vector owns finite numeric coordinates and their JSON representation. Embedding models and vector stores share these values; dimensions, metrics, encoder-space identity, and operation errors belong to their consuming domain. Float32 narrows values at the native storage boundary, whose precision and magnitude constraints determine whether the projection can be indexed.

Example
package main

import (
	jsonv2 "encoding/json/v2"
	"errors"
	"fmt"

	"github.com/Tangerg/scope/core/vector"
)

func main() {
	var coordinates vector.Coordinates[float64]
	if err := jsonv2.Unmarshal([]byte(`[0,1.5]`), &coordinates); err != nil {
		panic(err)
	}
	fmt.Println(vector.Float32(coordinates))
	err := jsonv2.Unmarshal([]byte(`[1,null]`), &coordinates)
	fmt.Println(errors.Is(err, vector.ErrInvalidCoordinates), coordinates)
}
Output:
[0 1.5]
true [0 1.5]

Index

Examples

Constants

This section is empty.

Variables

View Source
var ErrInvalidCoordinates = errors.New("vector: invalid coordinates")

Functions

func Float32

func Float32(source []float64) []float32

Float32 narrows coordinates for stores that index in single precision. The storage boundary owns its metric's precision and magnitude constraints.

Types

type Coordinates

type Coordinates[T float32 | float64] []T

Coordinates contains measured, finite components. JSON null is unknown, so decoding it must not invent a measured zero component.

func (Coordinates[T]) JSONSchemaModel

func (Coordinates[T]) JSONSchemaModel() any

func (Coordinates[T]) MarshalJSON

func (c Coordinates[T]) MarshalJSON() ([]byte, error)

func (*Coordinates[T]) UnmarshalJSON

func (c *Coordinates[T]) UnmarshalJSON(data []byte) error

func (Coordinates[T]) Validate

func (c Coordinates[T]) Validate() error

Jump to

Keyboard shortcuts

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