Skip to main content

Retrieval Query

Query published documents in a namespace and receive cited evidence for downstream agents.

POST /v2/retrieval/query
v2 endpoint

This is a v2 endpoint. Optional llm_config (BYOK) is supported here only — not on POST /v1/retrieval/query.

Request Body

ParameterTypeRequiredDescription
querystringYesNatural-language retrieval query.
namespacestringNoIsolation namespace. Defaults to "default". Max 255 chars.
top_kintegerNoMaximum number of results to return. Default: 10.
use_agenticboolean | nullNoWhen true, enables agentic retrieval (LLM document selection + section navigation). Default (null/false) uses classic 3-channel top-K.
chunk_typesstring[]NoAllowed chunk types: "text", "image", "table", "page". Empty or omitted means all types. Overrides data_type when provided.
data_typeintegerNoDeprecated. Legacy chunk-type filter (18). Prefer chunk_types. Default: 1 (all).
signal_pathsstring[]NoPath keywords for include/exclude filtering.
filter_modestringNoSignal-path filter mode: "delete" (default) or "keep".
channelsstring[]NoLexical channels to run: "path", "content", "term". Empty means all.
channel_weightsobjectNoPer-channel weight overrides (keys: path, content, term).
rerankbooleanNoEnable LLM reranking after RRF fusion. Default: false.
thresholdnumberNoMinimum RRF score threshold. Default: 0.0.
internal_recall_kintegerNoOverride per-channel recall count.
exclude_document_idsstring[]NoDocument IDs to exclude from results.
exclude_sectionsobject[]NoSection exclusions. Each item: { "document_id": string, "section_path": string }.
llm_configobjectNoBring-your-own-key (BYOK) OpenAI-compatible LLM credentials. Flat {api_key, model, base_url} applies to both channels; models picks per-channel model ids on the same endpoint; text / vision objects replace a channel entirely. When omitted, server defaults are used.
llm_config.api_keystringConditionalRequired with base_url plus model and/or models. Provider API key.
llm_config.modelstringConditionalDefault model for both channels (overridden by models.*).
llm_config.base_urlstringConditionalRequired with api_key plus model and/or models. OpenAI-compatible base URL.
llm_config.modelsobjectNoPer-channel model ids sharing root api_key / base_url.
llm_config.models.textstringNoText / planning model id.
llm_config.models.visionstringNoVision / VLM model id.
llm_config.textobjectNoText / planning LLM provider config (replaces root for text).
llm_config.text.api_keystringConditionalRequired when text is present. Provider API key.
llm_config.text.modelstringConditionalRequired when text is present. Model identifier.
llm_config.text.base_urlstringConditionalRequired when text is present. OpenAI-compatible base URL.
llm_config.visionobjectNoVision / VLM provider config (replaces root for vision).
llm_config.vision.api_keystringConditionalRequired when vision is present. Provider API key.
llm_config.vision.modelstringConditionalRequired when vision is present. Model identifier.
llm_config.vision.base_urlstringConditionalRequired when vision is present. OpenAI-compatible base URL.

Response

Status: 200 OK

{
"namespace": "default",
"query": "What are the key findings on AI security?",
"router_used": "agentic",
"evidence_text": "# AI_Security_Report.docx\n## 1. Overview\n...",
"answer_text": "",
"referenced_chunks": [
{
"chunk_id": "d88e4c47-3c48-5bdf-b849-693c00453021",
"document_id": "doc_abc123def456",
"chunk_type": "text",
"section_path": "AI_Security_Report.docx / 1. Overview / 1.1 Key Findings",
"source_chunk_path": "kb/AI_Security_Report.docx/1. Overview/1.1 Key Findings",
"file_path": null,
"asset_url": null,
"metadata": null
}
],
"results": [
{
"chunk_id": "d88e4c47-3c48-5bdf-b849-693c00453021",
"chunk_type": "text",
"content": "Key findings include...",
"score": 0.42,
"source_chunk_path": "kb/AI_Security_Report.docx/1. Overview/1.1 Key Findings",
"file_path": null,
"asset_url": null,
"metadata": null,
"source": {
"document_id": "doc_abc123def456",
"source_file_name": "AI_Security_Report.docx",
"section_path": "AI_Security_Report.docx / 1. Overview / 1.1 Key Findings"
}
}
],
"stop_reason": null,
"failure_reason": null,
"decision_trace": null
}

Response Fields

FieldTypeDescription
namespacestringEffective namespace used for the query.
querystringEcho of the request query.
router_usedstringRetrieval route taken (e.g. classic RRF or agentic).
evidence_textstringHierarchical evidence text. Primary output for downstream agents.
answer_textstringDeprecated. Always empty; KNOWHERE does not synthesize answers. Use evidence_text and synthesize downstream.
referenced_chunksobject[]Structured chunk citations (especially useful after agentic retrieval).
referenced_chunks[].chunk_idstringContent-hash chunk identifier.
referenced_chunks[].document_idstringParent document ID.
referenced_chunks[].chunk_typestring"text", "image", "table", or "page".
referenced_chunks[].section_pathstringHuman-readable section path.
referenced_chunks[].source_chunk_pathstring | nullOriginal parser path.
referenced_chunks[].file_pathstring | nullAsset path for images/tables.
referenced_chunks[].asset_urlstring | nullPresigned asset URL when available.
resultsobject[]Ranked chunk results with scores and source citations.
results[].chunk_idstring | nullChunk identifier.
results[].chunk_typestringChunk type.
results[].contentstringChunk content (text or HTML).
results[].scorenumber | nullRelevance score.
results[].sourceobjectCitation: document_id, source_file_name, section_path.
stop_reasonstring | nullWhy agentic retrieval stopped (when applicable).
failure_reasonstring | nullFailure detail when retrieval could not complete normally.
decision_traceobject[] | nullPer-step agentic observation/decision/result trace.

Examples

Basic Query

curl -X POST https://api.knowhereto.ai/v2/retrieval/query \
-H "Authorization: Bearer $KNOWHERE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"query": "What are the key findings on AI security?",
"namespace": "default",
"top_k": 10
}'

Agentic Retrieval

curl -X POST https://api.knowhereto.ai/v2/retrieval/query \
-H "Authorization: Bearer $KNOWHERE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"query": "Summarize supply-side recommendations from the security report",
"namespace": "default",
"use_agentic": true,
"chunk_types": ["text", "table"],
"top_k": 10
}'

With Custom LLM (BYOK)

OpenAI-compatible providers only.

  • Flat {api_key, model, base_url} → both text and vision (multimodal shorthand)
  • {api_key, base_url, models: {text, vision}} → same endpoint, different model ids
  • text / vision objects → fully replace that channel (set both for different endpoints)
  • a channel with no resolved model keeps the server default
curl -X POST https://api.knowhereto.ai/v2/retrieval/query \
-H "Authorization: Bearer $KNOWHERE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"query": "What are the key findings on AI security?",
"namespace": "default",
"use_agentic": true,
"llm_config": {
"api_key": "sk-...",
"model": "gpt-4.1",
"base_url": "https://api.openai.com/v1"
}
}'

Errors

CodeHTTP StatusDescription
INVALID_ARGUMENT400Missing or invalid parameters (e.g. empty query, invalid llm_config)
UNAUTHENTICATED401Invalid API key
RESOURCE_EXHAUSTED429Rate limit exceeded

Example Error Response

{
"success": false,
"error": {
"code": "INVALID_ARGUMENT",
"message": "llm_config requires root credentials and/or text/vision overrides",
"request_id": "req_abc123",
"details": {
"field": "llm_config"
}
}
}

Next Steps