Embedding API Usage Guide
The Turing Platform's embedding models convert text into high-dimensional vector representations for use in semantic search, clustering, recommendation, and other tasks.
Notes:
- Multiple embedding models are supported, including text-embedding-ada-002
- A single request supports up to 8,192 tokens
- The vector dimensions returned depend on the model selected
Models and Dimensions
| Model | Default Dimensions | Adjustable Dimension Range |
|---|---|---|
| turing/text-embedding-ada-002 | 1536 | Not supported |
| turing/text-embedding-3-small | 1536 | 512, 1536 |
| turing/text-embedding-3-large | 3072 | 256, 1024, 3072 |
Custom Dimensions
For models that support dimension adjustment, you can use the dimensions parameter to specify the output vector dimensions. Smaller dimensions can reduce cost and improve performance, but may affect embedding quality.
SDK
from openai import OpenAI
client = OpenAI()
response = client.embeddings.create(
model="text-embedding-ada-002",
input="The quick brown fox jumps over the lazy dog"
)
print(response.data[0].embedding)
print(f"Embedding dimension: {len(response.data[0].embedding)}")
# Batch processing multiple texts
texts = [
"Hello world",
"Python programming",
"Machine learning"
]
response = client.embeddings.create(
model="text-embedding-ada-002",
input=texts
)
for i, embedding in enumerate(response.data):
print(f"Text {i+1} embedding dimension: {len(embedding.embedding)}")
# Using custom dimensions (only applicable to text-embedding-3-small and text-embedding-3-large)
response = client.embeddings.create(
model="text-embedding-3-small",
input="Custom dimension example",
dimensions=512 # Set dimensions to 512
)
print(f"Custom embedding dimension: {len(response.data[0].embedding)}")
CURL
curl $TURING_BASE_URL/embeddings \
-H "Authorization: Bearer $TURING_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "text-embedding-ada-002",
"input": "The quick brown fox jumps over the lazy dog"
}'
Batch Processing Example
curl $TURING_BASE_URL/embeddings \
-H "Authorization: Bearer $TURING_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "text-embedding-ada-002",
"input": [
"Hello world",
"Python programming",
"Machine learning"
]
}'
Custom Dimensions Example
curl $TURING_BASE_URL/embeddings \
-H "Authorization: Bearer $TURING_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "text-embedding-3-small",
"input": "The quick brown fox jumps over the lazy dog",
"dimensions": 512
}'