コンテンツにスキップ

レスポンスシェーピング

Show:

レスポンスシェーピングを使用すると、バケット検索エンドポイントが返す内容と各結果のフォーマットを制御できます。フィールドを削減してペイロードを小さくしたり、フォーマットされた引用を挿入したり、取得したチャンクのグラフ隣接を引き込んだりするのに役立ちます。

Note: contextcitationsstatusoperational_statusを含む完全に組み立てられた回答コンテキストには、Query & Search エンドポイントを使用してください。バケット検索エンドポイントは生のランク付けされたチャンクを返し、下流の組み立てを所有している場合に適しています。

VersionStatusNotes
v2CurrentPOST /v2/buckets/\{bucket_id\}/search. Use for all new integrations.
v1DeprecatedPOST /v1/buckets/\{bucket_id\}/search is kept for existing clients and returns Deprecation, Warning, and Link headers pointing to the v2 successor.

バケットを検索し、返されるチャンクを整形します。

NameTypeDescription
bucket_idstring検索するバケットのUUIDまたはスラッグ。
HeaderValue
AuthorizationBearer $SCHIFT_API_KEY
Content-Typeapplication/json
FieldTypeRequiredDefaultDescription
querystringYes自然言語クエリ。最大8,192文字。
top_kintegerNo10返す結果の最大数(11000)。
modestringNo"hybrid""vector"または"hybrid"
rerankbooleanNofalse候補を再ランク付けするかどうか。
min_scorenumberNonull最小スコア閾値(0.01.0)。
include_fieldsarray of stringNonull結果フィールドのホワイトリスト、例:["id", "score", "metadata.title"]。レガシーの生結果制御。
exclude_fieldsarray of stringNonull結果フィールドのブラックリスト、例:["text", "metadata.source_url"]。レガシーの生結果制御。
citation_formatstringNonull結果ごとのcitationのテンプレート、例:"[\{title\}:p.\{page\}]"。レガシーの生結果制御。
expand_neighborsobjectNonull各ヒットのグラフ隣接を取得します。neighbor expansionを参照。
expand_contextobjectNonull再ランク付け前に同一ドキュメントの隣接チャンクを追加します。
debugbooleanNofalse詳細なデバッグタイミングとチャンクごとのスコアを含めます。
FieldTypeDescription
bucket_idstring検索されたバケット。
querystring実行されたクエリ。
search_idstring | nullサーバー生成の検索識別子。
resultsarray関連性順に並べられた一致するチャンク。
results[].idstringチャンク識別子。
results[].scorenumber最終的な関連性スコア。
results[].textstringチャンクテキスト。
results[].metadataobjectbucket_idcollection_idを含むチャンクメタデータ。
results[].citationstring | nullcitation_formatが設定されている場合のフォーマットされた引用。
results[].neighborsarray | nullexpand_neighborsが設定されている場合のグラフ隣接。
degradedboolean応答が劣化モードで生成されたかどうか。
warningsarray検索警告がある場合。
debugobject | nulldebug: trueの場合のデバッグ情報。

include_fieldsexclude_fieldsは、各結果に表示されるキーを制御します。どちらもmetadata.titleのようなドットパスをサポートします。

  • include_fieldsはキーをホワイトリスト化します。設定されている場合、リストされたトップレベルキーと要求されたメタデータサブキーのみが返されます。
  • exclude_fieldsはキーをブラックリスト化します。設定されている場合、リストされたトップレベルキーとメタデータサブキーが削除されます。
  • 両方が設定されている場合、include_fieldsが優先されます。

Note: idscoretextは常にデフォルトで埋め込まれ、プロジェクションがそれらを削除しても結果が有効であるようにします。

citation_formatが提供されると、各結果に\{key\}トークンを置換して構築されたcitation文字列が付きます。トークンはまず結果から解決され、その後metadataから解決されます。不明なトークンは空文字列としてレンダリングされます。

例えば、メタデータが{"title": "Terms", "page": 3}でフォーマットが"[\{title\}:p.\{page\}]"の場合、引用は"[Terms:p.3]"になります。

expand_neighborsは、各ヒットに接続されたグラフエッジを取得します。

FieldTypeRequiredDefaultDescription
relationsarray of stringNonullこれらの関係タイプにフィルタリングします。nullはすべてを意味します。
directionstringNo"both""outgoing""incoming"、または"both"
max_per_hitintegerNo10ヒットごとに返される最大エッジ数(1100)。

返される各隣接には以下があります:

FieldTypeDescription
idstring隣接ノードID。
relationstring関係タイプ、例:followshas_child
directionstring"outgoing"または"incoming"
weightnumberエッジの重み。
Terminal window
curl -X POST ${API_BASE_URL:-https://api.schift.io}/v2/buckets/product-docs/search \
-H "Authorization: Bearer $SCHIFT_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"query": "annual leave policy",
"top_k": 5,
"min_score": 0.7,
"citation_format": "[{title}:p.{page}]",
"expand_neighbors": {
"relations": ["references", "has_child"],
"direction": "both",
"max_per_hit": 3
},
"debug": true
}'
{
"bucket_id": "product-docs",
"query": "annual leave policy",
"search_id": "search_0a1b2c3d4e5f",
"results": [
{
"id": "chunk_01j8x9q2mvn9q",
"score": 0.91,
"text": "Full-time employees receive 20 days of paid annual leave per year.",
"metadata": {
"bucket_id": "product-docs",
"collection_id": "col_123",
"title": "Employee Handbook",
"page": 12,
"doc_type": "policy"
},
"citation": "[Employee Handbook:p.12]",
"neighbors": [
{
"id": "chunk_01j8x9q2mvna0",
"relation": "references",
"direction": "outgoing",
"weight": 1.0
}
]
}
],
"degraded": false,
"warnings": [],
"debug": {
"query_embedding_model": "schift-embed-v1",
"search_method": "hybrid",
"timing_ms": {
"embedding": 23,
"vector_search": 18,
"bm25": 9,
"hydration": 4,
"total": 62
},
"results_detail": [
{
"chunk_id": "chunk_01j8x9q2mvn9q",
"vector_score": 0.88,
"bm25_score": 0.72,
"rrf_score": 0.85,
"final_score": 0.91,
"source": "hybrid"
}
]
}
}
// 400 Bad Request — missing query
{
"detail": "query or query_vector is required"
}
// 400 Bad Request — invalid filter
{
"detail": "Invalid filter: unsupported operator"
}
// 402 Payment Required — search quota exhausted
{
"allowed": false,
"reason": "quota_exceeded"
}
// 403 Forbidden — search quota unavailable
{
"detail": "Search quota unavailable. Upgrade your plan."
}
// 404 Not Found
{
"detail": "Bucket not found"
}
// 500 Internal Server Error
{
"detail": "Bucket search failed"
}

POST /v1/buckets/\{bucket_id\}/searchは廃止予定です。同じペイロード形式を返しますが、以下のレスポンスヘッダーを追加します:

HeaderValue
Deprecationtrue
Warning299 - "Deprecated search endpoint; migrate to /v2/buckets/\{bucket_id\}/search"
Link</v2/buckets/\{bucket_id\}/search>; rel="successor-version"