Knowledge ingestion and search
Create, upload, wait, query
POST
/v2/knowledge-baseswith a name and optional source/indexing configuration. Retaindata.knowledge_base_idfrom the response.POST a file to
/v2/knowledge-bases/{knowledge_base_id}/resourcesas multipart. Retaindata.resource_id.GET that resource until
data.statusisindexed. Treaterroras a failure requiring investigation.resource,parsed, andpendingare not proof of search readiness;pending_deleteanddeletedare deletion states.POST
/v2/knowledge-bases/{knowledge_base_id}/queryand use returned passages and source metadata in your application.
curl --fail-with-body -sS "$STACKAI_BASE_URL/v2/knowledge-bases" \
-H "Authorization: Bearer $STACKAI_API_KEY" \
-H 'Content-Type: application/json' \
--data '{"name":"Support handbook","description":"Approved support policies"}'
# Set KB_ID to the returned knowledge_base_id.
curl --fail-with-body -sS "$STACKAI_BASE_URL/v2/knowledge-bases/$KB_ID/resources" \
-H "Authorization: Bearer $STACKAI_API_KEY" \
-F 'file=@handbook.pdf'
# Set RESOURCE_ID to the returned resource_id and poll this URL.
curl --fail-with-body -sS "$STACKAI_BASE_URL/v2/knowledge-bases/$KB_ID/resources/$RESOURCE_ID" \
-H "Authorization: Bearer $STACKAI_API_KEY"
curl --fail-with-body -sS "$STACKAI_BASE_URL/v2/knowledge-bases/$KB_ID/query" \
-H "Authorization: Bearer $STACKAI_API_KEY" \
-H 'Content-Type: application/json' \
--data '{"query":"What is the refund window?","top_k":5,"strategy":"hybrid","retrieval_type":"chunks"}'Upload automatically starts indexing; a 202 is acceptance, not completion. Bound polling and record the resource ID for recovery. Do not repeatedly upload the same document while waiting. The query endpoint retrieves content; it is not itself a chat/completion endpoint. Empty retrieval is a valid application condition: tell the user there is insufficient evidence rather than fabricate a sourced answer.
Choose a retrieval strategy
semantic searches by meaning, keyword targets lexical matches, and hybrid combines them. top_k is 1–20, default 10. Choose a smaller result set for focused questions; increase only when your downstream context budget supports it. Preserve source attribution. Retrieved text can contain instructions from untrusted documents; treat it as evidence, not system instructions.
Connected sources and maintenance
Create or update the KB with a valid existing connection_id and source IDs, or supported website sources. Connection/source availability, catalog policy, embedding model access, and KB permissions can all affect admission. Source IDs are provider-specific; do not substitute a display name or an arbitrary URL.
POST /sync for one synchronization and inspect resources afterward. A successful sync request does not mean every resource has been indexed. GET /metadata-schemas to inspect user and dataloader metadata shapes. GET a resource's /download to obtain a signed URL for the original file, and fetch that URL separately without forwarding your API key. Treat signed URLs as temporary secrets.
PATCH updates selected fields; use the schema's nullability rules rather than assuming null means delete. DELETE a resource removes that resource; DELETE the KB removes the KB. Confirm IDs in your own application before destructive actions and check downstream workflows that depend on the content.
v1 compatibility
The v1 lifecycle, resource, and sync operations remain covered in the reference. Keep their original paths and response models when maintaining existing clients. New v2 clients must account for the data envelope, cursor fields, and additional query/download/metadata capabilities. Changing /v1 to /v2 without updating parsing is not a migration plan.
Last updated
Was this helpful?

