创建嵌入
curl --request POST \
--url https://api.qhaigc.net/v1/embeddings \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"model": "<string>",
"input": "<string>"
}
'import requests
url = "https://api.qhaigc.net/v1/embeddings"
payload = {
"model": "<string>",
"input": "<string>"
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({model: '<string>', input: '<string>'})
};
fetch('https://api.qhaigc.net/v1/embeddings', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.qhaigc.net/v1/embeddings",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'model' => '<string>',
'input' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.qhaigc.net/v1/embeddings"
payload := strings.NewReader("{\n \"model\": \"<string>\",\n \"input\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.qhaigc.net/v1/embeddings")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"model\": \"<string>\",\n \"input\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.qhaigc.net/v1/embeddings")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"model\": \"<string>\",\n \"input\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"object": "<string>",
"data": [
{
"embedding": [
123
],
"index": 123,
"object": "<string>"
}
],
"model": "<string>",
"usage": {}
}嵌入模型
创建嵌入
将文本转换为高维向量表示,用于搜索和聚类
POST
/
v1
/
embeddings
创建嵌入
curl --request POST \
--url https://api.qhaigc.net/v1/embeddings \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"model": "<string>",
"input": "<string>"
}
'import requests
url = "https://api.qhaigc.net/v1/embeddings"
payload = {
"model": "<string>",
"input": "<string>"
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({model: '<string>', input: '<string>'})
};
fetch('https://api.qhaigc.net/v1/embeddings', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.qhaigc.net/v1/embeddings",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'model' => '<string>',
'input' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.qhaigc.net/v1/embeddings"
payload := strings.NewReader("{\n \"model\": \"<string>\",\n \"input\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.qhaigc.net/v1/embeddings")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"model\": \"<string>\",\n \"input\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.qhaigc.net/v1/embeddings")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"model\": \"<string>\",\n \"input\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"object": "<string>",
"data": [
{
"embedding": [
123
],
"index": 123,
"object": "<string>"
}
],
"model": "<string>",
"usage": {}
}功能说明
将输入的文本转换为向量(Embeddings),适用于语义搜索、推荐系统、分类和聚类等场景。请求参数
| 名称 | 类型 | 必选 | 说明 |
|---|---|---|---|
model | string | 是 | 模型名称,如 bge-m3 或 text-embedding-3-large |
input | string | 是 | 要转换为向量的文本内容 |
调用示例
import openai
client = openai.OpenAI(
api_key="sk-your-api-key-here",
base_url="https://api.qhaigc.net/v1"
)
response = client.embeddings.create(
model="bge-m3",
input="启航 AI API 系统是一款聚焦低成本探索 AIGC 无限可能的服务平台"
)
print(response.data[0].embedding)
import OpenAI from 'openai';
const openai = new OpenAI({
apiKey: 'sk-your-api-key-here',
baseURL: 'https://api.qhaigc.net/v1'
});
async function main() {
const embedding = await openai.embeddings.create({
model: 'bge-m3',
input: '启航 AI API 系统是一款聚焦低成本探索 AIGC 无限可能的服务平台',
});
console.log(embedding.data[0].embedding);
}
main();
curl https://api.qhaigc.net/v1/embeddings \
-H "Content-Type: application/json" \
-H "Authorization: Bearer sk-your-api-key-here" \
-d '{
"model": "bge-m3",
"input": "启航 AI API 系统是一款聚焦低成本探索 AIGC 无限可能的服务平台"
}'
返回结果
返回包含向量数据的对象。{
"object": "list",
"data": [
{
"embedding": [
-0.06332587,
-0.019955011,
-0.03361425,
// ... 共 1024 或更多维度
],
"index": 0,
"object": "embedding"
}
],
"model": "bge-m3",
"usage": {
"prompt_tokens": 21,
"total_tokens": 21
}
}
相关参考
Authorizations
Bearer authentication header of the form Bearer <token>, where <token> is your auth token.
⌘I