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

OpenAI & Anthropic

Pair Telys retrieval with an OpenAI or Anthropic chat model — embed with CallableEmbedder or a local Algenta embedder, retrieve, and augment the prompt.

Telys handles retrieval; a hosted chat model handles generation. Embed and index documents in Telys, retrieve the most relevant ones for a question, and pass them as context to OpenAI or Anthropic. Two independent choices:

  • Embeddings — a hosted embedder (OpenAI) wrapped in CallableEmbedder, or a local Algenta embedder that runs on-device with no API key.

  • Generation — an OpenAI or Anthropic chat model, prompted with the retrieved context.

Install with pipx install telys, sign in with telys login, then verify with telys runtime verify. Also install the provider SDK (pip install openai or pip install anthropic) and set its API key. See Install Telys.

Index with an embedder

Choose where embeddings come from. A hosted embedder gives a dense space matched to the provider; a local Algenta embedder keeps everything on your machine.

Wrap the OpenAI embeddings endpoint in CallableEmbedder. Your function takes a list of strings and returns an (n, dim) float32 array; EmbeddingProfile declares the space identity so Telys rejects a query embedded in an incompatible space.

index_openai.py
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


def embed(texts: list[str]) -> np.ndarray:
    resp = client.embeddings.create(model="text-embedding-3-small", input=texts)
    return np.array([d.embedding for d in resp.data], dtype="float32")


profile = EmbeddingProfile(
    provider="openai",
    model_id="text-embedding-3-small",
    model_version="1",
    dimension=1536,          # must match what `embed` returns
    normalization="l2",      # text-embedding-3 vectors are unit length
    distance="ip",           # inner product on unit vectors == cosine
)
embedder = CallableEmbedder(embed, profile)

col = Telys("./rag-store").create_collection(
    "docs", dim=profile.dimension, partition_by="source", embedder=embedder,
    filter_columns=("text",),   # persisted + returned by search(..., with_metadata=True)
)

No API key, no network — the multigram embedder runs entirely on-device via the native kernel. Its dimension comes from the kernel, so read it from the profile.

Ingest the same way with either embedder. Keep the source text in metadata to rebuild the prompt context later:

Retrieve and generate

Retrieval is one search_text call. Feed the hits to the chat model as context and instruct it to answer only from that context.

The Anthropic SDK returns a list of content blocks; read the text from the text block.

What you will see

Both variants retrieve the on-device / privacy document as the top hit and produce a grounded answer:

With OpenAI embeddings, document vectors are computed by OpenAI at index time; the local Algenta path computes them on-device. Either way, the chat model sees only the small retrieved context you assemble — not your whole corpus.

Next steps

Last updated

Was this helpful?