子チャンクを作成
親チャンクの下に子チャンクを作成します。親子(
hierarchical_model)チャンキングモードを使用するドキュメント向けです。1 min read
post/datasets/{dataset_id}/documents/{document_id}/segments/{segment_id}/child_chunks
Request example
curl --request POST \
--url https://api.dify.ai/v1/datasets/{dataset_id}/documents/{document_id}/segments/{segment_id}/child_chunks \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '{
"content": "<string>"
}'import requests
url = "https://api.dify.ai/v1/datasets/{dataset_id}/documents/{document_id}/segments/{segment_id}/child_chunks"
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json",
}
payload = {
"content": "<string>"
}
response = requests.request("POST", url, headers=headers, json=payload)
print(response.text)const response = await fetch('https://api.dify.ai/v1/datasets/{dataset_id}/documents/{document_id}/segments/{segment_id}/child_chunks', {
method: 'POST',
headers: {
'Authorization': 'Bearer <token>',
'Content-Type': 'application/json'
},
body: JSON.stringify({
"content": "<string>"
})
});
const data = await response.json();
console.log(data);<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => 'https://api.dify.ai/v1/datasets/{dataset_id}/documents/{document_id}/segments/{segment_id}/child_chunks',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => '{
"content": "<string>"
}',
CURLOPT_HTTPHEADER => [
'Authorization: Bearer <token>',
'Content-Type: application/json',
],
]);
$response = curl_exec($curl);
curl_close($curl);
echo $response;package main
import (
"fmt"
"io"
"net/http"
"strings"
)
func main() {
url := "https://api.dify.ai/v1/datasets/{dataset_id}/documents/{document_id}/segments/{segment_id}/child_chunks"
payload := strings.NewReader("{\n \"content\": \"<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))
}HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://api.dify.ai/v1/datasets/{dataset_id}/documents/{document_id}/segments/{segment_id}/child_chunks"))
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.method("POST", HttpRequest.BodyPublishers.ofString("{\n \"content\": \"<string>\"\n}"))
.build();
HttpResponse<String> response = HttpClient.newHttpClient()
.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());require 'uri'
require 'net/http'
url = URI('https://api.dify.ai/v1/datasets/{dataset_id}/documents/{document_id}/segments/{segment_id}/child_chunks')
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = url.scheme == 'https'
request = Net::HTTP::Post.new(url)
request['Authorization'] = 'Bearer <token>'
request['Content-Type'] = 'application/json'
request.body = '{
"content": "<string>"
}'
response = http.request(request)
puts response.read_bodyResponse
{
"data": {
"content": "Dify is an open-source platform.",
"created_at": 1741267200,
"id": "d7e8f9a0-1b2c-3d4e-5f6a-7b8c9d0e1f2a",
"position": 1,
"segment_id": "f3d1c7be-9f3a-40d8-8eb8-3a1ef9c3f2c1",
"type": "customized",
"updated_at": 1741267200,
"word_count": 6
}
}{
"code": "invalid_param",
"message": "Vector store operation failed: [Errno 111] Connection refused",
"status": 400
}{
"code": "provider_not_initialize",
"message": "No Embedding Model available. Please configure a valid provider in the Settings -> Model Provider.",
"status": 400
}{
"code": "forbidden",
"message": "Dataset api access is not enabled.",
"status": 403
}{
"code": "forbidden",
"message": "The capacity of the vector space has reached the limit of your subscription.",
"status": 403
}{
"code": "forbidden",
"message": "Sorry, you have reached the knowledge base request rate limit of your subscription.",
"status": 403
}{
"code": "forbidden",
"message": "To unlock this feature and elevate your Dify experience, please upgrade to a paid plan.",
"status": 403
}{
"code": "forbidden",
"message": "The API key is not authorized to access this knowledge base.",
"status": 403
}{
"code": "not_found",
"message": "Dataset not found.",
"status": 404
}{
"code": "not_found",
"message": "Document not found.",
"status": 404
}{
"code": "not_found",
"message": "Segment not found.",
"status": 404
}{
"code": "service_unavailable",
"message": "Unable to verify vector space usage right now. Please try again later.",
"status": 503
}post/datasets/{dataset_id}/documents/{document_id}/segments/{segment_id}/child_chunks
Authorization
すべてのリクエストは API キーで認証します:Authorization: Bearer {API_KEY}。アプリのエンドポイントにはアプリの API キーを、ナレッジのエンドポイントにはナレッジベースの API キーを使用します(Dify API クイックスタート)。
キーはサーバーサイドで保管し、クライアントコードには決して埋め込まないでください。キーが欠落または無効なリクエストは HTTP 401(unauthorized)で失敗します。
Path parameters
ナレッジベース ID。ナレッジベースリストを取得 で取得します。スコープを限定したキーでは、Dify の URL から ID をコピー してください。
ドキュメント ID です。ナレッジベースのドキュメントリストを取得 から取得します。
Body
application/json子チャンクのテキスト内容です。
Responses
application/json
子チャンクが正常に作成されました。
Show child attributesHide child attributes
子チャンクのテキスト内容です。
作成タイムスタンプ(Unix エポック、秒単位)です。
子チャンクの一意識別子です。
親チャンク内の子チャンクの位置です。
この子チャンクが属する親チャンクの ID です。
子チャンクの作成方法です。API から作成または更新された子チャンクは常に
customized です。システム生成の子チャンクは automatic です。最終更新タイムスタンプ(Unix エポック、秒単位)です。
子チャンク内容の単語数です。