Install and authenticate the Bailian CLI, then use its 36 Knowledge commands for knowledge bases, documents, chunks, and retrieval/Q&A services.
The Bailian CLI (package
The npm method requires Node.js ≥ 18.17.0 and npm. Do not use pnpm / yarn to install
Without Node.js, use the binary installer instead. For macOS / Linux:
For Windows PowerShell:
Both
Knowledge calls use a standard DashScope API Key (Bearer token). Coding Plan Keys in the
If a browser cannot open automatically, use
For CI and other non-interactive environments, inject
Knowledge resources belong to a workspace. After console login, list workspaces and configure the target ID:
Knowledge commands accept
This list counts only
Use
Call a Q&A service by ID for streaming RAG Q&A. See Knowledge Q&A for service configuration.
The SSE lifecycle is
Bailian CLI 2.5.0 removed
The workflow uploads sample data, creates a knowledge base and retrieval service, and verifies the first retrieval, with recovery and resource reuse. It uses the retrieval service beta draft, does not publish a service, and does not create a Q&A service. Keep the state file for recovery. Dry-run still reads existing resources but changes neither resources nor checkpoints. Actual initialization without
Structure and storage types are
Each command below accepts
Use the knowledge-base ID from list output as
A data-center file is the raw asset; importing it into a knowledge base creates an indexed document. Do not confuse
The pipeline is upload lease → streaming PUT to OSS → file registration → import job creation when index-id is supplied. Files are processed sequentially. On failure, the error hint lists already-registered file IDs.
This reuses file IDs without re-uploading, but can trigger parsing, indexing, and model charges. Keep the returned import job ID for later
Each command below accepts
Each command below accepts
Each command below accepts
In practice, all supported knowledge-base types require
Document, table, and image knowledge bases are supported; audio/video knowledge bases are not. Image-type documents do not accept text chunks; target text-type documents such as docx/pdf/txt. The API is idempotent but limited to 10 calls per second, so throttle batches. The response does not include a chunk ID; list chunks afterwards to locate the new entry.
For update, use
Categories organize files by business domain. Collections define storage, using platform-managed storage by default or your own OSS bucket. Each command below accepts
Files with no explicit category go into the category marked
Services are the entry points for search/chat. Create and bind a knowledge base → verify the beta draft → deploy a published version. Each command below accepts
New services have draft status and beta version. Run list once per scene to view both chat and search services. Use the returned agent_id for calls or service management. Creating a service requires knowledge-base create permission in the workspace.
Scalar configuration uses read-merge-write against the draft; config-file replaces the entire configuration. Published configuration cannot be changed directly. Update beta, verify with
bailian-cli, commands bl / bailian) uses bl knowledge to manage knowledge bases and call retrieval and Q&A services. This page covers only Knowledge capabilities. Command details follow the source reference's bl 2.8.0 baseline, with the 2.5.0 migration note retained.
This page and the Knowledge Studio CLI (kscli) manual document two different tools. The latter installs from
knowledge-studio-cli and uses commands such as kscli kb. Do not simply replace command prefixes or apply this page's flags, confirmation rules, output behavior, or version changes to kscli. Knowledge capabilities in the Bailian CLI are currently available only to China site (aliyun.com) accounts.Installation, authentication, and workspace
Install
The npm method requires Node.js ≥ 18.17.0 and npm. Do not use pnpm / yarn to install bailian-cli:
bl and bailian should be on PATH after installation. If the command is not found, run npm config get prefix and check its bin directory for npm installs, or check the path printed by the binary installer. Run bl update to check for and install updates.
Sign in and select an API Key
Knowledge calls use a standard DashScope API Key (Bearer token). Coding Plan Keys in the sk-sp-xxx format do not support knowledge-base services. Do not substitute a subscription model-call profile for Knowledge credentials.
For local use, console login is recommended. It defaults to the China site and creates a standard API Key when needed:
bl auth login --console --no-browser to print the login URL. Alternatively, obtain a standard Key from the Bailian console API Key page and sign in. The command tests the Key before saving it:
DASHSCOPE_API_KEY through secret management instead of saving the Key in a configuration file or script. With multiple profiles, inspect and select the intended one rather than assuming the active Key is a standard Key:
bl config show reports the effective sources of the API Key and Base URL and warns when they come from different configuration sources. Confirm the active credential from masked status output; do not infer Bailian CLI credential precedence from kscli or another Skill's documentation. Use bl auth logout to clear local credentials.
Set the workspace
Knowledge resources belong to a workspace. After console login, list workspaces and configure the target ID:
--workspace-id <id> for the workspace in the API endpoint URL. You can also use the BAILIAN_WORKSPACE_ID environment variable or the workspace_id config key. Examples below that omit the workspace assume it is configured. bl workspace list is a console capability: having a standard API Key is not the same as completing console login.
Shared conventions and safety
- Append
--helpto any command for full parameters, for examplebl knowledge search --help. - The default output is text.
--output jsonreturns complete business results on stdout and writes warnings, diagnostics, and errors separately to stderr as JSONL. You can also select JSON withDASHSCOPE_OUTPUT=jsonor theoutputconfig key. --quiet(orDASHSCOPE_QUIET=1) hides only progress and informational messages. It preserves complete results, the final answer, warnings, and errors; it does not mean “ID/answer only.” Scripts should read JSON fields.- High-risk deletion, service deployment, and initialization or sync replacement/deletion that require confirmation are blocked with exit code 7 unless
--yesis explicitly supplied. They do not wait for interactive input and then continue. Preview with--dry-runbefore confirming the scope. - Dry-run is not an offline mode:
knowledge init --dry-runstill requires credentials and reads existing resources, but does not change resources or checkpoints.
All 36 Knowledge commands
This list counts only bl knowledge commands, not installation, authentication, or configuration commands. The Bailian CLI creation command is bl knowledge create, not bl knowledge kb create. IDs, file paths, and image URLs in examples are placeholders: replace them with your own resources and prepare JSON files in the format required by each flag.
| Command | Purpose |
|---|---|
bl knowledge search | Call a retrieval service |
bl knowledge chat | Call a Q&A service |
bl knowledge init | Initialize and verify sample retrieval |
bl knowledge create | Create a knowledge base and import files/categories |
bl knowledge list | List knowledge bases |
bl knowledge info | Inspect knowledge-base configuration |
bl knowledge update | Update name, description, or rerank threshold |
bl knowledge delete | Delete a knowledge-base index |
bl knowledge stats | Query storage and QPS metrics |
bl knowledge doc upload | Upload local files/directories, optionally importing them |
bl knowledge doc import | Import existing data-center files into a knowledge base |
bl knowledge doc sync | Synchronize a local document directory |
bl knowledge doc import-oss | Import from OSS into the data center |
bl knowledge doc list | List knowledge-base documents and status |
bl knowledge doc status | Track an import job |
bl knowledge doc tag | Update data-center file tags |
bl knowledge doc delete | Delete indexed documents and chunks |
bl knowledge file get | Inspect a source file |
bl knowledge file list | List source files in a category |
bl knowledge file delete | Delete a data-center source file |
bl knowledge chunk add | Add a chunk |
bl knowledge chunk list | List chunks |
bl knowledge chunk update | Update content or retrieval visibility |
bl knowledge chunk delete | Delete chunks |
bl knowledge category add | Create a category |
bl knowledge category list | List categories |
bl knowledge category delete | Delete a category |
bl knowledge collection create | Create a collection |
bl knowledge collection get | Inspect a collection |
bl knowledge service create | Create a retrieval/Q&A service draft |
bl knowledge service list | List services |
bl knowledge service get | Inspect a service and its version configurations |
bl knowledge service update | Update service metadata or draft configuration |
bl knowledge service deploy | Publish a draft as a new version |
bl knowledge service copy | Copy a service to a new draft |
bl knowledge service delete | Delete a service |
Retrieval and Q&A
search
--agent-id must be a retrieval service ID, not a knowledge-base ID. The service configuration determines retrieval scope, multi-index recall, routing, ranking, and reranking. See Knowledge retrieval for service configuration.
| Flag | Constraint |
|---|---|
--agent-id <id> | Required retrieval service ID |
--query <text> | Query text; provide at least one of query or image, or both |
--image <url> | Repeatable image URL; image-only retrieval without query is supported |
--agent-version <version> | beta draft or a published version number; defaults to the latest published version |
--kb-search-configs-file <path> | JSON array file with knowledge-base IDs and online search_filters for each base |
--workspace-id <id> | Workspace ID, also configurable through the environment or config key |
--agent-version beta to debug before deployment. JSON output preserves request_id, data.total, data.cost_time, and data.nodes. Nodes contain score, text, and metadata such as title, document ID, URL, page number, and media URLs. Text mode prints scores, text, and media summaries per node.
chat
Call a Q&A service by ID for streaming RAG Q&A. See Knowledge Q&A for service configuration.
| Flag | Constraint |
|---|---|
--agent-id <id> | Required Q&A service ID |
--message <text> | Repeatable; accepts role:content, defaults to user, and follows the OpenAI message format |
--image <url> | Repeatable; attached as multimodal content to the last user message |
--messages-file <path> | Complete messages JSON array, including tool history; mutually exclusive with --message and --image |
--agent-version <version> | beta draft or a published version number; defaults to the latest published version |
--enable-cache-control <true|false> | Explicit context-cache control |
--request-id <id> | Business request ID |
--session-file-id <fileId> | Repeatable, up to 10; requires service-side file preprocessing |
--workspace-id <id> | Workspace ID, also configurable through the environment or config key |
tool_calling → tool_return → plan_start → planning → plan_end → generation_start → generating → generation_end. Tool calls and returns can repeat.
JSON output separates the final answer from process information: read answer for the answer and phases, tools, docs, usage, and events for phases, tools, sources, usage, and events. Quiet does not reduce the result to an answer string. Scripts that extracted answers from quiet output should read JSON fields instead.
Migrate from retrieve
Bailian CLI 2.5.0 removed bl knowledge retrieve. Use bl knowledge search instead. Create a retrieval service bound to the target knowledge base and pass its --agent-id; do not reuse the old --index-id value. Configure recall, ranking, and reranking in the service rather than carrying over old retrieval flags. This statement does not establish version behavior for standalone kscli.
Knowledge-base management
init: recoverable sample initialization
| Flag | Constraint |
|---|---|
--name <name> | 1–20 characters; default cli-demo |
--state-file <path> | Recovery checkpoint; default ~/.bailian/knowledge/init/<key>.json, keyed by workspace and name |
--poll-interval <seconds> | Polling interval; default 5 seconds |
--workspace-id <id> | Workspace ID |
--yes | Confirm knowledge-base creation and billing |
--yes is blocked with exit code 7. Use the cleanup actions in the output for knowledge bases you no longer need.
create: create and import
| Flag | Constraint |
|---|---|
--name <text> | Required, 1–20 characters, unique in the workspace |
--description <text> | Required by the CLI, 1–500 characters; describe content and purpose |
--doc-id <id> | Repeatable data-center file ID; choose this or --category-id |
--category-id <id> | Import every file under each specified category; repeatable and mutually exclusive with --doc-id |
--embedding-model <name> | Document default: text-embedding-v4; multimedia/visual scenes: qwen3-vl-embedding |
--knowledge-type <document|multimedia> | Knowledge-base type |
--knowledge-scene <scene> | Scene; requires --knowledge-type |
--multimodal-embedding-model <name> | Alias of --embedding-model in multimedia/visual scenes |
--chunk-size <n> | Characters; CLI default 600, recommended 300–800 |
--wait | Poll the initial import job to a terminal state |
--poll-interval <seconds> | Default 5 seconds |
--workspace-id <id> | Workspace ID |
unstructured and BUILT_IN. Multimedia bases use basic_multimedia_qa, qwen3-vl-embedding, and qwen3-vl-rerank; explicitly selected models are validated by the server. The command returns the knowledge-base ID pipelineId and initial import job ID ingestionId. Track the job with doc status or --wait.
The required description and default chunk size of 600 are Bailian CLI constraints, not universal console or REST rules. The REST create API makes description optional and defines its own chunkSize default. Do not replace the CLI default of 600 with the REST default of 500.
list, info, update, delete, and stats
Each command below accepts --workspace-id <id>.
| Command | Required flags | Optional flags and behavior |
|---|---|---|
bl knowledge list | No command-specific required flag | --name <text> fuzzy match, 1–20 characters; --page-number <n> defaults to 1; --page-size <n> |
bl knowledge info | --index-id <id> | Returns knowledge-base configuration |
bl knowledge update | --index-id <id> | --name <text> 1–20 characters; --description <text>; --rerank-min-score <score> 0–1, filters out lower-scoring chunks |
bl knowledge delete | --index-id <id> | --yes confirms permanent deletion of the base, documents, and chunk indexes; data-center source files remain |
bl knowledge stats | --index-id <id> | --start <time> and --end <time> accept Unix seconds or ISO dates; defaults to the last 24 hours |
--index-id in management commands. Index settings such as embedding model and chunk size are immutable; recreate the base to change them. Monitoring timestamps are normalized to epoch seconds. Future start times are rejected; future end times are clamped to now.
Documents and data-center files
A data-center file is the raw asset; importing it into a knowledge base creates an indexed document. Do not confuse fileId, document-level doc_id, and chunk IDs. Source-file deletion and indexed-document deletion are independent.
doc upload: upload local files
| Flag | Constraint |
|---|---|
--file <path> | Required, repeatable local file/directory; directories are scanned recursively, skipping unsupported formats and directories such as node_modules and .git |
--index-id <id> | Import after registration, using one import job for all files |
--category-id <id> | Target data-center category; resolves the workspace default when omitted |
--tag <text> | Repeatable; applied to every uploaded file |
--category-type <UNSTRUCTURED|SESSION_FILE> | File category type; SESSION_FILE is for temporary chat attachments |
--parser <name> | Parser, such as AUTO_SELECT or DOCMIND_LLM_VERSION_MEDIA |
--parser-config-file <path> | JSON object file containing parser configuration |
--wait | Wait for the import job to reach a terminal state; requires --index-id |
--poll-interval <seconds> | Default 5 seconds |
--workspace-id <id> | Workspace ID |
This command supports audio/video files up to 2 GiB each. With
--index-id, it processes at most 50 local media files per call, without automatic batching. These are Bailian CLI upload constraints. They do not replace the 512 MB audio/video file limit in console knowledge-base creation, nor establish a universal limit for REST uploads.doc import: reuse existing files
| Flag | Constraint |
|---|---|
--index-id <id> | Required existing knowledge-base ID |
--doc-id <fileId> / --category-id <id> | Choose one; each is repeatable. Here doc-id is a data-center file ID |
--chunk-mode <mode> | h1, h2, h3, h4, h5, length, page, or regex; document chunking, not video time slicing |
--chunk-size <characters> | 1–6000 characters |
--overlap-size <characters> | 0–1024 characters |
--separator <regex> | Separator for regex mode |
--enable-headers <true|false> | Whether to extract document headers |
--wait | Wait for the import job to finish |
--poll-interval <seconds> | Default 5 seconds |
--workspace-id <id> | Workspace ID |
doc status queries. Do not assume that the init/sync --state-file flag is supported by this command.
doc sync: synchronize a local directory
| Flag | Constraint |
|---|---|
--dir <path> | Required local document directory |
--index-id <id> | Required target knowledge-base ID |
--category-id <id> | Data-center category; defaults to the workspace default on the first run |
--delete | Delete managed index documents that no longer exist locally |
--sync-id <uuid> | Synchronization set UUID |
--state-file <path> | Checkpoint; default <dir>/.bailian/sync/<key>.json, keyed by knowledge-base ID |
--poll-interval <seconds> | Default 5 seconds |
--yes | Confirm high-risk operations |
doc import-oss, list, status, tag, and delete
Each command below accepts --workspace-id <id>.
| Command | Required flags | Optional flags and behavior |
|---|---|---|
bl knowledge doc import-oss | --bucket <name>, --region <id>, --oss-key <key> | Repeatable oss-key, 1–10 per call; --category-id <id> defaults to the workspace default; repeatable --tag <text>, up to 10; --overwrite replaces files previously imported from the same OSS keys |
bl knowledge doc list | --index-id <id> | --page-number <n> defaults to 1; --page-size <n> server default 10, maximum 100; displays parse/index status |
bl knowledge doc status | --index-id <id>, --job-id <id> | job-id is ingestionId; --page-number <n> defaults to 1; --page-size <n>; --wait; --poll-interval <seconds> defaults to 5 |
bl knowledge doc tag | --doc-id <id>, --tag <text> | doc-id is a repeatable data-center file ID, 1–20 per call; tags are repeatable, up to 32 characters each; --mode <append|overwrite> defaults to append |
bl knowledge doc delete | --index-id <id>, --doc-id <id> | doc-id is a repeatable knowledge-base document ID; --yes confirms irreversible deletion of documents and their chunks, leaving data-center source files intact |
- Authorize the OSS bucket to the platform service role first. Permission errors are passed through; check
AliyunServiceRoleForBailianin the RAM console. File names come from the Object Key basename.--overwriteissues a new fileId and invalidates the old one. doc listhighlights FAILED documents in text mode.doc statusrequires both index-id and job-id. A SystemError may mean the job does not exist; check the ingestion ID in document-list output. Overall states are PENDING / RUNNING / COMPLETED. Per-document failures such as PARSE_FAILED exit non-zero and preserve the error.doc tagapplies the same tag set to every file. Server limits are 100 tags per file, 700 characters total, and 32 characters per tag.- Obtain document IDs from
bl knowledge doc listbefore deletion instead of using upload fileIds directly. A doc_id from create can equal fileId; one imported through upload with index-id can include a workspace suffix. Deletion can take about 30 seconds to propagate. Output lists the IDs actually deleted.
file get, list, and delete
Each command below accepts --workspace-id <id>.
| Command | Required flags | Optional flags and behavior |
|---|---|---|
bl knowledge file get | --file-id <id> | Returns size, MD5, tags, timestamps, and other details |
bl knowledge file list | --category-id <id> | --name <text> exactly matches the file name without its extension; repeatable --file-id <id> for exact matching; --next-token <token>; --max-result <n> |
bl knowledge file delete | --file-id <id> | --yes confirms permanent deletion of the data-center file |
file list requires a real category ID and does not resolve the literal default; find IDs with category list. To query a.md, pass a as name. Partial keywords do not match. Cursor pagination reuses the next token from the previous page.
file delete does not delete documents or chunk indexes already imported into knowledge bases. Use doc delete to remove indexed content. To clean up both resource layers, verify their IDs and deletion scopes separately.
Chunk management
Each command below accepts --workspace-id <id>.
chunk add
In practice, all supported knowledge-base types require --doc-id. Use the document-level ID from bl knowledge doc list, not a per-row doc_id from chunk list.
| Flag | Constraint |
|---|---|
--index-id <id> | Required knowledge-base ID |
--doc-id <id> | Document-level ID, required in practice |
--content <text> / --content-file <path> | Alternatives for a document-type chunk body; content is at most 6000 characters; content-file is UTF-8 plain text such as md/txt |
--title <text> | Document-type title, up to 50 characters |
--image-url <url> | Repeatable image URL for document-type chunks, up to 10 |
--field <key=value> | Repeatable fields for table/image knowledge bases; keys are Excel column headers and values remain strings; mutually exclusive with content/title/image flags |
chunk list, update, and delete
| Command | Required flags | Optional flags and behavior |
|---|---|---|
bl knowledge chunk list | --index-id <id> | --doc-id <id> filters by document; --page-number <n> defaults to 1; --page-size <n> server default 20, maximum 100 |
bl knowledge chunk update | --index-id <id>, --chunk-id <id>, --doc-id <id> | --content <text> or --content-file <path>; --title <text>; --exclude / --include control retrieval visibility (include is the default) |
bl knowledge chunk delete | --index-id <id>, --chunk-id <id> | Repeatable chunk-id; sends automatic batches of 10 IDs; --yes confirms irreversible deletion |
metadata._id as chunk-id and metadata.doc_id from the same chunk-list row as doc-id. This differs from add's document-level ID requirement. New content must be 10–6000 characters and within the knowledge base's maximum chunk size. content-file accepts UTF-8 plain text only, not parsed docx/pdf. Titles are 0–50 characters: an empty string clears the title, omission keeps it unchanged. Toggling include/exclude alone re-submits the existing content automatically.
Batch-deletion failures separately report completed batches, batches with unconfirmed results, and unexecuted parts. Do not treat unconfirmed results as unexecuted operations and blindly retry everything.
Categories and collections
Categories organize files by business domain. Collections define storage, using platform-managed storage by default or your own OSS bucket. Each command below accepts --workspace-id <id>.
| Command | Required flags | Optional flags and behavior |
|---|---|---|
bl knowledge category add | --name <text> | Name is 1–20 characters; --parent-id <id> creates a child category; --collection-id <id> defaults to the platform collection |
bl knowledge category list | No command-specific required flag | Exact filters --collection-id <id> and --parent-id <id>; exact --name <text> (unlike fuzzy knowledge-base name matching); --next-token <token>; --max-result <n> defaults to 20 |
bl knowledge category delete | --category-id <id> | --yes confirms irreversible deletion; behavior for categories containing files/children is server-defined, with errors passed through |
bl knowledge collection create | --name <text>, --description <text> | Creates a FILE collection; --store-type <platform|custom> defaults to platform; custom requires --oss-region <id> and --oss-bucket <name> |
bl knowledge collection get | --collection-id <id> or --name <text> | Choose one to retrieve details |
[default]. Category listing uses next-token cursor pagination. Custom buckets must be authorized and carry the bailian-connector-access=ReadAndWrite tag; otherwise creation can fail with setBucketCORS failed. There is currently no collection-delete API, so create collections deliberately.
Retrieval and Q&A service management
Services are the entry points for search/chat. Create and bind a knowledge base → verify the beta draft → deploy a published version. Each command below accepts --workspace-id <id>.
create, list, and get
| Command | Required flags | Optional flags and behavior |
|---|---|---|
bl knowledge service create | --name <text>, --scene <chat|search> | Name up to 200 characters, unique per scene in the workspace; --description <text> up to 1000 characters, recommended to explain capabilities and audience; --index-id <id> binds a base, with other settings using server defaults |
bl knowledge service list | --scene <chat|search> | --status <draft|deployed|deleted> (deployed includes edited); fuzzy --name <text>; exact --agent-id <id> and --index-id <id>; --page-number <n> defaults to 1; --page-size <n> |
bl knowledge service get | --agent-id <id> | --agent-version <version> selects beta or a published number; omission returns all versions, with valid versions determined by server state |
update: change the draft
bl knowledge service update requires --agent-id <id>.
| Optional flag | Constraint |
|---|---|
--name <text> / --description <text> | Name up to 200 characters; description up to 1000 |
--agent-version <version> | Defaults to beta; published versions accept only --version-desc |
--version-desc <text> | Version description |
--policy <turbo|agentic> | Fast or multi-turn policy |
--model <name> | Generation model code, required to be on the platform allowlist |
--temperature <n> | 0–2 |
--max-llm-calls <n> | Maximum LLM calls per request, 1–30 |
--enable-session-file <true|false> | Enable session files |
--enable-refusal <true|false> | Enable refusal answers |
--enable-anti-leak <true|false> | Enable prompt-leak prevention |
--enable-rich-text <true|false> | Enable rich-text output |
--enable-citation <true|false> | Enable citations |
--config-file <path> | JSON file replacing the whole agent_config, for nested settings such as kb_search_configs; mutually exclusive with scalar config flags |
--agent-version beta on search/chat, then deploy a new version. Updating requires knowledge-base modify permission.
deploy, copy, and delete
| Command | Required flags | Optional flags and behavior |
|---|---|---|
bl knowledge service deploy | --agent-id <id> | --version-desc <text>, --yes; publishes beta, automatically increments the version, and sets status to deployed; requires knowledge-base modify permission |
bl knowledge service copy | --agent-id <id> | Copies to a beta draft with a copy_ name prefix; requires knowledge-base create permission; verify and deploy separately |
bl knowledge service delete | --agent-id <id> | --yes; soft-delete and idempotent, so repeated deletion succeeds, but deletion cannot be undone; requires knowledge-base delete permission |
Related documentation
- Knowledge Studio CLI (kscli): the existing manual for the standalone tool.
- Service channels: other integration entry points.
- REST API overview: check REST field constraints separately from CLI flags.
- Bailian CLI Knowledge source reference and Use the CLI: the sources for Knowledge commands on this page.
- Bailian CLI installation and authentication and Configuration and tools: installation, login, profiles, workspaces, and output settings.