API, MCP, CLI, Skill, and other integration paths.
Once a Knowledge Retrieval or Q&A service is published, you can integrate it into your application through several channels. The Service Channels page in the console shows the integration details and sample code for each one.
All retrieval and Q&A capabilities are exposed through the DashScope API at
Create an API Key in the Console API Key page. The system routes requests to the correct workspace based on the API Key.
Main endpoints:
See the API Reference for the full list.
MCP (Model Context Protocol) is an open protocol that lets AI coding assistants and Agent frameworks call external tools directly. After connecting to the Knowledge MCP Server, your AI assistant can retrieve from your Knowledge Bases mid-conversation.
Parameters for
Parameters for
Supported clients:
Run
For all 34 commands, parameter constraints, and output formats, see the CLI reference.
Integrate your Knowledge Base as a skill package into AI coding tools such as Qoder or Claude Code. Install URL:
KnowledgeStudio Knowledge Bases can be integrated as external capabilities into Alibaba Cloud Bailian agent applications in two ways:
Use this method for Agent 2.0 applications. The agent decides when to invoke the Knowledge Base according to its task plan, alongside other tools such as MCP.
Use this method for workflow applications with ordered steps. KnowledgeStudio serves as a Knowledge Base Retrieval node in the workflow.
Channel comparison
| Channel | Protocol | Best for | Notes |
|---|---|---|---|
| Dash API | REST / SSE | Backend services you own | DashScope HTTP endpoints. |
| MCP Server | MCP | AI Agent frameworks | Works with Qoder, Claude Code, Codex, and others. |
| Python SDK | Python | Python apps | Wraps auth, retries, and stream parsing. |
| Java SDK | Java | Java apps | Pulled in as a Maven dependency. |
| CLI | Command line | Local debugging, scripts, CI | kscli — 34 commands covering Knowledge Base management, retrieval, and chat. |
| Agent Skill | Skill package | Qoder / Claude Code | Integrate the Knowledge Base as a skill package. |
| Bailian Agent | Web | Quick validation / low-code | Supports Agent binding and Workflow binding in Alibaba Cloud Bailian. |
Dash API
All retrieval and Q&A capabilities are exposed through the DashScope API at https://{workspaceId}.cn-beijing.maas.aliyuncs.com.
Authentication:
| Endpoint | Method | Path |
|---|---|---|
| Retrieve | POST | /api/v1/indices/rag/index/retrieve |
| Q&A | POST | /api/v2/apps/knowledge/chat |
| Knowledge search | POST | /api/v1/indices/knowledge/search |
MCP Server
MCP (Model Context Protocol) is an open protocol that lets AI coding assistants and Agent frameworks call external tools directly. After connecting to the Knowledge MCP Server, your AI assistant can retrieve from your Knowledge Bases mid-conversation.
Prerequisites
- At least one Knowledge Base containing successfully parsed documents.
- An API Key.
- An MCP-compatible client (Qoder, Claude Code, Codex, etc.).
Setup
1
Get an API Key
Create an API Key in the Console API Key page. Store it as an environment variable:
2
Add the MCP Server in your client
Pick the configuration that matches your client:
- Qoder / QoderWork
- Claude Code
- Codex
Open the MCP config file and add:
3
Verify the connection
From your client, try invoking the Knowledge Base. For example, in Claude Code:
Search the knowledge base for "how to create a knowledge base"If the assistant successfully calls the
Retrieve tool and returns matches, the integration is working.Connection details
| Item | Value |
|---|---|
| Endpoint | https://{workspaceId}.cn-beijing.maas.aliyuncs.com/api/v1/indices/rag/mcp |
| Protocol version | MCP 2024-11-05 |
| Transport | Streamable HTTP (POST + GET SSE) |
| Auth | Authorization: Bearer <API-Key> |
Tools
| Name | Function | Description |
|---|---|---|
ListIndices | List Knowledge Bases | Paginated list of Knowledge Bases in the current workspace, filterable by name prefix. |
Retrieve | Retrieve from a Knowledge Base | Retrieve relevant Chunks with hybrid search and Rerank. |
Retrieve:
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
IndexId | string | Yes | — | Knowledge Base index ID. |
Query | string | Yes | — | Query text; cannot be empty. |
DenseSimilarityTopK | integer | No | 100 | Semantic retrieval recall count, range 0–100. |
SparseSimilarityTopK | integer | No | 100 | Keyword retrieval recall count, range 0–100. |
EnableReranking | boolean | No | true | Whether to apply reranking. |
Rerank.ModelName | string | No | qwen3-rerank | Rerank model; either qwen3-rerank or qwen3-rerank-hybrid. |
RerankMode, RerankMinScore, RerankTopN, and RerankInstruct on the Rerank object are not available in this version and will return an error if passed. Use EnableReranking and Rerank.ModelName to control reranking.ListIndices:
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
pageNumber | integer | No | 1 | Page number, starting from 1. |
pageSize | integer | No | 10 | Items per page. |
indexName | string | No | — | Filter by Knowledge Base name prefix. |
- Qoder / QoderWork
- Claude Code
- Codex (0.120.0+)
- Alibaba Cloud Model Studio MCP custom integration (Agent)
- Any other MCP-compatible client
CLI
kscli (Knowledge Studio CLI) is the command-line tool for Knowledge Bases. Its 34 commands span Knowledge Base setup, content maintenance, retrieval service management, and retrieval/chat. No code required — it fits local debugging, scripting, and CI/CD pipelines. The console Service Channels page provides the install command and usage examples.
This section covers Knowledge Studio CLI (
kscli), a different tool from the Bailian CLI (bl). Bailian CLI uses bl knowledge search --agent-id <retrieval-service-id> --query "your query" to call a published retrieval service; --agent-id is not a Knowledge Base ID. Do not mix the two tools' installation, configuration, or commands.Prerequisites
- Node.js 20 or later.
- At least one Knowledge Base containing successfully parsed documents.
- An API Key.
Quickstart
1
Install the CLI
kscli --version to verify the installation.2
Configure the API Key and workspace
Obtain the actual workspace ID (e.g.,
llm-xxxxxxxxxxxx) from Workspace Management in the console; see API endpoint. Replace ws-xxxxxxxx below with that ID. The API Key, Knowledge Base, and retrieval service must belong to this workspace. Once written to the config file, later commands no longer need these flags:3
Run your first retrieval
List the retrieval services in the workspace, then retrieve with a service ID:The command prints the matched Chunks along with their relevance scores.
Common commands
| Command | Purpose |
|---|---|
kscli kb list | List Knowledge Bases |
kscli doc upload --file <path> --index-id <id> | Upload files and import them into a Knowledge Base |
kscli service list --scene search | List retrieval services and their IDs |
kscli search --query <text> --agent-id <id> | Run a semantic retrieval |
kscli chat --message <text> --agent-id <id> | Run a Knowledge conversation |
kscli retrieve --index-id is the earlier direct-retrieval command and is now deprecated — it prints a deprecation warning when used. Use search instead: retrieval scope and strategy come from the service config behind --agent-id, which supports multiple Knowledge Bases, routing, and reranking.Agent Skill
Integrate your Knowledge Base as a skill package into AI coding tools such as Qoder or Claude Code. Install URL: https://skills.aliyun.com/skills/alibabacloud-bailian-rag-knowledgebase. You can also obtain this link on the console's Service Channels → Agent Skill page.
Once installed, the AI coding tool automatically detects and loads Knowledge Base retrieval capabilities without manual configuration.
Bailian Agent
KnowledgeStudio Knowledge Bases can be integrated as external capabilities into Alibaba Cloud Bailian agent applications in two ways:
Method 1: Agent binding (recommended)
Use this method for Agent 2.0 applications. The agent decides when to invoke the Knowledge Base according to its task plan, alongside other tools such as MCP.
- In the Bailian console, select Create Application → Agent Application → Agent 2.0.
- In the Knowledge Base section, select External Knowledge Base → KnowledgeStudio.
- Enter your API Key and Knowledge Base ID, then publish.
Method 2: Workflow binding
Use this method for workflow applications with ordered steps. KnowledgeStudio serves as a Knowledge Base Retrieval node in the workflow.
- In the Bailian console, select Create Application → Workflow Application.
- Drag a Knowledge Base Retrieval node onto the canvas and select KnowledgeStudio as the source.
- Connect the start, LLM, and end nodes, then publish the application.
Selection guidance
| Method | Best for |
|---|---|
| Agent binding | Dynamic tasks that require multi-step reasoning and autonomous decisions, such as enterprise Q&A or complex research. |
| Workflow binding | Fixed processes that require strict execution order, such as report generation, customer-service routing, or diagnostic assistance. |