Embeddings API
An embedding is a vector representation of a piece of data. Text embeddings are often used to capture the semantic meaning of a piece of text, where the distance between text embedding vectors is used to measure their relatedness.
Create Embeddings
Endpoint to create an embedding vector representation of a text input.
POST https://api.relax.ai/v1/embeddings
Example Request
curl https://api.relax.ai/v1/embeddings \ -H "Authorization: Bearer $RELAX_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "input": "The capital city of the UK is London", "model": "Mistral-7b-embedding", "encoding_format": "float" }'
import openai
client = OpenAI( api_key = RELAX_API_KEY, base_url = 'https://api.relax.ai/v1/',)
response = client.embeddings.create( model="Mistral-7b-embedding", input="The capital city of the UK is London", encoding_format="float")
print(response)
import OpenAI from "openai";
const openai = new OpenAI({ apiKey: RELAX_API_KEY, baseURL: 'https://api.relax.ai/v1/' });
async function main() { const embedding = await openai.embeddings.create({ model: "Mistral-7b-embedding", input: "The capital city of the UK is London", encoding_format: "float", });
console.log(embedding);}
main();
Response
Returns an embedding object, which contains the embedding vector of the text input.
Embedding Response
{ "object": "list", "data": [ { "object": "embedding", "embedding": [ -0.002363205, 0.005371202, ... ], "index": 0 } ], "model": "Mistral-7b-embedding", "usage": { "prompt_tokens": 10, "completion_tokens": 0, "total_tokens": 10, "prompt_tokens_details": null, "completion_tokens_details": null }}
Request Body
The following parameters can be included in the request body:
Create Embeddings Request Body
model
- Type: string
- Required: Yes
- Description: The model name to use for generating the completion.
input
- Type: string or array
- Required: Yes
- Description: Input text to embed. To embed multiple inputs in a single request, pass an array of strings or array of token arrays.
The input must not exceed the max token length of the model (4096 tokens for the
Mistral-7b-embedding
model) and cannot be an empty string.
encoding_format
- Type: string
- Required: No
- Description: Embeddings vector format. Either
float
orbase64
.