Bring your own
Reference for CallableEmbedder — wrap any embedding function (OpenAI, BGE, a local model) into a Telys embedder with a matching EmbeddingProfile.
CallableEmbedder turns any text-to-vector function into a Telys embedder. Point it at an OpenAI call, a local sentence-transformers model, or a bespoke lexical hasher — anything that returns a 2-D float32 array — and pair it with an EmbeddingProfile that declares the vector space.
from telys.embedding import CallableEmbedder, EmbeddingProfileSignature
CallableEmbedder(fn, profile, query_fn=None)fn
Callable[[list[str]], np.ndarray]
(required)
Embeds documents. Takes a list of strings, returns an [N, D] float32 array.
profile
EmbeddingProfile
(required)
Declares the vector space: dimension, normalization, distance, provider/model identity.
query_fn
Callable[[list[str]], np.ndarray] | None
None
Optional separate embedder for queries. When None, fn is used for both.
CallableEmbedder satisfies the EmbeddingProvider protocol, so a collection uses it exactly like the built-in Algenta* embedders.
The fn contract
Your function receives a list of strings and must return a NumPy array. On every call CallableEmbedder asserts:
result.ndim == 2— one row per input, one column per dimension.result.shape[1] == profile.dimension— the width matches the declared space.
Return one row per input text, in order, as float32. Cast if your model emits float64 or a Python list: np.asarray(vecs, dtype="float32").
Methods
As an EmbeddingProvider, an instance exposes:
.profile
EmbeddingProfile
The space you passed in. Its space_id() gates reopen/attach.
embed_documents(texts)
[N, D] float32
Calls fn; runs the shape assertions.
embed_queries(texts)
[N, D] float32
Calls query_fn if given, otherwise fn.
A minimal, offline example
This toy embedder needs no network or extra packages; it shows the mechanics only. Swap fn for a real model (see the recipes below) before relying on results.
The dim passed to create_collection must equal profile.dimension, or the two disagree about the space. See Dimensions & space IDs.
Separate query embedding
Some models embed queries differently from documents — for example, instruction-tuned retrieval models prepend a task prefix to queries only. Pass query_fn for that asymmetry:
add_texts / upsert_texts route through embed_documents; search_text routes through embed_queries. Both run the same shape assertions.
Building a matching profile
The profile identifies the space your vectors live in. Two collections are compatible only when their profiles share a space_id(). Set the fields that describe your model honestly:
Changing model_id, dimension, normalization, or distance produces a different space_id(), making the new embedder incompatible with a collection built under the old one. Full field reference: EmbeddingProfile & space compatibility.
Common errors
See also
EmbeddingProfile & space compatibility — every profile field and how identity is computed.
Recipe: OpenAI embeddings — a complete cloud-backed
CallableEmbedder.Recipe: BGE / sentence-transformers — a fully offline
CallableEmbedder.Choosing an embedder — when to reach for BYO vs the built-in lexical embedders.
Embedders API — the full
telys.embeddingsurface.
Last updated
Was this helpful?