Use the kb CLI subcommands to create knowledge bases, upload documents, run hybrid searches that combine vector and full-text results, and isolate multi-tenant data with subspaces.
Prerequisites
-
Tablestore Agent Storage CLI installed and configured with access credentials (see Agent Storage CLI)
-
An OSS bucket configured with
oss_endpointandoss_bucket_name, or a managed bucket auto-created by the CLI
Manage knowledge bases
Create, view, list, and delete knowledge bases from the CLI.
Create a knowledge base
Minimal create command:
tablestore-agent-cli kb create --name my_kb --description "Product documentation knowledge base"
Enable subspaces and specify a custom embedding model:
tablestore-agent-cli kb create --name product_docs \
--description "Product documentation" \
--tags "tech,docs" \
--subspace \
--embedding-provider bailian \
--embedding-model text-embedding-v4 \
--embedding-dimension 1024
Parameters:
|
Parameter |
Required |
Default |
Description |
|
|
Yes |
— |
Knowledge base name. Letters, digits, and underscores only. Must start with a letter. 1 to 64 characters. |
|
|
No |
— |
Description. Up to 4 KB. |
|
|
No |
|
Enables subspace partitioning. After you enable it, document upload and search must specify a subspace. For details, see Subspace workflow. |
|
|
No |
— |
Tags. Comma-separated. Total size up to 4 KB. |
|
|
No |
— |
Metadata schema as a JSON string. Mutually exclusive with |
|
|
No |
— |
Path to a JSON file that contains the metadata schema. |
|
|
No |
— |
Path to a JSON file that contains the full request body. Mutually exclusive with the other parameters. |
|
|
No |
— |
Embedding service provider. Valid values: |
|
|
No |
— |
Embedding model name. For example, |
|
|
No |
— |
Vector dimension. |
|
|
No |
— |
API key for a custom embedding service. |
|
|
No |
— |
URL for a custom embedding service. The URL must be registered in Tablestore in advance. |
|
|
No |
— |
Path to a JSON file that contains the retrieval configuration. |
Metadata field types: string, long, double, boolean, date, and their list variants. Each knowledge base supports up to 200 metadata fields, and each field name has a maximum length of 128 characters.
List knowledge bases
tablestore-agent-cli kb list
tablestore-agent-cli kb list --limit 50
kb list paginates automatically and returns all knowledge bases for the current account. --limit sets the page size and does not affect the total number of results.
View a knowledge base
tablestore-agent-cli kb describe --name my_kb
The output includes basic metadata, embedding configuration, and retrieval configuration.
Delete a knowledge base
Deleting a knowledge base permanently removes all documents and vector data. This action cannot be undone.
tablestore-agent-cli kb delete --name my_kb # Prompts for confirmation in a TTY.
tablestore-agent-cli kb delete --name my_kb -y # Skips the confirmation.
Manage documents
Add, view, list, and remove documents in an existing knowledge base.
Add documents
The CLI supports three sources: local files, local directories, and existing OSS objects.
Add local files:
tablestore-agent-cli kb doc-add --kb my_kb --file ./report.pdf
tablestore-agent-cli kb doc-add --kb my_kb --file ./doc1.pdf --file ./doc2.md
Scan a local directory (recursion and glob filters supported):
Leading and trailing * wildcards are supported (for example, *.pdf).
tablestore-agent-cli kb doc-add --kb my_kb --dir ./docs
tablestore-agent-cli kb doc-add --kb my_kb --dir ./docs --include "*.pdf,*.md"
tablestore-agent-cli kb doc-add --kb my_kb --dir ./docs --exclude "*.tmp" --no-recursive
Add an existing OSS object:
tablestore-agent-cli kb doc-add --kb my_kb --oss-key oss://my-bucket/data.pdf
Specify a subspace and metadata:
tablestore-agent-cli kb doc-add --kb my_kb --file ./doc.pdf --subspace tenant_A --metadata '{"author":"Alice"}'
Parameters:
|
Parameter |
Required |
Default |
Description |
|
|
Yes |
— |
Knowledge base name. |
|
|
Yes (choose one) |
— |
Document source. Specify the parameter multiple times to upload multiple items. |
|
|
Required when subspaces are enabled |
— |
Subspace name. |
|
|
No |
— |
Metadata as a JSON string. Mutually exclusive with |
|
|
No |
— |
Path to a JSON file that contains the metadata. |
|
|
No |
— |
Glob allowlist. Comma-separated. |
|
|
No |
— |
Glob denylist. Comma-separated. |
|
|
No |
|
Recursively scans subdirectories. Use |
|
|
No |
|
Number of concurrent uploads. |
Supported file formats: PDF, DOCX, DOC, WPS, PPTX, PPT, TXT, Markdown, HTML, XLSX, XLS, PNG, JPG, BMP, and GIF.
View a document
tablestore-agent-cli kb doc-get --kb my_kb --doc-id doc-123
tablestore-agent-cli kb doc-get --kb my_kb --oss-key data.pdf
The output includes the document status (pending, completed, or failed), chunk count, and metadata.
List documents
tablestore-agent-cli kb doc-list --kb my_kb
tablestore-agent-cli kb doc-list --kb my_kb --subspace tenant_A,tenant_B
kb doc-list paginates automatically and returns all documents in the knowledge base. --subspace accepts multiple subspaces separated by commas.
Remove a document
tablestore-agent-cli kb doc-remove --kb my_kb --doc-id doc-123
tablestore-agent-cli kb doc-remove --kb my_kb --oss-key data.pdf --delete-file
--delete-file also deletes the source file in OSS. Without this flag, kb doc-remove removes only the index from the knowledge base and keeps the OSS source file.
Search documents
Run vector search, full-text search, or hybrid search against a knowledge base.
Basic search
By default, kb retrieve runs a hybrid search that combines vector and full-text signals and returns the top 20 results:
tablestore-agent-cli kb retrieve --kb my_kb --query "System architecture design"
Advanced search
These examples cover search-type control, metadata filtering, multi-subspace search, and rerank strategies. For the full parameter list, see Parameters.
Specify search type and result count:
tablestore-agent-cli kb retrieve --kb my_kb --query "SSL certificate" --search-type DENSE_VECTOR --top-k 5
Filter by metadata:
tablestore-agent-cli kb retrieve --kb my_kb --query "Deployment guide" --filter '{"author":{"equals":"Alice"}}'
Search across multiple subspaces:
tablestore-agent-cli kb retrieve --kb my_kb --query "policy" --subspace "tenant_A,tenant_B"
Specify a rerank strategy:
tablestore-agent-cli kb retrieve --kb my_kb --query "Optimization plan" --rerank-type WEIGHT --weight-dense 0.7 --weight-fulltext 0.3
Parameters
|
Parameter |
Default |
Description |
|
|
|
Search type. Valid values: |
|
|
|
Sets the result count for the dense, full-text, and rerank stages simultaneously. |
|
|
— |
Rerank strategy. Valid values: |
|
|
— |
RRF rerank parameters. |
|
|
— |
Weights for the dense and full-text results in WEIGHT rerank. |
|
|
— |
Model provider and model name for MODEL rerank. For example, |
|
|
— |
Metadata filter as a JSON string. Mutually exclusive with |
|
|
— |
Path to a JSON file that contains the metadata filter. |
|
|
— |
Subspace list. Comma-separated. |
Metadata filter operators
|
Operator |
Example |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Subspace workflow
Subspaces isolate data by tenant, business line, or scenario within a single knowledge base. Typical use cases include multi-tenant SaaS isolation, business-line archiving, and A/B testing.
To enable and use subspaces:
-
When you create the knowledge base, enable subspace partitioning with
--subspace. For details, see Create a knowledge base. -
When you upload documents, specify the target subspace with
--subspace <name>. For details, see Add documents. -
When you query the knowledge base, specify one or more subspaces to search with
--subspace "<name1>,<name2>". For details, see Advanced search.
End-to-end example:
# Create a knowledge base with subspaces enabled.
tablestore-agent-cli kb create --name multi_tenant_kb --subspace
# Specify a subspace when uploading documents.
tablestore-agent-cli kb doc-add --kb multi_tenant_kb --file ./doc.pdf --subspace tenant_A
# Specify multiple subspaces when searching.
tablestore-agent-cli kb retrieve --kb multi_tenant_kb --query "policy" --subspace "tenant_A,tenant_B"