Skip to content

Commit 9bd8b60

Browse files
committed
refactor(knowledge-search): 移除对 query-history 功能的支持及相关代码
- 从文档中删除了 query-history 参数及示例 - 删除命令行接口中 query-history 相关 flag 定义 - 移除解析和传递 query-history 的逻辑代码 - 调整测试用例,去除对 query-history 的相关断言和测试 - 更新帮助文档,删除 query-history 相关说明和示例 - 精简接口类型定义,去除 query_history 字段
1 parent 0369bd3 commit 9bd8b60

5 files changed

Lines changed: 16 additions & 122 deletions

File tree

docs/knowledge/search-chat.md

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -77,18 +77,16 @@ bl knowledge search --query <text> --agent-id <id> [flags]
7777

7878
**参数**
7979

80-
| 参数 | 类型 | 必填 | 说明 |
81-
| --------------------------- | ------ | ---- | ----------------------------------------------------------------------------------------------------------------------------------------- |
82-
| `--query <text>` | string || 检索查询文本(不可为空) |
83-
| `--agent-id <id>` | string || 检索服务 ID(在控制台知识检索页面获取,或通过 `service list` 查看) |
84-
| `--agent-version <version>` | string || 服务版本:`beta`(调试草稿)或已发布版本号;默认调用最新已发布版本 |
85-
| `--image <url>` | array || 图片 URL(可重复),用于多模态检索 |
86-
| `--query-history <json>` | string || 用户对话历史 JSON,用于上下文理解和查询改写。格式:`[{"role":"user","content":"What is RAG"},{"role":"assistant","content":"RAG is..."}]` |
80+
| 参数 | 类型 | 必填 | 说明 |
81+
| --------------------------- | ------ | ---- | ------------------------------------------------------------------- |
82+
| `--query <text>` | string || 检索查询文本(不可为空) |
83+
| `--agent-id <id>` | string || 检索服务 ID(在控制台知识检索页面获取,或通过 `service list` 查看) |
84+
| `--agent-version <version>` | string || 服务版本:`beta`(调试草稿)或已发布版本号;默认调用最新已发布版本 |
85+
| `--image <url>` | array || 图片 URL(可重复),用于多模态检索 |
8786

8887
**参数约束**
8988

9089
- `--query` 不可为空(API 要求 `minLength: 1`
91-
- `--query-history` 必须是合法 JSON 数组
9290

9391
**输出**
9492

@@ -109,8 +107,7 @@ json 模式:返回 API 原始响应,`data.nodes[]` 包含检索结果。
109107
**注意事项**
110108

111109
- 检索范围和策略(多知识库加权、路由、rerank 等)由 `--agent-id` 对应的服务配置驱动。只需 `--query``--agent-id` 即可调用。
112-
- `--query-history` 传入前序对话轮次,服务端基于上下文改写查询以提升检索相关性。
113-
- `--agent-version beta` 调用草稿配置进行调试,部署前验证效果。
110+
- `--agent-version beta` 调试草稿配置进行调试,部署前验证效果。
114111
-`retrieve` 的区别:`search` 通过 agent_id 间接驱动检索策略(支持多知识库、路由、rerank 等),`retrieve` 直接操作 index_id 且功能较少。
115112

116113
**示例**
@@ -122,9 +119,6 @@ bl knowledge search --query "What is RAG?" --agent-id aid-xxx --workspace-id ws-
122119
# 多模态检索(带图片)
123120
bl knowledge search --query "describe this image" --agent-id aid-xxx --workspace-id ws-xxx --image https://example.com/img.jpg
124121

125-
# 带对话历史的多轮检索
126-
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"}]'
127-
128122
# 调试草稿版本
129123
bl knowledge search --query "test" --agent-id aid-xxx --agent-version beta --workspace-id ws-xxx
130124
```

packages/commands/src/commands/knowledge/search.ts

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ import {
22
defineCommand,
33
knowledgeSearchEndpoint,
44
detectOutputFormat,
5-
BailianError,
6-
ExitCode,
75
type FlagsDef,
86
type KnowledgeSearchRequest,
97
type KnowledgeSearchResponse,
@@ -39,12 +37,6 @@ const SEARCH_FLAGS = {
3937
valueHint: "<url>",
4038
description: "Image URL for multimodal retrieval (repeatable)",
4139
},
42-
queryHistory: {
43-
type: "string",
44-
valueHint: "<json>",
45-
description:
46-
'User conversation history JSON for context understanding and query rewriting. Format: \'[{"role":"user","content":"What is RAG"},{"role":"assistant","content":"RAG is..."}]\'',
47-
},
4840
} satisfies FlagsDef;
4941

5042
export default defineCommand({
@@ -56,13 +48,11 @@ export default defineCommand({
5648
"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.",
5749
"Auth: uses DashScope API Key (Bearer token). Get yours from the console API Key page.",
5850
"`--workspace-id` can be set via BAILIAN_WORKSPACE_ID env or `kscli config set workspace_id <id>`.",
59-
"`--query-history` passes prior conversation turns; the server rewrites the query based on context to improve retrieval relevance.",
6051
"`--agent-version beta` calls the draft config for debugging before it is deployed.",
6152
],
6253
exampleArgs: [
6354
'--query "What is RAG?" --agent-id aid-xxx --workspace-id ws-xxx',
6455
'--api-key $DASHSCOPE_API_KEY --query "test search" --agent-id aid-xxx --workspace-id ws-xxx --image https://example.com/img.jpg',
65-
'--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"}]\'',
6656
],
6757
async run(ctx) {
6858
const { settings, flags } = ctx;
@@ -86,21 +76,6 @@ export default defineCommand({
8676
body.images = flags.image;
8777
}
8878

89-
// Parse query_history JSON for multi-turn context
90-
if (flags.queryHistory) {
91-
try {
92-
body.query_history = JSON.parse(flags.queryHistory) as Array<{
93-
role: "user" | "assistant";
94-
content: string;
95-
}>;
96-
} catch {
97-
throw new BailianError(
98-
'--query-history must be valid JSON. Example: --query-history \'[{"role":"user","content":"What is RAG"}]\'',
99-
ExitCode.USAGE,
100-
);
101-
}
102-
}
103-
10479
const url = knowledgeSearchEndpoint(workspaceId);
10580

10681
if (settings.dryRun) {

packages/commands/tests/e2e/knowledge/knowledge-search.e2e.test.ts

Lines changed: 0 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ interface DryRunBody {
1515
agent_id?: string;
1616
agent_version?: string;
1717
images?: string[];
18-
query_history?: Array<{ role: string; content: string }>;
1918
};
2019
}
2120

@@ -31,7 +30,6 @@ describe("e2e: knowledge search", () => {
3130
expect(stderr).toMatch(/--agent-id/i);
3231
expect(stderr).toMatch(/--workspace-id/i);
3332
expect(stderr).toMatch(/--image/i);
34-
expect(stderr).toMatch(/--query-history/i);
3533
});
3634

3735
test("缺少 --query 时报用法错误并退出 (2)", async () => {
@@ -148,50 +146,6 @@ describe("e2e: knowledge search", () => {
148146
"https://example.com/b.jpg",
149147
]);
150148
});
151-
152-
test("--dry-run + --query-history 输出用户对话历史", async () => {
153-
const { stdout, stderr, exitCode } = await runCommandE2e(KNOWLEDGE_SEARCH_ROUTES, [
154-
"knowledge",
155-
"search",
156-
"--dry-run",
157-
"--query",
158-
"它怎么工作",
159-
"--agent-id",
160-
"aid_test",
161-
"--workspace-id",
162-
"ws_test",
163-
"--query-history",
164-
'[{"role":"user","content":"什么是RAG"},{"role":"assistant","content":"RAG是检索增强生成"}]',
165-
"--output",
166-
"json",
167-
]);
168-
expect(exitCode, stderr).toBe(0);
169-
const data = parseStdoutJson<DryRunBody>(stdout);
170-
expect(data.request?.query_history).toEqual([
171-
{ role: "user", content: "什么是RAG" },
172-
{ role: "assistant", content: "RAG是检索增强生成" },
173-
]);
174-
});
175-
176-
test("--dry-run + --query-history 无效 JSON 非零退出", async () => {
177-
const { stderr, exitCode } = await runCommandE2e(KNOWLEDGE_SEARCH_ROUTES, [
178-
"knowledge",
179-
"search",
180-
"--dry-run",
181-
"--query",
182-
"test",
183-
"--agent-id",
184-
"aid_test",
185-
"--workspace-id",
186-
"ws_test",
187-
"--query-history",
188-
"not-valid-json",
189-
"--output",
190-
"json",
191-
]);
192-
expect(exitCode).not.toBe(0);
193-
expect(stderr).toMatch(/query-history.*valid JSON/i);
194-
});
195149
});
196150

197151
interface SearchResponse {
@@ -259,28 +213,6 @@ describe.skipIf(!isSearchE2EReady())("e2e: knowledge search (live)", () => {
259213
expect(stdout).toMatch(/\[1\].*score/);
260214
});
261215

262-
test("search with --query-history returns results", async () => {
263-
const { stdout, stderr, exitCode } = await runCommandE2e(KNOWLEDGE_SEARCH_ROUTES, [
264-
"knowledge",
265-
"search",
266-
"--query",
267-
"它怎么工作",
268-
"--agent-id",
269-
agentId,
270-
"--workspace-id",
271-
workspaceId,
272-
"--query-history",
273-
'[{"role":"user","content":"什么是大模型"},{"role":"assistant","content":"大模型是大规模语言模型"}]',
274-
"--output",
275-
"json",
276-
]);
277-
278-
expect(exitCode, stderr).toBe(0);
279-
const data = parseStdoutJson<SearchResponse>(stdout);
280-
expect(data.code).toBe("Success");
281-
expect(data.data.nodes.length).toBeGreaterThan(0);
282-
});
283-
284216
test("search with invalid agent_id fails gracefully", async () => {
285217
const { stderr, exitCode } = await runCommandE2e(KNOWLEDGE_SEARCH_ROUTES, [
286218
"knowledge",

packages/core/src/types/api.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,6 @@ export interface KnowledgeSearchRequest {
414414
/** "beta" targets the debug draft; a numeric version targets that published version; defaults to the latest published version */
415415
agent_version?: string;
416416
images?: string[];
417-
query_history?: Array<{ role: "user" | "assistant"; content: string }>;
418417
}
419418

420419
export interface KnowledgeSearchResponse {

skills/bailian-cli/reference/knowledge.md

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -907,23 +907,21 @@ bl knowledge retrieve --index-id idx_xxx --query "RAG retrieval" --rerank --rera
907907

908908
#### Flags
909909

910-
| Flag | Type | Required | Description |
911-
| --------------------------- | ------ | -------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
912-
| `--query <text>` | string | yes | Search query text (required, cannot be empty) |
913-
| `--agent-id <id>` | string | yes | Retrieval service ID (find in console knowledge retrieval page) |
914-
| `--workspace-id <id>` | string | no | Workspace ID for API endpoint URL (or set BAILIAN_WORKSPACE_ID) |
915-
| `--agent-version <version>` | string | no | Service version to call: beta (draft for debugging) or a published number; default is the latest published version |
916-
| `--image <url>` | array | no | Image URL for multimodal retrieval (repeatable) |
917-
| `--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..."}]' |
918-
| `--api-key <key>` | string | no | API key |
919-
| `--base-url <url>` | string | no | API base URL |
910+
| Flag | Type | Required | Description |
911+
| --------------------------- | ------ | -------- | ------------------------------------------------------------------------------------------------------------------ |
912+
| `--query <text>` | string | yes | Search query text (required, cannot be empty) |
913+
| `--agent-id <id>` | string | yes | Retrieval service ID (find in console knowledge retrieval page) |
914+
| `--workspace-id <id>` | string | no | Workspace ID for API endpoint URL (or set BAILIAN_WORKSPACE_ID) |
915+
| `--agent-version <version>` | string | no | Service version to call: beta (draft for debugging) or a published number; default is the latest published version |
916+
| `--image <url>` | array | no | Image URL for multimodal retrieval (repeatable) |
917+
| `--api-key <key>` | string | no | API key |
918+
| `--base-url <url>` | string | no | API base URL |
920919

921920
#### Notes
922921

923922
- 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.
924923
- Auth: uses DashScope API Key (Bearer token). Get yours from the console API Key page.
925924
- `--workspace-id` can be set via BAILIAN_WORKSPACE_ID env or `kscli config set workspace_id <id>`.
926-
- `--query-history` passes prior conversation turns; the server rewrites the query based on context to improve retrieval relevance.
927925
- `--agent-version beta` calls the draft config for debugging before it is deployed.
928926

929927
#### Examples
@@ -936,10 +934,6 @@ bl knowledge search --query "What is RAG?" --agent-id aid-xxx --workspace-id ws-
936934
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
937935
```
938936

939-
```bash
940-
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"}]'
941-
```
942-
943937
### `bl knowledge service copy`
944938

945939
| Field | Value |

0 commit comments

Comments
 (0)