Documentation
¶
Overview ¶
Package latent projects text into a representation space (JEPA or any embedding encoder) for semantic caching and latent guardrails.
Index ¶
- Constants
- Variables
- func Cosine(a, b []float32) float32
- func Dot(a, b []float32) float32
- func MarshalVector(v []float32) []byte
- func Normalize(v []float32) error
- func Tokenize(text string) []string
- func UnmarshalVector(b []byte) ([]float32, error)
- type Embedding
- type Encoder
- type Fallback
- type HTTPEncoder
- type HashEncoder
- type Memo
Constants ¶
const DefaultHashDims = 512
DefaultHashDims is the width of the local fallback encoder.
Variables ¶
var ErrInvalidVector = errors.New("latent: invalid vector")
ErrInvalidVector reports an encoder output that cannot be compared.
Functions ¶
func Dot ¶
Dot is the inner product of equal-length vectors; for unit vectors it is the cosine similarity. Mismatched lengths score 0 rather than panic.
func MarshalVector ¶
MarshalVector encodes v as little-endian float32s.
func Tokenize ¶
Tokenize folds text the way an attacker would try to evade a matcher: compatibility forms, diacritics, zero-width runes and common homoglyphs all collapse to plain lowercase Latin before splitting on non-alphanumerics.
func UnmarshalVector ¶
UnmarshalVector decodes the output of MarshalVector.
Types ¶
type Embedding ¶
Embedding is one unit-length vector and the encoder that produced it. Vectors from different models live in different spaces and are never compared.
type Fallback ¶
type Fallback struct {
// contains filtered or unexported fields
}
Fallback serves from primary and switches to secondary when it fails. The embeddings carry their model, so vectors from the two never get compared.
func NewFallback ¶
NewFallback chains primary (typically HTTP/JEPA) to secondary (typically local).
type HTTPEncoder ¶
type HTTPEncoder struct {
// contains filtered or unexported fields
}
HTTPEncoder calls an OpenAI-compatible /v1/embeddings endpoint, which is what a node-agent hosting a JEPA encoder (or any embedding server) serves.
func NewHTTPEncoder ¶
func NewHTTPEncoder(url, model, apiKey string, timeout time.Duration, client *http.Client) *HTTPEncoder
NewHTTPEncoder targets url with the given model name; timeout bounds one Encode call so a slow encoder cannot stall the request path.
type HashEncoder ¶
type HashEncoder struct {
// contains filtered or unexported fields
}
HashEncoder is a deterministic, in-process encoder built on signed feature hashing of words, word bigrams and character trigrams. It is lexical, not semantic: it keeps caching and guardrails alive when no JEPA encoder is up.
func NewHashEncoder ¶
func NewHashEncoder(dims int) *HashEncoder
NewHashEncoder returns a local encoder producing dims-wide vectors.
func (*HashEncoder) Model ¶
func (e *HashEncoder) Model() string
Model names the vector space; it changes whenever dims or features change.
type Memo ¶
type Memo struct {
// contains filtered or unexported fields
}
Memo is an in-memory LRU in front of an encoder. One request is encoded by both the latent guardrail and the semantic cache; the memo makes the second lookup free. Returned vectors are shared and must be treated as read-only.