嵌入(Embeddings)
嵌入接口用于将文本转换为向量表示。
接口地址
POST https://ai-tokenhub.com/v1/embeddings请求头
| 名称 | 类型 | 必填 | 说明 |
|---|---|---|---|
| Authorization | string | 是 | Bearer YOUR_API_KEY |
| Content-Type | string | 是 | application/json |
请求体
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
| model | string | 是 | - | 嵌入模型标识符 |
| input | string/array | 是 | - | 要嵌入的文本 |
| encoding_format | string | 否 | float | 返回格式 (float/dense) |
请求示例
bash
curl https://ai-tokenhub.com/v1/embeddings \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{
"model": "text-embedding-3-small",
"input": "The quick brown fox jumps over the lazy dog"
}'响应示例
json
{
"object": "list",
"data": [
{
"object": "embedding",
"embedding": [0.123, -0.456, 0.789, ...],
"index": 0
}
],
"model": "text-embedding-3-small",
"usage": {
"prompt_tokens": 10,
"total_tokens": 10
}
}应用场景
- 语义搜索: 文本相似度计算
- 文档聚类: 文档分类和分组
- 推荐系统: 基于内容的推荐
- 知识图谱: 实体关系表示