注册

Gemini 原生文本嵌入接口 - 向量嵌入生成

POST https://api.quickrouter.ai/v1beta/models/gemini-embedding-001:embedContent 在线调试 →
Authorization

在 Header 添加参数 Authorization,其值为 Bearer 之后拼接 Token

示例: Authorization: Bearer ********************

请求参数

Header 参数
Content-Type string
可选
示例: application/json
Body 参数 application/json
content object
可选
要嵌入的内容。 必需
parts array [object]
可选
output_dimensionality integer
可选
输出嵌入的可选降维。
taskType string
可选
嵌入将用于的可选任务类型。 { "content": { "parts": [ { "text": "What is the meaning of life?" } ] }, "output_dimensionality": 768, "taskType": "SEMANTIC_SIMILARITY" } 请求
示例
{
    "content": {
        "parts": [
            {
                "text": "What is the meaning of life?"
            }
        ]
    },
    "output_dimensionality": 768,
    "taskType": "SEMANTIC_SIMILARITY"
}

请求示例代码

{
  "model": "models/gemini-embedding-001",
  "content": {
    "parts": [
      {
        "text": "Hello world"
      }
    ]
  }
}
curl --location --request POST 'https://api.quickrouter.ai/v1beta/models/gemini-embedding-001:embedContent' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer YOUR_API_KEY' \
--header 'Content-Type: application/json' \
--data-raw '{
  "content": {
    "parts": [
      {
        "text": "What is the meaning of life?"
      }
    ]
  },
  "output_dimensionality": 768,
  "taskType": "SEMANTIC_SIMILARITY"
}'
"var myHeaders = new Headers();\nmyHeaders.append(\"Authorization\", \"Bearer YOUR_API_KEY\");\nmyHeaders.append(\"Content-Type\", \"application/json\");\n\nvar raw = JSON.stringify({\n   \"content\": {\n      \"parts\": [\n         {\n            \"text\": \"What is the meaning of life?\"\n         }\n      ]\n   },\n   \"output_dimensionality\": 768,\n   \"taskType\": \"SEMANTIC_SIMILARITY\"\n});\n\nvar requestOptions = {\n   method: 'POST',\n   headers: myHeaders,\n   body: raw,\n   redirect: 'follow'\n};\n\nfetch(\"https://api.quickrouter.ai/v1beta/models/gemini-embedding-001:embedContent\", requestOptions)\n   .then(response => response.text())\n   .then(result => console.log(result))\n   .catch(error => console.log('error', error));"
"import http.client\nimport json\n\nconn = http.client.HTTPSConnection(\"api.quickrouter.ai\")\npayload = json.dumps({\n   \"content\": {\n      \"parts\": [\n         {\n            \"text\": \"What is the meaning of life?\"\n         }\n      ]\n   },\n   \"output_dimensionality\": 768,\n   \"taskType\": \"SEMANTIC_SIMILARITY\"\n})\nheaders = {\n   'Authorization': 'Bearer YOUR_API_KEY',\n   'Content-Type': 'application/json'\n}\nconn.request(\"POST\", \"/v1beta/models/gemini-embedding-001:embedContent\", payload, headers)\nres = conn.getresponse()\ndata = res.read()\nprint(data.decode(\"utf-8\"))"

返回响应

响应参数 🟢 200 OK · application/json
embeddings object
可选
{ "embedding": { "values": [ -0.0296398, -0.010636787, 0.012426536, -0.043735605, -0.012861362, 0.0025766853, -0.0056927837, 0.013363464, 0.042344756, -0.00600363, 0.016946154, -0.016573662, -0.0242951, 0.040273175, 0.13305295, 0.006534976, -0.0066952384, 0.011369802, 0.014375867, -0.0056447736, 0.007932834, 0.003440911, 0.0015993431, -0.012414881, -0.014631236, -0.0057829414, 0.019290049, 0.0005005244, 0.014184347, -0.0065879934, -0.003565929, 0.019397464, 0.005518749, 0.030157084, -0.009677098, -0.0029866593, 0.017299578, 0.006338976, -9.322887e-05, 0.021375261, -0.024926692, -0.0003635663, 0.004625881, 0.0027941137, 0.032529075, -0.0025162857, 0.006721118, -0.027300382, -0.0030568605, 0.020879114, -0.01518175, 0.024195358, -0.0022586272, -0.16242279, -0.0031008113, 0.011878735, -0.0065687853, -0.0078121293, -0.0031238683, -0.0036403642, -0.02131096, -0.0039914316, -0.018723665, -0.045217782, 0.006739287, -0.010009519, 0.0018316646, -0.0018083674, -0.012085223, -0.0014903563, -0.015677448, 0.00876675, -0.011975094, 0.005202495, -0.0013395232, -0.02117135, 0.02085695, 0.009407144, 0.023169326, -0.0061100135, 0.011164493, -0.0015549492, -0.027464285, -0.0123647, -9.947967e-05, -0.010167568, -0.015949652, 0.0012945095, 0.004713989, -0.009797795, -0.006914863, 0.01999175, 0.009941107, 0.022365669, -0.011112252, 0.0018841166, -0.0140149705, -0.009466361, -0.0051897927, 0.0017415871, -0.023722459, -0.013767081, 0.0009987081, 0.0025969457, 0.011067786, -0.0008395377, 0.02449344, 0.0065714344, -0.008802859, 0.01478423, -0.009419866, 0.0024454435, -0.014272332, 0.002841706, 0.0014935558, -0.1668367, 0.0071803983, 0.0002759486, -0.0005119746, 0.0138186235, 0.00035195384, 0.0021816439, 0.013897939, 0.022451976, -0.0046094316, -0.016414018, 0.029705513, 0.0013502334, -0.029205326, -0.00223862, 0.008688559, -0.0017488803, -0.0017071241, 0.02811523, 0.0003582492, 0.013387385, 0.0020523916, -0.008380343, -0.008700947, 0.01313421, 0.024904193, 0.0033890235, -0.0067567667, 0.006474785, -0.009726371, -0.013789963, -0.024971183, 0.027432237, 0.021531988, 0.00085505226, -0.007530849, 0.017413057, -0.019567914, -0.0029013238, 0.02718425, -0.048679482, -0.025425717, -0.003643478, 0.046605345, 0.015131438, 0.017564094, -0.024245195, 0.009929572, 0.010758676, 0.027922388, -0.0046666698, 0.012225224, -0.0040972205, 0.009128703, 0.0119820675, -0.0018588518, -0.000116790565, 0.008043984, 0.028858813, -0.015383414, 0.0047377315, -0.014935567, -0.0070394077, 0.026544005, 0.008124204, 0.011230377, -0.011875552, -0.018568655, -0.014651568, -0.010986834, -0.0070081796, -0.030712977, -0.016584154, 0.043207396, -0.010555375, 0.010056673, -0.004625643, -0.00096580194, -0.005962162, -0.0044048144, 0.013608296, -0.0038451874, 0.02661319, -0.009673978, 0.0073342496, -0.024697386, 0.024071904, 0.007120086, -0.004817186, 0.021704704, 0.014507516, 0.019033715, -0.021459393, 0.0009360375, 0.0034508815, 0.008515678, 0.013316997, 0.02246404, -0.0017898967, 0.015261492, -0.009148077, -0.016117442, 0.01113729, -0.0074887434, -0.0021146906, 0.0347106, -0.015456998, -0.01071589, 0.023878252, -0.0054925852, 0.0022822723, -0.008937607, -0.008547459, 0.0027762372, 0.02171912, -0.0024024074, 0.036017273, -0.0020466154, 0.004725955, 0.0016764981, 0.00070662843, 0.009837389, 0.0019250698, 0.010220786, -0.006446121, -0.0055151423, -0.02765927, 0.025683768, 0.02911067, -0.011834867, -0.0018890229, -0.0028985268, 0.020689119, -0.032568946, -0.01900007, 0.012674699, 0.02096