Skip to Content
DocsRecipesCustom embedder

Custom embedder

Any class with name, dimensions, embed(text), and embed_batch(texts) satisfies the Embedder protocol. No inheritance required.

from typing import Any from loomflow.memory.vector import VectorMemory class CohereEmbedder: name: str = "embed-english-v3.0" dimensions: int = 1024 def __init__(self, api_key: str) -> None: import cohere self._client = cohere.AsyncClient(api_key) async def embed(self, text: str) -> list[float]: result = await self._client.embed( texts=[text], model=self.name, input_type="search_document", ) return list(result.embeddings[0]) async def embed_batch(self, texts: list[str]) -> list[list[float]]: result = await self._client.embed( texts=texts, model=self.name, input_type="search_document", ) return [list(e) for e in result.embeddings] memory = VectorMemory(embedder=CohereEmbedder(api_key="..."))

Same shape works for Voyage, sentence-transformers, or any other embedding provider. The framework only consumes the protocol surface.

Last updated on