Text Embeddings
POST /v1/embeddings
Converts text into high-dimensional vectors for semantic search, RAG (retrieval-augmented generation), clustering, recommendation, and similar use cases.
input accepts a single string or an array of strings (batch processing).
Request parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
model | string | ✅ | Embedding model ID, e.g. text-embedding-3-small |
input | string / array | ✅ | Text to embed; supports an array of strings for batching |
dimensions | integer | — | Output vector dimensions (dimensionality reduction); supported by some models |
encoding_format | string | — | Output format: float (default) or base64 |
Request example
bash
curl https://api.idreame.ai/v1/embeddings \
-H "Content-Type: application/json" \
-H "Authorization: Bearer sk-xxxxxxxx" \
-d '{
"model": "text-embedding-3-small",
"input": ["Hello, world", "你好,世界"]
}'1
2
3
4
5
6
7
2
3
4
5
6
7
python
from openai import OpenAI
client = OpenAI(
base_url="https://api.idreame.ai/v1",
api_key="sk-xxxxxxxx",
)
response = client.embeddings.create(
model="text-embedding-3-small",
input=["Hello, world", "你好,世界"],
)
for item in response.data:
print(f"index {item.index}: dim {len(item.embedding)}")1
2
3
4
5
6
7
8
9
10
11
12
13
14
2
3
4
5
6
7
8
9
10
11
12
13
14
Response example
json
{
"object": "list",
"data": [
{
"object": "embedding",
"index": 0,
"embedding": [0.0023, -0.0091, 0.0142, ...]
},
{
"object": "embedding",
"index": 1,
"embedding": [0.0154, 0.0037, -0.0089, ...]
}
],
"model": "text-embedding-3-small",
"usage": {
"prompt_tokens": 8,
"total_tokens": 8
}
}1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
Common use: semantic similarity
python
import numpy as np
from openai import OpenAI
client = OpenAI(
base_url="https://api.idreame.ai/v1",
api_key="sk-xxxxxxxx",
)
def cosine_similarity(a, b):
return np.dot(a, b) / (np.linalg.norm(a) * np.linalg.norm(b))
texts = ["Apples are a fruit", "Bananas are yellow", "Cats are pets"]
query = "What fruits are there?"
# Fetch all vectors in one batch
all_texts = [query] + texts
response = client.embeddings.create(
model="text-embedding-3-small",
input=all_texts,
)
embeddings = [item.embedding for item in response.data]
query_vec = embeddings[0]
doc_vecs = embeddings[1:]
# Compute similarity and sort
scores = [(texts[i], cosine_similarity(query_vec, doc_vecs[i])) for i in range(len(texts))]
scores.sort(key=lambda x: x[1], reverse=True)
for text, score in scores:
print(f"{score:.4f} {text}")1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
Recommended models
| Model | Dimensions | Use case |
|---|---|---|
text-embedding-3-small | 1536 | General semantic search, cost-effective |
text-embedding-3-large | 3072 | High-precision semantic understanding |
text-embedding-ada-002 | 1536 | Compatibility with older projects |