ion7-llm / embed

class

ion7.llm.Embed

_model ion7.core.Model
_vocab ion7.core.Vocab
_ctx ion7.core.Context? Lazily created at first call.
_opts table

Functions

Embed.new

Build an embedder.

Embed.new(model, opts)
modelion7.core.Model
optstable?
→ ion7.llm.Embed

Embed:_ensure_ctx

Lazy : build the embedding context on first use.

Embed:_ensure_ctx()

Embed:encode

Encode `text` into a Lua array of floats. The array length is the model's output embedding dimension (typically 384 / 768 / 1024 / 1536 / 4096 depending on the model).

Embed:encode(text)
textstring
→ number[]1-based array of n_embd floats.

Embed:encode_many

Encode a list of texts. Each text gets its own forward pass — no batched packing yet, but the embedding context is reused so the per-call overhead is tokenisation + decode only.

Embed:encode_many(texts)
textsstring[]
→ number[][]

Embed.cosine

Cosine similarity between two equal-length float arrays. Returns a scalar in `[-1, 1]`.

Embed.cosine(a, b)
anumber[]
bnumber[]
→ number

Embed:pooling

Pooling strategy of the underlying context (after lazy creation), as a symbolic string. Useful for diagnostics.

Embed:pooling()
→ string

Embed:free

Free the embedding context immediately. The model is left alone (the caller still owns it). Calling `:encode` after `:free` will lazy-rebuild a fresh context.

Embed:free()