POST /v2/knowledge-bases/{knowledge_base_id}/query
Search a knowledge base and return the most relevant results.
How to use
Search only after the resources you need are indexed. Choose semantic, keyword, or hybrid; top_k is 1–20. This returns retrieval results, not a generated answer. Handle empty results and preserve source attribution.
Authentication and permissions
Required permissions: kbs.query. Resource and owner access checks also apply.
Prepare request.json
Save the example body below as request.json for the curl sample. Replace example IDs, node keys, and dynamic configuration with values for your organization; these are illustrative, not pre-existing resources.
{
"query": "What is the refund window?",
"top_k": 5,
"strategy": "hybrid",
"retrieval_type": "chunks"
}Personal API key (sk_...) or supported user access JWT. See Authentication and authorization for endpoint restrictions and scopes. Use exactly one Authorization header.
A query against a knowledge base on the public v2 surface.
The search query to run against the knowledge base.
Number of top results to return.
10Retrieval strategy to use for the search.
semanticPossible values: Type of retrieval to use for the search.
chunksPossible values: Successful Response
Machine-readable response code, when provided.
Validation Error
curl --fail-with-body -sS \
"$STACKAI_BASE_URL/v2/knowledge-bases/${KNOWLEDGE_BASE_ID}/query" \
-H "Authorization: Bearer $STACKAI_API_KEY" \
-H 'Content-Type: application/json' \
--data-binary @request.json{
"response_code": "text",
"meta": {
"ANY_ADDITIONAL_PROPERTY": "anything"
},
"data": [
{
"content": "text",
"score": 0,
"resource_id": "123e4567-e89b-12d3-a456-426614174000"
}
]
}Last updated
Was this helpful?

