Add a query to the retrieval-quality corpus
POST /v1/knowledge-bases/{knowledge_base_id}/eval-queries
| Property | Value |
|---|---|
| Operation | create_knowledge_eval_query |
| Group | Knowledge bases |
| Scope | knowledge:write |
| Route class | control |
| Idempotency | Idempotency-Key accepted: a retry with the same key replays the first answer |
| Audit | Audited knowledge.eval_query.create (mutation) |
| Released in | 1.53.0 |
| Phase 0 host | Served (the hosted api pins 1.65.0) |
Adds a labelled question with the Documents that answer it, or expect_empty, at revision 1 (1.53.0). Every issue is a detail of 422 validation_failed (KnowledgeEvalQueryIssueCode). The answer carries query null, as every write does.
Request
Set VOCAL_API to the base URL of your API and VOCAL_API_KEY to an API key with the knowledge:write 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_.../eval-queries" \
-H "Authorization: Bearer $VOCAL_API_KEY" \
-H "Idempotency-Key: $(uuidgen)" \
-H "Content-Type: application/json" \
-d '{ "query": "<query>" }'const response = await fetch(`${process.env.VOCAL_API}/v1/knowledge-bases/kb_.../eval-queries`, {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.VOCAL_API_KEY}`,
'Idempotency-Key': crypto.randomUUID(),
'Content-Type': 'application/json',
},
body: JSON.stringify({
"query": "<query>"
}),
});
console.log(response.status, await response.text());import os
import uuid
import requests
response = requests.post(
f"{os.environ['VOCAL_API']}/v1/knowledge-bases/kb_.../eval-queries",
headers={
"Authorization": f"Bearer {os.environ['VOCAL_API_KEY']}",
"Idempotency-Key": str(uuid.uuid4()),
},
json={
"query": "<query>",
},
)
print(response.status_code, response.text)Parameters
| Name | In | Type | Required | Description |
|---|---|---|---|---|
knowledge_base_id | path | KnowledgeBaseId | yes | The id of a Knowledge base: kb_ and the row's UUIDv7 in 26 Crockford base32 characters. Opaque and safe to log. |
idempotency-key | header | string | no | A client-chosen key, kept 24 hours per Organization, environment and route. A replay returns the stored response. |
Request body
Content type application/json, required: KnowledgeEvalQueryCreateRequest.
| Field | Type | Required | Description |
|---|---|---|---|
expect_empty | boolean | no | False when omitted. |
filter | KnowledgeFilterInput | no | |
query | string | yes | |
relevant_documents | array of KnowledgeDocumentId | no | None when omitted. |
tags | array of KnowledgeEvalQueryTag | no | snake_case labels that group the queries, such as lab_visits. |
Responses
| Status | Content type | Shape | Error codes |
|---|---|---|---|
201 | application/json | KnowledgeEvalQuery | |
400 | application/json | ErrorEnvelope | invalid_request |
401 | application/json | ErrorEnvelope | unauthenticated |
403 | application/json | ErrorEnvelope | forbidden, org_suspended |
404 | application/json | ErrorEnvelope | not_found |
409 | application/json | ErrorEnvelope | knowledge_base_archived, idempotency_in_progress, idempotency_key_reused |
422 | application/json | ErrorEnvelope | validation_failed |
429 | application/json | ErrorEnvelope | rate_limited |
500 | application/json | ErrorEnvelope | internal_error |
Fields of the 201 answer
The shape is KnowledgeEvalQuery.
| Field | Type | Required | Description |
|---|---|---|---|
created_at | Timestamp | yes | |
expect_empty | boolean | yes | True when no passage should score at or above min_score for the query. |
filter | KnowledgeFilter or null | yes | The filter the query is run under, as a binding would fix it; null for none. |
id | KnowledgeEvalQueryId | yes | |
knowledge_base_id | KnowledgeBaseId | yes | |
object | "knowledge_eval_query" | yes | |
query | string or null | yes | The question as a caller would ask it: the content class text, null unless the read names include=text, and null in the answer of a write. |
relevant_documents | array of KnowledgeDocumentId | yes | The Documents that answer the query; empty when expect_empty. |
revision | integer | yes | Counts writes; returned as the ETag and required in If-Match. |
tags | array of KnowledgeEvalQueryTag | yes | snake_case labels that group the queries, such as lab_visits. |
updated_at | Timestamp | yes |