Vector Embeddings
Chuyển văn bản thành các vector phục vụ tìm kiếm ngữ nghĩa, RAG, phân cụm và gợi ý.
RequestREQUEST
POST
https://test.kailin.com.cn/v1/embeddingsResponseRESPONSE
Fill in the request and hit Send — the response shows up here
Yêu cầu
curl https://test.kailin.com.cn/v1/embeddings \
-H "Content-Type: application/json" \
-H "Authorization: Bearer sk-your-token" \
-d '{
"model": "text-embedding-3-small",
"input": "AI Station is a unified model gateway"
}'
Thân yêu cầu
| Tham số | Kiểu | Bắt buộc | Mô tả |
|---|---|---|---|
model | string | Có | Mô hình embedding, ví dụ text-embedding-3-small, text-embedding-3-large, text-embedding-ada-002 |
input | string / array | Có | Một chuỗi hoặc mảng các chuỗi (theo lô) — giới hạn mỗi yêu cầu phụ thuộc vào mô hình |
dimensions | integer | Không | Số chiều của vector đầu ra (chuỗi text-embedding-3 hỗ trợ giảm số chiều) |
encoding_format | string | Không | float (mặc định) hoặc base64 |
user | string | Không | Định danh người dùng cuối |
Phản hồi
{
"object": "list",
"data": [
{
"object": "embedding",
"index": 0,
"embedding": [0.0023, -0.0091, 0.0154, "..."]
}
],
"model": "text-embedding-3-small",
"usage": {
"prompt_tokens": 12,
"total_tokens": 12
}
}
| Trường | Mô tả |
|---|---|
data[].embedding | Mảng vector — mặc định 1536 chiều (text-embedding-3-small) / 3072 (-large) |
data[].index | Chỉ số của chuỗi đầu vào tương ứng |
usage.prompt_tokens | Số token được tính phí |
Yêu cầu theo lô (Batch)
{
"model": "text-embedding-3-small",
"input": ["first document", "second document", "third document"]
}
data trả về mang index khớp với thứ tự đầu vào. Một lượt gọi gộp nhanh hơn và ít tốn số lượt yêu cầu hơn so với gọi từng mục riêng lẻ.
Sử dụng SDK
from openai import OpenAI
client = OpenAI(
api_key="sk-your-token",
base_url="https://test.kailin.com.cn/v1",
)
resp = client.embeddings.create(
model="text-embedding-3-small",
input=["Document A", "Document B"],
)
vectors = [item.embedding for item in resp.data]
Ghi chú
Các endpoint embedding bản địa của Gemini (/v1beta/models/{model}:embedContent v.v.) cũng được proxy — tham số tuân theo định dạng chính thức của Gemini, xem tài liệu của Google.