VocalDocscontracts 1.65.0

Query a Knowledge base

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

PropertyValue
Operationquery_knowledge_base
GroupKnowledge bases
Scopeknowledge:read
Scopes of include valuesnames needs knowledge:read; text needs knowledge:read
Route classread
IdempotencyIdempotency-Key accepted: a retry with the same key replays the first answer
AuditAn audited content read knowledge.knowledge_base.query, when the request names an include value
Released in1.53.0
Phase 0 hostServed (the hosted api pins 1.65.0)

Runs hybrid retrieval over one version of the Knowledge base, the active one unless version names another or working_set, and answers the passages with their citations (1.53.0; knowledge-bases.md section 6). Semantic and keyword candidates, each restricted to the version's manifest and the filter, are fused by reciprocal rank fusion, then dropped below min_score, cut at top_k and packed within max_context_tokens. Without a content class in include the passages carry no text and the citations no names, and nothing is audited; naming text or names makes the query an audited content read. No version named and none active is 422 validation_failed with knowledge_base_no_active_version; a version that does not exist is 404 not_found, and a retired one 409 knowledge_base_version_retired. An archived Knowledge base still answers. From 1.54.0 the api runs no model, so it asks a worker of the ingest role for the query's vector through a query embedding task (KnowledgeQueryTask), holding the query sealed in that task for the wait only, and answers 503 dependency_unavailable when no vector comes within 5 seconds (a target) or the worker answers embedding_failed; elapsed_ms includes the wait.

Request

Set VOCAL_API to the base URL of your API and VOCAL_API_KEY to an API key with the knowledge:read scope (Authentication and keys). Replace each placeholder, such as agt_... or <name>, with your own value.

curl -X POST "$VOCAL_API/v1/knowledge-bases/kb_.../query" \
  -H "Authorization: Bearer $VOCAL_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{ "query": "<query>" }'

Parameters

NameInTypeRequiredDescription
knowledge_base_idpathKnowledgeBaseIdyesThe id of a Knowledge base: kb_ and the row's UUIDv7 in 26 Crockford base32 characters. Opaque and safe to log.
includequeryarray of KnowledgeContentClassnoContent classes to add, comma-separated (text, names). Naming any makes the query an audited content read; without one the passages carry ids, ranks, scores and locators only.
idempotency-keyheaderstringnoA client-chosen key, kept 24 hours per Organization, environment and route. A replay returns the stored response.

Request body

Content type application/json, required: KnowledgeQueryRequest.

FieldTypeRequiredDescription
filterKnowledgeFilterInputno
max_context_tokensintegernoStops adding passages once their tokens would exceed it.
min_scorenumbernoDrops candidates whose semantic similarity is below it.
querystringyesThe question, 1 to 2,000 characters (a target). Content: never logged. From 1.54.0 the query route holds it only sealed in the query embedding task the worker reads (KnowledgeQueryTask), for the wait of the query (5 s, a target), and deletes it when the wait ends, whatever its outcome.
rerankbooleannoRerank through the rerank stage when a Provider resolves; skipped, and the answer says reranked: false, otherwise.
top_kintegernoAt most this many passages.
versionKnowledgeVersionTargetnoThe active version when omitted.

Responses

StatusContent typeShapeError codes
200application/jsonKnowledgeQueryResult
400application/jsonErrorEnvelopeinvalid_request
401application/jsonErrorEnvelopeunauthenticated
403application/jsonErrorEnvelopeforbidden
404application/jsonErrorEnvelopenot_found
409application/jsonErrorEnvelopeknowledge_base_version_retired, idempotency_in_progress, idempotency_key_reused
422application/jsonErrorEnvelopevalidation_failed
429application/jsonErrorEnveloperate_limited
500application/jsonErrorEnvelopeinternal_error
503application/jsonErrorEnvelopedependency_unavailable

Fields of the 200 answer

The shape is KnowledgeQueryResult.

FieldTypeRequiredDescription
elapsed_msintegeryesThe time the api took to answer, a measurement.
knowledge_base_idKnowledgeBaseIdyes
object"knowledge_query_result"yes
passagesarray of KnowledgePassageyesBest first: at most top_k, none below min_score, and no more than fit max_context_tokens. An empty list is an answer, not a failure.
rerankedbooleanyesFalse when the fused order was kept, as when no rerank Provider resolves.
top_scorenumber or nullyesThe highest score of the passages; null when there is none.
versioninteger or nullyesThe version searched; null for the working set.