Skip to main content

Knowledge Search

Retrieve relevant content from Knowledge Bases, returning document chunks or Wiki pages

POST
/api/v1/indices/knowledge/search
# Obtain agent_id from List Agents with agent_scene=search and search_type=wiki
curl -X POST "https://{workspaceId}.cn-beijing.maas.aliyuncs.com/api/v1/indices/knowledge/search" \
  -H "Authorization: Bearer $DASHSCOPE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "agent_id": "aid-wiki-xxxxxxxxxxxx",
    "query": "What is hybrid retrieval?",
    "kb_search_configs": [
      {
        "id": "kb_tech_001",
        "search_filters": [
          {"page_type": ["CONCEPT", "ENTITY"]},
          {"category_path": ["Technology", "Retrieval"]}
        ]
      }
    ]
  }'
{
  "success": true,
  "status": "SUCCESS",
  "request_id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
  "data": {
    "total": 1,
    "nodes": [
      {
        "score": 0.92,
        "text": "doc_name: Sports jacket guide\ntitle: Suitable seasons\ncontent: This sports jacket is suitable for outdoor activities in autumn and winter.",
        "metadata": {
          "pipeline_id": "kb_product_001",
          "doc_id": "file_abc_123",
          "doc_name": "Sports jacket guide",
          "title": "Suitable seasons",
          "content": "This sports jacket is suitable for outdoor activities in autumn and winter."
        }
      }
    ],
    "cost_time": 2629
  },
  "status_code": 200,
  "code": "Success",
  "message": "success"
}
Retrieve relevant content from one or more knowledge bases. Vector retrieval returns document chunks; Wiki retrieval returns page titles, summaries, and metadata.

Invocation and limits

  • Vector retrieval: Provide at least one of agent_id and pipeline_id_list. If both are provided, agent_id takes precedence. With only pipeline_id_list, knowledge bases are searched directly using the default strategy.
  • Service-based retrieval: When using agent_id, configure and publish the service in the console first. An unpublished service returns RagAgentNotExist. Omit agent_version to use the currently published version.
  • Query intent: Vector retrieval requires at least one of query and images. query is limited to 4500 UTF-8 bytes. images accepts up to 10 items; only the first image is used. Image-only search requires a knowledge base with image extraction enabled.
  • Search scope: pipeline_id_list accepts up to 15 items; file_id_list accepts up to 10. Omitting file_id_list or passing [] adds no document restriction. In vector retrieval, it is merged and deduplicated with the doc_id filter; the scope is their union.
  • Rate limit: Up to 10 requests per 10 seconds. The limiting dimension is pending confirmation; actual service throttling applies. See Rate limits for handling recommendations.

Wiki retrieval

Enabling Wiki on a knowledge base automatically creates a corresponding Wiki retrieval service. Call List Agents with agent_scene=search and search_type=wiki, optionally adding pipeline_id, to obtain its agent_id.
agent_id is a retrieval service ID, not a knowledge base ID (pipeline_id). Passing a knowledge base ID returns RagAgentGroupNotExist (Agent application not found.). A vector retrieval service has search_type=chunk; its ID cannot be used to switch to Wiki retrieval. This endpoint does not accept search_type as a retrieval-mode switch.
  • agent_id is required. All bound knowledge bases must have Wiki enabled, otherwise WikiNotEnabled is returned. The retrieval type is fixed at service creation.
  • query is required and must not be empty. Image queries and direct Wiki retrieval through pipeline_id_list are not supported.
  • file_id_list causes an error only when non-empty. [] is equivalent to omitting it.
  • doc_id, tags, and custom metadata filters are not supported. Only the following filter fields are supported.
Filter fieldType and description
page_typeString or string array; SUMMARY / ENTITY / CONCEPT / INDEX / SYNTHESIS / COMPARISON, case-insensitive
folder_idFolder ID, string; an empty string denotes the root folder
category_pathFolder name path from the root to the current folder, string array
An invalid Wiki filter value, such as a misspelled page_type, returns empty results rather than an error. An unsupported filter field returns InvalidParameter.Disabling Wiki does not delete the existing Wiki retrieval service. Its original agent_id becomes usable again after Wiki is re-enabled. This does not restore old pages or mean that all data disappears immediately on disable; wait for cleanup and regeneration to finish.

Wiki request example

{
  "agent_id": "aid-wiki-xxxxxxxxxxxx",
  "query": "What is hybrid retrieval?",
  "kb_search_configs": [
    {
      "id": "kb_tech_001",
      "search_filters": [
        {"page_type": ["CONCEPT", "ENTITY"]},
        {"category_path": ["Technology", "Retrieval"]}
      ]
    }
  ]
}

Filters and strategies

kb_search_configs takes effect only when agent_id is provided. Each id must be present, non-empty, bound to the service, and unique within the request.
  • Request search_filters are appended to service-configured conditions with AND, not substituted. The serialized merged array for each knowledge base must not exceed 80000 UTF-8 bytes.
  • Vector retrieval supports doc_id, tags, and custom metadata fields written to the index. The top-level tags array for an unstructured knowledge base is limited to 1000 items.
  • Both retrieval modes support logical grouping with _operator (AND / OR, case-insensitive) and _conditions.
  • Field comparison supports eq / neq / like / unlike / is_null / gt / gte / lt / lte. Set operators include contains / ncontains / intersect / nintersect / within / nwithin.
For service-based retrieval, recall counts, reranking, knowledge routing, and multi-base weights are managed in agent_config and cannot be overridden in the request. See the parameter table above for full fields and filter examples.

Response

data.total is the number of results returned, equal to the length of nodes; cost_time is latency in milliseconds. Each result contains score, text, and metadata. score may be null; its range depends on retrieval and reranking models and is not restricted to 0–1. Wiki results have metadata.source_type=WIKI_PAGE and page fields including wiki_page_id, slug, title, summary, page_type, wiki_path, category_path, source_doc_ids, and version (see WikiSearchNodeMetadata). text contains the title and summary by default, not necessarily the full body. Verify critical content against the source documents identified by source_doc_ids.
Metadata fields beginning with _ are used for internal scoring and may change between versions; do not depend on them in business logic. Vector retrieval from tabular knowledge bases also returns business fields from the table schema.

Error handling

Always check success. On failure, status is ERROR; the response-body status_code is a business status code, not the transport-layer HTTP status. Use code and message together, and provide request_id when troubleshooting.
codestatus_codeTypical scenario
InvalidParameter400No valid retrieval target, invalid query intent, exceeded limits, non-empty Wiki file_id_list, or unsupported Wiki filter field
RagAgentGroupNotExist400Service does not exist, or a knowledge base ID is passed as agent_id
RagAgentNotExist400Service unpublished or specified version not found
WikiNotEnabled400Not all bound knowledge bases have Wiki enabled
See the error reference for verified code and message values. The shared InvalidParameter code alone does not identify the cause.

Authorizations

string
header
required

DashScope API Key, obtained from the API Key page in the console.

Body

application/json
string

Knowledge retrieval service ID, not a knowledge base ID, obtainable via List Agents. Uses the service's retrieval strategy; the retrieval type is fixed at creation and cannot be switched at call time. Find Wiki services with agent_scene=search + search_type=wiki; do not substitute a regular chunk retrieval service ID.

  • Vector retrieval: provide at least one of agent_id and pipeline_id_list; if both are provided, agent_id takes precedence.
  • Wiki retrieval: required.
string
default""

Query text, limited to 4500 UTF-8 bytes.

  • Vector retrieval: provide at least one of query and images; for image-only retrieval, omit the text or pass an empty string.
  • Wiki retrieval: required and must not be empty.
string[]
default[]

Publicly accessible image URLs, up to 10 items. Only the first image is used.

  • Vector retrieval: can be combined with query; image-only retrieval requires a knowledge base with image extraction enabled.
  • Wiki retrieval: image queries are not supported.
string[]

Document IDs restricting the search scope, up to 10 items. Omitted or empty adds no document restriction.

  • Vector retrieval: merged and deduplicated with the doc_id filter; the search scope is their union.
  • Wiki retrieval: only a non-empty array causes an error; [] is equivalent to omitting it.
string[]

Knowledge base IDs for direct retrieval, up to 15 items.

  • Vector retrieval: provide at least one of this array and agent_id; if both are provided, agent_id takes precedence. When using this array alone, it must not be empty; retrieval uses the default strategy.
  • Wiki retrieval: not supported; use agent_id.
string

Retrieval service version, used with agent_id. Defaults to the currently published version.

object[]

Per-knowledge-base filters, effective only when agent_id is provided. Each item contains a knowledge base ID and its filters.

Response

200-application/json
string

Business status code. Success on success; otherwise the error code string.

integer

Business status code in the response body, not the transport-layer HTTP status. See the error reference.

string

Status enum. SUCCESS on success, ERROR on failure.

boolean

Whether the request succeeded. Callers should use this field as the primary verdict.

string

Status description.

string

Unique request identifier. Include this ID when reporting an issue.

object