Skip to content

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

from relaxai import Relaxai
client = Relaxai(api_key=RELAX_API_KEY)
response = client.embeddings.create_embedding(
model="Mistral-7b-embedding",
input="The capital city of the UK is London",
encoding_format="float"
)
print(response)
import { Relaxai } from 'relaxai';
const relaxai = new Relaxai({
apiKey: RELAX_API_KEY
});
const embeddingResponse = await client.embeddings.createEmbedding({
input: "The capital city of the UK is London",
model: "Mistral-7b-embedding",
});
console.log(embeddingResponse.data);
package main
import (
"context"
"fmt"
"github.com/relax-ai/go-sdk"
"github.com/relax-ai/go-sdk/option"
)
func main() {
client := relaxai.NewClient(
option.WithAPIKey("RELAX_API_KEY"),
)
embeddingResponse, err := client.Embeddings.NewEmbedding(context.TODO(), relaxai.EmbeddingNewEmbeddingParams{
EmbeddingRequest: relaxai.EmbeddingRequestParam{
Input: map[string]interface{}{
},
Model: "Mistral-7b-embedding",
},
})
if err != nil {
panic(err.Error())
}
fmt.Printf("%+v
", embeddingResponse.Data)
}
Terminal window
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"
}'

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 or base64.