Skip to content
For the complete documentation index, see llms.txt. This page is also available as Markdown.

OpenAI recipe

Integration recipe — wrap OpenAI text-embedding-3-small in a CallableEmbedder with a matching EmbeddingProfile, then create a collection, add text, and search.

Wrap OpenAI's text-embedding-3-small (1536 dimensions) in a CallableEmbedder so Telys embeds documents and queries through the OpenAI API, while the vectors, index, and search stay on your machine.

Prerequisites

pip install telys openai numpy
telys login            # free telys_developer tier
telys runtime verify   # confirm the signed runtime is active
pipx install telys
pip install openai numpy
telys login
telys runtime verify

Set your OpenAI key in the environment; the OpenAI SDK reads it automatically:

export OPENAI_API_KEY="sk-..."

The full script

import numpy as np
from openai import OpenAI
from telys import Telys
from telys.embedding import CallableEmbedder, EmbeddingProfile

client = OpenAI()                       # reads OPENAI_API_KEY from the environment
MODEL = "text-embedding-3-small"
DIM = 1536

def embed(texts):
    resp = client.embeddings.create(model=MODEL, input=list(texts))
    vecs = [item.embedding for item in resp.data]
    return np.asarray(vecs, dtype="float32")

profile = EmbeddingProfile(
    provider="openai",
    model_id=MODEL,
    model_version="1",
    dimension=DIM,
    normalization="l2",                 # text-embedding-3-* returns unit vectors
    distance="ip",                      # inner product == cosine on unit vectors
)
embedder = CallableEmbedder(embed, profile)

ame = Telys("./telys-openai")
col = ame.create_collection("docs", dim=DIM, partition_by="scope",
                            filter_columns=("source",), embedder=embedder)

col.add_texts(
    texts=[
        "Telys runs entirely on-device.",
        "Vectors are stored locally and never uploaded.",
        "The signed runtime is verified before it loads.",
    ],
    ids=["a", "b", "c"],
    metadata=[
        {"scope": "demo", "source": "docs"},
        {"scope": "demo", "source": "docs"},
        {"scope": "demo", "source": "docs"},
    ],
)
col.save()

hits = col.search_text("where do my vectors live?", top_k=2, with_metadata=True)
for doc_id, score, meta in zip(hits["ids"], hits["scores"], hits["metadata"]):
    print(f"{doc_id}  {score:.3f}  {meta}")

What you will see

The two most relevant documents, ranked by inner-product score, with their metadata:

Exact scores vary with the model, but the ranking is stable: search_text embeds the query through embed and returns the nearest stored vectors. With with_metadata=True, each hit carries back only the columns you declared in filter_columns (here source) — the partition key scope is stored separately and is not echoed into metadata. add_texts inserts new rows only; it raises KeyError if an id already exists — use upsert_texts to replace.

text-embedding-3-small returns L2-normalized vectors, so distance="ip" behaves as cosine similarity. If you request fewer dimensions via OpenAI's dimensions parameter, set EmbeddingProfile(dimension=...) and the collection dim to that same number — they must agree.

Reopen later

The collection stores the profile, so a fresh process can reopen it — register a matching provider under the profile's model_id so Telys re-attaches the embedder on open:

Next steps

Next: keep everything on your machine with the BGE recipe.

Last updated

Was this helpful?