Skip to main content

Use the CLI

Search and query knowledge bases directly from the terminal with the Bailian CLI.

The Bailian CLI wraps knowledge-base search and Q&A into commands you can drive from the terminal or an Agent.
Knowledge-base CLI capabilities are currently available only to China site (aliyun.com) accounts.

Prerequisites

Use the service ID for --agent-id, not a knowledge base ID. Configure retrieval scope, result counts, and reranking in the service.

Commands

CapabilityCommandNotesCommon options
Semantic searchbl knowledge searchCalls a published retrieval service to run semantic search--query query text, --agent-id retrieval service ID
RAG Q&Abl knowledge chatCalls a published Q&A service for RAG Q&A with streaming output--message message text, --agent-id Q&A service ID

Example

Replace the service and workspace IDs before running:
bl knowledge search --query "How do I configure the chunking strategy?" --agent-id '<retrieval-service-id>' --workspace-id '<workspace-id>'
bl knowledge chat --message "How do I configure the chunking strategy?" --agent-id '<qa-service-id>' --workspace-id '<workspace-id>'
CLI 2.5.0 removed bl knowledge retrieve and kscli retrieve. Scripts that retrieved directly by knowledge base ID must switch to a retrieval service with bl knowledge search or kscli search; the old --index-id value and retrieval parameters cannot be carried over directly. Append --help to any command for full parameter details. See the RAG command reference for more commands.