feat: CLI 添加 --incremental/--force/--mode 选项

This commit is contained in:
2026-07-11 19:45:50 +08:00
parent 82924ff5f3
commit ba814c7a70
+7 -2
View File
@@ -63,6 +63,8 @@ def ingest(
typer.Argument(help="Markdown 文件路径 (可多个, 或 - 从标准输入读取)"), typer.Argument(help="Markdown 文件路径 (可多个, 或 - 从标准输入读取)"),
] = None, ] = None,
name: Annotated[str | None, typer.Option("--name", help="标准输入模式下的虚拟文件名")] = None, name: Annotated[str | None, typer.Option("--name", help="标准输入模式下的虚拟文件名")] = None,
incremental: Annotated[bool, typer.Option("--incremental", help="增量模式:跳过未变更文件")] = False,
force: Annotated[bool, typer.Option("--force", help="强制重新入库(忽略增量检查)")] = False,
config: ConfigOpt = DEFAULT_CONFIG_PATH, config: ConfigOpt = DEFAULT_CONFIG_PATH,
collection: CollectionOpt = None, collection: CollectionOpt = None,
): ):
@@ -93,11 +95,11 @@ def ingest(
if not is_safe_cli_path(m): if not is_safe_cli_path(m):
typer.echo(f"[SKIP] 不安全的路径: {m}", err=True) typer.echo(f"[SKIP] 不安全的路径: {m}", err=True)
continue continue
c = ingestor.ingest_file(m) c = ingestor.ingest_file(m, incremental=incremental, force=force)
typer.echo(f" {m}: {c} chunks") typer.echo(f" {m}: {c} chunks")
total += c total += c
elif p.is_file(): elif p.is_file():
c = ingestor.ingest_file(fp) c = ingestor.ingest_file(fp, incremental=incremental, force=force)
typer.echo(f" {fp}: {c} chunks") typer.echo(f" {fp}: {c} chunks")
total += c total += c
else: else:
@@ -137,12 +139,15 @@ def search(
query: Annotated[str, typer.Argument(help="搜索关键词或自然语言查询")], query: Annotated[str, typer.Argument(help="搜索关键词或自然语言查询")],
top_k: Annotated[int, typer.Option("--top-k", "-k", help="返回结果数量 (1-100)")] = 10, top_k: Annotated[int, typer.Option("--top-k", "-k", help="返回结果数量 (1-100)")] = 10,
json_output: Annotated[bool, typer.Option("--json", help="以 JSON 格式输出")] = False, json_output: Annotated[bool, typer.Option("--json", help="以 JSON 格式输出")] = False,
mode: Annotated[str, typer.Option("--mode", help="检索模式: hybrid | vector")] = "",
config: ConfigOpt = DEFAULT_CONFIG_PATH, config: ConfigOpt = DEFAULT_CONFIG_PATH,
collection: CollectionOpt = None, collection: CollectionOpt = None,
): ):
_init_config(config) _init_config(config)
state = get_state() state = get_state()
searcher = state.get_searcher(_resolve_collection(collection)) searcher = state.get_searcher(_resolve_collection(collection))
if mode:
searcher._search_config.mode = mode
results = searcher.search(query, top_k=top_k) results = searcher.search(query, top_k=top_k)
if json_output: if json_output: