For the complete documentation index, see llms.txt. This page is also available as Markdown.

POST /v2/knowledge-bases/{knowledge_base_id}/query

Query Knowledge Base

post

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"
}
Authorizations
AuthorizationstringRequired

Personal API key (sk_...) or supported user access JWT. See Authentication and authorization for endpoint restrictions and scopes. Use exactly one Authorization header.

Path parameters
knowledge_base_idstring · uuidRequired
Body

A query against a knowledge base on the public v2 surface.

querystring · min: 1Required

The search query to run against the knowledge base.

top_kinteger · min: 1 · max: 20Optional

Number of top results to return.

Default: 10
strategystring · enumOptional

Retrieval strategy to use for the search.

Default: semanticPossible values:
retrieval_typestring · enumOptional

Type of retrieval to use for the search.

Default: chunksPossible values:
Responses
200

Successful Response

application/json
response_codestring · nullableOptional

Machine-readable response code, when provided.

post/v2/knowledge-bases/{knowledge_base_id}/query
curl
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?