Embeddings
Hopfield provides an easy way to get type-safe embeddings. You can use different API providers with type guarantees with Zod, and composability across providers.
API Providers
We currently only support OpenAI, but are working on adding further providers. Reach out on Discord or Github Discussions if you have any suggestions!
Usage
Check out how we type responses:
ts
importhop from "hopfield";importopenai from "hopfield/openai";importOpenAI from "openai";consthopfield =hop .client (openai ).provider (newOpenAI ());constembeddings =hopfield .embedding ();constresponse = awaithopfield .embedding ().get ({input : ["hello"] });constembedding =response .data [0].embedding ;const embedding: [number, number, number, number, number, number, number, number, number, number, number, number, number, number, number, number, number, number, number, number, number, ... 1514 more ..., number]
ts
importhop from "hopfield";importopenai from "hopfield/openai";importOpenAI from "openai";consthopfield =hop .client (openai ).provider (newOpenAI ());constembeddings =hopfield .embedding ();constresponse = awaithopfield .embedding ().get ({input : ["hello"] });constembedding =response .data [0].embedding ;const embedding: [number, number, number, number, number, number, number, number, number, number, number, number, number, number, number, number, number, number, number, number, number, ... 1514 more ..., number]
You can guarantee that your response is constructed correctly (with no optional accessors) and the embedding and outer array uses the tuple
type, based on the inputs you requested.
Composability
The big unlock is not only that types are guaranteed to be safe - we provide composability to allow building complex apps with RAG and embedding-driven search.
INFO
We are actively working on building a RAG solution - please reach out if you are interested in influencing the API for this!
Learn More
Learn more about the intricacies embeddings in the Embeddings page.