Text Embeddings
Convert text into numerical vector representations for semantic search, clustering, and recommendations.
Create embeddings
POST https://ciyuanx.io/v1/embeddings
bash
curl https://ciyuanx.io/v1/embeddings \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{
"model": "text-embedding-3-small",
"input": "Your text here"
}'python
from openai import OpenAI
client = OpenAI(
api_key="YOUR_API_KEY",
base_url="https://ciyuanx.io/v1",
)
response = client.embeddings.create(
model="text-embedding-3-small",
input="Your text here",
)
embedding = response.data[0].embedding
print(f"Embedding dimension: {len(embedding)}")typescript
import OpenAI from "openai";
const client = new OpenAI({
apiKey: "YOUR_API_KEY",
baseURL: "https://ciyuanx.io/v1",
});
const response = await client.embeddings.create({
model: "text-embedding-3-small",
input: "Your text here",
});
console.log(`Embedding dimension: ${response.data[0].embedding.length}`);Request parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
model | string | Yes | The embedding model ID to use |
input | string or array | Yes | The text to embed, as a single string or an array of strings |
dimensions | integer | No | Number of dimensions for the output embedding (only text-embedding-3 and newer models) |
encoding_format | string | No | Return format, float (default) or base64 |
Response
The response returns the embedding vector inside the data array:
json
{
"object": "list",
"data": [
{
"object": "embedding",
"index": 0,
"embedding": [0.0023, -0.0091, 0.0145, "..."]
}
],
"model": "text-embedding-3-small",
"usage": {
"prompt_tokens": 5,
"total_tokens": 5
}
}Best practices
Use embeddings efficiently
- Pass an array of strings to
inputto embed in bulk and reduce the number of requests - Cache embeddings for frequently used text to avoid recomputation
- Use cosine similarity to compare vectors when measuring relatedness
Tip
Use embeddings for semantic search, document similarity, and recommendation systems.