To get an embedding, send your text to the embeddings API endpoint with the model name. The response will include an embedding as a list of numbers that you can save in a vector database.
fetch("https://api.monolyth.ai/v1/embeddings", {
method: "POST",
headers: {
Authorization: `Bearer ${MONOLYTH_API_KEY}`,
"HTTP-Referer": `${YOUR_SITE_URL}`, // Optional, Shows in analytics dashboard on monolyth.ai
"X-Name": `${YOUR_SITE_NAME}`, // Optional, Shows in analytics dashboard on monolyth.ai
"Content-Type": "application/json",
},
body: JSON.stringify({
model: "text-embedding-3-small",
input: "What is your dream?",
}),
});
import OpenAI from "openai"
const openai = new OpenAI({
baseURL: "https://api.monolyth.ai/v1",
apiKey: $MONOLYTH_API_KEY,
defaultHeaders: {
"HTTP-Referer": $YOUR_SITE_URL, // Optional, Shows in analytics dashboard on monolyth.ai
"X-Name": $YOUR_APP_NAME, // Optional, Shows in analytics dashboard on monolyth.ai
},
})
async function main() {
const embeddings = await openai.embeddings.create({
model: "text-embedding-3-small",
input: "What is your dream?",
encoding_format: "float",
})
console.log(embeddings)
}
main()
{
"object": "list",
"data": [
{
"object": "embedding",
"index": 0,
"embedding": [
-0.006929283495992422,
-0.005336422007530928,
...
-4.547132266452536e-05,
-0.024047505110502243
],
}
],
"model": "text-embedding-3-small",
"usage": {
"prompt_tokens": 5,
"total_tokens": 5
}
}
The default embedding vector length is 1536 for and 3072 for
. You can adjust the
parameter to reduce the size while preserving conceptual integrity. More details are available in the embedding use case section.
Parameter | Description |
---|---|
| Input text to embed, encoded as a string or array of tokens. 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 input tokens for the model (8192 tokens for text-embedding-ada-002), cannot be an empty string, and any array must be 2048 dimensions or less. |
| ID of the model to use. You can use the List models API to see all of your available models, or see our Model overview for descriptions of them. |
| The number of dimensions the resulting output embeddings should have. Only supported in and later models. |