embed

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2026 License: MIT Imports: 6 Imported by: 0

README

embed

embedder := embed.NewHashing(64)
result, err := embedder.Embed(ctx, embedding.Request{Inputs: []string{"hello"}})

embed provides a deterministic hashing embedder for examples, tests, and reliquary.Quickstart.

It has no model runtime, API key, provider SDK, network dependency, or production quality claim.

Documentation

Overview

Package embed provides deterministic, dependency-free embedding helpers for demos, tests, and reliquary.Quickstart.

The hashing embedder maps text to normalized vectors with the signed feature hashing trick. It is useful for examples and local tests, but it is not a replacement for a production embedding model.

Package embed provides a deterministic, dependency-free embedding.Embedder for demos, tests, and reliquary.Quickstart. It maps text to vectors with the signed feature-hashing trick, so callers obtain meaningful (non-trivial cosine) vectors without an ONNX runtime or API key.

It is a stand-in for a real embedding model, not a replacement: quality is suitable for examples and tests only, never production retrieval.

Index

Examples

Constants

View Source
const DefaultHashingDim = 256

DefaultHashingDim is used when callers pass a non-positive dimension. It is intentionally small and deterministic for demos and tests, not production retrieval quality.

Variables

This section is empty.

Functions

func HashVector

func HashVector(text string, dim int) embedding.Vector

HashVector maps text to an L2-normalized []float32 via signed feature hashing. Non-positive dimensions use DefaultHashingDim.

Types

type Hashing

type Hashing struct {
	Model embedding.ModelRef
}

Hashing is a deterministic hashing-trick embedder implementing embedding.Embedder.

func NewHashing

func NewHashing(dim int) *Hashing

NewHashing returns a Hashing embedder producing L2-normalized vectors of the given width. Non-positive dimensions use DefaultHashingDim.

func (*Hashing) Embed

func (h *Hashing) Embed(ctx context.Context, req embedding.Request) (embedding.Result, error)

Embed satisfies embedding.Embedder.

Example
package main

import (
	"context"
	"fmt"

	"github.com/dotcommander/reliquary/embed"
	"github.com/dotcommander/reliquary/embedding"
)

func main() {
	embedder := embed.NewHashing(8)
	result, err := embedder.Embed(context.Background(), embedding.Request{Inputs: []string{"hello world"}})
	fmt.Println(len(result.Vectors), len(result.Vectors[0]), err == nil)
}
Output:
1 8 true

Jump to

Keyboard shortcuts

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