mirror of
https://github.com/modelstudioai/cli.git
synced 2026-09-14 19:49:23 +08:00
refactor(knowledge-search): 移除对 query-history 功能的支持及相关代码
- 从文档中删除了 query-history 参数及示例 - 删除命令行接口中 query-history 相关 flag 定义 - 移除解析和传递 query-history 的逻辑代码 - 调整测试用例,去除对 query-history 的相关断言和测试 - 更新帮助文档,删除 query-history 相关说明和示例 - 精简接口类型定义,去除 query_history 字段
This commit is contained in:
@@ -77,18 +77,16 @@ bl knowledge search --query <text> --agent-id <id> [flags]
|
||||
|
||||
**参数**
|
||||
|
||||
| 参数 | 类型 | 必填 | 说明 |
|
||||
| --------------------------- | ------ | ---- | ----------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| `--query <text>` | string | 是 | 检索查询文本(不可为空) |
|
||||
| `--agent-id <id>` | string | 是 | 检索服务 ID(在控制台知识检索页面获取,或通过 `service list` 查看) |
|
||||
| `--agent-version <version>` | string | 否 | 服务版本:`beta`(调试草稿)或已发布版本号;默认调用最新已发布版本 |
|
||||
| `--image <url>` | array | 否 | 图片 URL(可重复),用于多模态检索 |
|
||||
| `--query-history <json>` | string | 否 | 用户对话历史 JSON,用于上下文理解和查询改写。格式:`[{"role":"user","content":"What is RAG"},{"role":"assistant","content":"RAG is..."}]` |
|
||||
| 参数 | 类型 | 必填 | 说明 |
|
||||
| --------------------------- | ------ | ---- | ------------------------------------------------------------------- |
|
||||
| `--query <text>` | string | 是 | 检索查询文本(不可为空) |
|
||||
| `--agent-id <id>` | string | 是 | 检索服务 ID(在控制台知识检索页面获取,或通过 `service list` 查看) |
|
||||
| `--agent-version <version>` | string | 否 | 服务版本:`beta`(调试草稿)或已发布版本号;默认调用最新已发布版本 |
|
||||
| `--image <url>` | array | 否 | 图片 URL(可重复),用于多模态检索 |
|
||||
|
||||
**参数约束**
|
||||
|
||||
- `--query` 不可为空(API 要求 `minLength: 1`)
|
||||
- `--query-history` 必须是合法 JSON 数组
|
||||
|
||||
**输出**
|
||||
|
||||
@@ -109,8 +107,7 @@ json 模式:返回 API 原始响应,`data.nodes[]` 包含检索结果。
|
||||
**注意事项**
|
||||
|
||||
- 检索范围和策略(多知识库加权、路由、rerank 等)由 `--agent-id` 对应的服务配置驱动。只需 `--query` 和 `--agent-id` 即可调用。
|
||||
- `--query-history` 传入前序对话轮次,服务端基于上下文改写查询以提升检索相关性。
|
||||
- `--agent-version beta` 调用草稿配置进行调试,部署前验证效果。
|
||||
- `--agent-version beta` 调试草稿配置进行调试,部署前验证效果。
|
||||
- 与 `retrieve` 的区别:`search` 通过 agent_id 间接驱动检索策略(支持多知识库、路由、rerank 等),`retrieve` 直接操作 index_id 且功能较少。
|
||||
|
||||
**示例**
|
||||
@@ -122,9 +119,6 @@ bl knowledge search --query "What is RAG?" --agent-id aid-xxx --workspace-id ws-
|
||||
# 多模态检索(带图片)
|
||||
bl knowledge search --query "describe this image" --agent-id aid-xxx --workspace-id ws-xxx --image https://example.com/img.jpg
|
||||
|
||||
# 带对话历史的多轮检索
|
||||
bl knowledge search --query "How does it work" --agent-id aid-xxx --workspace-id ws-xxx --query-history '[{"role":"user","content":"What is RAG"},{"role":"assistant","content":"RAG is retrieval-augmented generation"}]'
|
||||
|
||||
# 调试草稿版本
|
||||
bl knowledge search --query "test" --agent-id aid-xxx --agent-version beta --workspace-id ws-xxx
|
||||
```
|
||||
|
||||
@@ -2,8 +2,6 @@ import {
|
||||
defineCommand,
|
||||
knowledgeSearchEndpoint,
|
||||
detectOutputFormat,
|
||||
BailianError,
|
||||
ExitCode,
|
||||
type FlagsDef,
|
||||
type KnowledgeSearchRequest,
|
||||
type KnowledgeSearchResponse,
|
||||
@@ -39,12 +37,6 @@ const SEARCH_FLAGS = {
|
||||
valueHint: "<url>",
|
||||
description: "Image URL for multimodal retrieval (repeatable)",
|
||||
},
|
||||
queryHistory: {
|
||||
type: "string",
|
||||
valueHint: "<json>",
|
||||
description:
|
||||
'User conversation history JSON for context understanding and query rewriting. Format: \'[{"role":"user","content":"What is RAG"},{"role":"assistant","content":"RAG is..."}]\'',
|
||||
},
|
||||
} satisfies FlagsDef;
|
||||
|
||||
export default defineCommand({
|
||||
@@ -56,13 +48,11 @@ export default defineCommand({
|
||||
"Retrieval scope and strategy (multi-index weighting, routing, reranking, etc.) are driven by the agent_id service config. Only query and agent_id are required.",
|
||||
"Auth: uses DashScope API Key (Bearer token). Get yours from the console API Key page.",
|
||||
"`--workspace-id` can be set via BAILIAN_WORKSPACE_ID env or `kscli config set workspace_id <id>`.",
|
||||
"`--query-history` passes prior conversation turns; the server rewrites the query based on context to improve retrieval relevance.",
|
||||
"`--agent-version beta` calls the draft config for debugging before it is deployed.",
|
||||
],
|
||||
exampleArgs: [
|
||||
'--query "What is RAG?" --agent-id aid-xxx --workspace-id ws-xxx',
|
||||
'--api-key $DASHSCOPE_API_KEY --query "test search" --agent-id aid-xxx --workspace-id ws-xxx --image https://example.com/img.jpg',
|
||||
'--query "How does it work" --agent-id aid-xxx --workspace-id ws-xxx --query-history \'[{"role":"user","content":"What is RAG"},{"role":"assistant","content":"RAG is retrieval-augmented generation"}]\'',
|
||||
],
|
||||
async run(ctx) {
|
||||
const { settings, flags } = ctx;
|
||||
@@ -86,21 +76,6 @@ export default defineCommand({
|
||||
body.images = flags.image;
|
||||
}
|
||||
|
||||
// Parse query_history JSON for multi-turn context
|
||||
if (flags.queryHistory) {
|
||||
try {
|
||||
body.query_history = JSON.parse(flags.queryHistory) as Array<{
|
||||
role: "user" | "assistant";
|
||||
content: string;
|
||||
}>;
|
||||
} catch {
|
||||
throw new BailianError(
|
||||
'--query-history must be valid JSON. Example: --query-history \'[{"role":"user","content":"What is RAG"}]\'',
|
||||
ExitCode.USAGE,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
const url = knowledgeSearchEndpoint(workspaceId);
|
||||
|
||||
if (settings.dryRun) {
|
||||
|
||||
@@ -15,7 +15,6 @@ interface DryRunBody {
|
||||
agent_id?: string;
|
||||
agent_version?: string;
|
||||
images?: string[];
|
||||
query_history?: Array<{ role: string; content: string }>;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -31,7 +30,6 @@ describe("e2e: knowledge search", () => {
|
||||
expect(stderr).toMatch(/--agent-id/i);
|
||||
expect(stderr).toMatch(/--workspace-id/i);
|
||||
expect(stderr).toMatch(/--image/i);
|
||||
expect(stderr).toMatch(/--query-history/i);
|
||||
});
|
||||
|
||||
test("缺少 --query 时报用法错误并退出 (2)", async () => {
|
||||
@@ -148,50 +146,6 @@ describe("e2e: knowledge search", () => {
|
||||
"https://example.com/b.jpg",
|
||||
]);
|
||||
});
|
||||
|
||||
test("--dry-run + --query-history 输出用户对话历史", async () => {
|
||||
const { stdout, stderr, exitCode } = await runCommandE2e(KNOWLEDGE_SEARCH_ROUTES, [
|
||||
"knowledge",
|
||||
"search",
|
||||
"--dry-run",
|
||||
"--query",
|
||||
"它怎么工作",
|
||||
"--agent-id",
|
||||
"aid_test",
|
||||
"--workspace-id",
|
||||
"ws_test",
|
||||
"--query-history",
|
||||
'[{"role":"user","content":"什么是RAG"},{"role":"assistant","content":"RAG是检索增强生成"}]',
|
||||
"--output",
|
||||
"json",
|
||||
]);
|
||||
expect(exitCode, stderr).toBe(0);
|
||||
const data = parseStdoutJson<DryRunBody>(stdout);
|
||||
expect(data.request?.query_history).toEqual([
|
||||
{ role: "user", content: "什么是RAG" },
|
||||
{ role: "assistant", content: "RAG是检索增强生成" },
|
||||
]);
|
||||
});
|
||||
|
||||
test("--dry-run + --query-history 无效 JSON 非零退出", async () => {
|
||||
const { stderr, exitCode } = await runCommandE2e(KNOWLEDGE_SEARCH_ROUTES, [
|
||||
"knowledge",
|
||||
"search",
|
||||
"--dry-run",
|
||||
"--query",
|
||||
"test",
|
||||
"--agent-id",
|
||||
"aid_test",
|
||||
"--workspace-id",
|
||||
"ws_test",
|
||||
"--query-history",
|
||||
"not-valid-json",
|
||||
"--output",
|
||||
"json",
|
||||
]);
|
||||
expect(exitCode).not.toBe(0);
|
||||
expect(stderr).toMatch(/query-history.*valid JSON/i);
|
||||
});
|
||||
});
|
||||
|
||||
interface SearchResponse {
|
||||
@@ -259,28 +213,6 @@ describe.skipIf(!isSearchE2EReady())("e2e: knowledge search (live)", () => {
|
||||
expect(stdout).toMatch(/\[1\].*score/);
|
||||
});
|
||||
|
||||
test("search with --query-history returns results", async () => {
|
||||
const { stdout, stderr, exitCode } = await runCommandE2e(KNOWLEDGE_SEARCH_ROUTES, [
|
||||
"knowledge",
|
||||
"search",
|
||||
"--query",
|
||||
"它怎么工作",
|
||||
"--agent-id",
|
||||
agentId,
|
||||
"--workspace-id",
|
||||
workspaceId,
|
||||
"--query-history",
|
||||
'[{"role":"user","content":"什么是大模型"},{"role":"assistant","content":"大模型是大规模语言模型"}]',
|
||||
"--output",
|
||||
"json",
|
||||
]);
|
||||
|
||||
expect(exitCode, stderr).toBe(0);
|
||||
const data = parseStdoutJson<SearchResponse>(stdout);
|
||||
expect(data.code).toBe("Success");
|
||||
expect(data.data.nodes.length).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
test("search with invalid agent_id fails gracefully", async () => {
|
||||
const { stderr, exitCode } = await runCommandE2e(KNOWLEDGE_SEARCH_ROUTES, [
|
||||
"knowledge",
|
||||
|
||||
@@ -414,7 +414,6 @@ export interface KnowledgeSearchRequest {
|
||||
/** "beta" targets the debug draft; a numeric version targets that published version; defaults to the latest published version */
|
||||
agent_version?: string;
|
||||
images?: string[];
|
||||
query_history?: Array<{ role: "user" | "assistant"; content: string }>;
|
||||
}
|
||||
|
||||
export interface KnowledgeSearchResponse {
|
||||
|
||||
@@ -907,23 +907,21 @@ bl knowledge retrieve --index-id idx_xxx --query "RAG retrieval" --rerank --rera
|
||||
|
||||
#### Flags
|
||||
|
||||
| Flag | Type | Required | Description |
|
||||
| --------------------------- | ------ | -------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| `--query <text>` | string | yes | Search query text (required, cannot be empty) |
|
||||
| `--agent-id <id>` | string | yes | Retrieval service ID (find in console knowledge retrieval page) |
|
||||
| `--workspace-id <id>` | string | no | Workspace ID for API endpoint URL (or set BAILIAN_WORKSPACE_ID) |
|
||||
| `--agent-version <version>` | string | no | Service version to call: beta (draft for debugging) or a published number; default is the latest published version |
|
||||
| `--image <url>` | array | no | Image URL for multimodal retrieval (repeatable) |
|
||||
| `--query-history <json>` | string | no | User conversation history JSON for context understanding and query rewriting. Format: '[{"role":"user","content":"What is RAG"},{"role":"assistant","content":"RAG is..."}]' |
|
||||
| `--api-key <key>` | string | no | API key |
|
||||
| `--base-url <url>` | string | no | API base URL |
|
||||
| Flag | Type | Required | Description |
|
||||
| --------------------------- | ------ | -------- | ------------------------------------------------------------------------------------------------------------------ |
|
||||
| `--query <text>` | string | yes | Search query text (required, cannot be empty) |
|
||||
| `--agent-id <id>` | string | yes | Retrieval service ID (find in console knowledge retrieval page) |
|
||||
| `--workspace-id <id>` | string | no | Workspace ID for API endpoint URL (or set BAILIAN_WORKSPACE_ID) |
|
||||
| `--agent-version <version>` | string | no | Service version to call: beta (draft for debugging) or a published number; default is the latest published version |
|
||||
| `--image <url>` | array | no | Image URL for multimodal retrieval (repeatable) |
|
||||
| `--api-key <key>` | string | no | API key |
|
||||
| `--base-url <url>` | string | no | API base URL |
|
||||
|
||||
#### Notes
|
||||
|
||||
- Retrieval scope and strategy (multi-index weighting, routing, reranking, etc.) are driven by the agent_id service config. Only query and agent_id are required.
|
||||
- Auth: uses DashScope API Key (Bearer token). Get yours from the console API Key page.
|
||||
- `--workspace-id` can be set via BAILIAN_WORKSPACE_ID env or `kscli config set workspace_id <id>`.
|
||||
- `--query-history` passes prior conversation turns; the server rewrites the query based on context to improve retrieval relevance.
|
||||
- `--agent-version beta` calls the draft config for debugging before it is deployed.
|
||||
|
||||
#### Examples
|
||||
@@ -936,10 +934,6 @@ bl knowledge search --query "What is RAG?" --agent-id aid-xxx --workspace-id ws-
|
||||
bl knowledge search --api-key $DASHSCOPE_API_KEY --query "test search" --agent-id aid-xxx --workspace-id ws-xxx --image https://example.com/img.jpg
|
||||
```
|
||||
|
||||
```bash
|
||||
bl knowledge search --query "How does it work" --agent-id aid-xxx --workspace-id ws-xxx --query-history '[{"role":"user","content":"What is RAG"},{"role":"assistant","content":"RAG is retrieval-augmented generation"}]'
|
||||
```
|
||||
|
||||
### `bl knowledge service copy`
|
||||
|
||||
| Field | Value |
|
||||
|
||||
Reference in New Issue
Block a user