From c1f2f6f2bc7d8eda8e26633048e7e6b52bd24078 Mon Sep 17 00:00:00 2001 From: Nalla Prakash <81852531+prakashNalla@users.noreply.github.com> Date: Fri, 30 Oct 2026 13:59:55 +0530 Subject: [PATCH] fix(cli): search the index set in ingest.index --- .changeset/search-config-index.md | 5 +++++ packages/cli/src/main.ts | 2 +- packages/cli/tests/cli.test.ts | 17 +++++++++++++++-- 3 files changed, 21 insertions(+), 3 deletions(-) create mode 100644 .changeset/search-config-index.md diff --git a/.changeset/search-config-index.md b/.changeset/search-config-index.md new file mode 100644 index 00000000..493c826a --- /dev/null +++ b/.changeset/search-config-index.md @@ -0,0 +1,5 @@ +--- +"@chatcops/cli": patch +--- + +`chatcops search` now uses `ingest.index` from the config when `--index` isn't passed, the same index `chatcops ingest` builds. diff --git a/packages/cli/src/main.ts b/packages/cli/src/main.ts index 2d0d0781..d4da0bb7 100644 --- a/packages/cli/src/main.ts +++ b/packages/cli/src/main.ts @@ -187,7 +187,7 @@ async function runSearch(question: string, values: Values, io: Io): Promise(manifestKeys(index).meta); if (meta && meta.embedder !== embedder.id) { diff --git a/packages/cli/tests/cli.test.ts b/packages/cli/tests/cli.test.ts index 9b19f05f..5ec96991 100644 --- a/packages/cli/tests/cli.test.ts +++ b/packages/cli/tests/cli.test.ts @@ -22,7 +22,7 @@ afterAll(async () => { * the same in-memory storage (kept on globalThis), so one can build an index * and another search it. */ -function project(options: { shared: string; embedderId?: string; body?: string } = { shared: 'default' }): string { +function project(options: { shared: string; embedderId?: string; index?: string; body?: string } = { shared: 'default' }): string { const dir = mkdtempSync(join(TMP, 'project-')); const embedderId = options.embedderId ?? 'test:fake@4'; writeFileSync( @@ -42,7 +42,7 @@ export default { return texts.map((t) => Float32Array.from([1, /refund/i.test(t) ? 5 : 0, /pricing|plan/i.test(t) ? 5 : 0, 1])); }, }, - ingest: { sources: [{ type: 'urls', urls: ['${site.url}/pricing'] }] }, + ingest: { ${options.index ? `index: '${options.index}', ` : ''}sources: [{ type: 'urls', urls: ['${site.url}/pricing'] }] }, }; ` ); @@ -140,6 +140,19 @@ describe('chatcops', () => { expect(await run(['ingest'], other)).toMatchObject({ code: EXIT.unusable, stderr: expect.stringContaining('Index "default" was built with test:fake@4') }); }); + it('searches the index named in ingest.index', async () => { + const cwd = project({ shared: 'named', index: 'docs' }); + await run(['ingest'], cwd); + const json = await run(['search', 'pricing', '--json'], cwd); + expect(json.stderr).not.toContain(`hasn't been built yet`); + const result = JSON.parse(json.stdout) as { index: string; chunks: Array<{ source: { url: string } }> }; + expect(result.index).toBe('docs'); + expect(result.chunks[0].source.url).toBe(`${site.url}/pricing`); + + const other = project({ shared: 'named', index: 'docs', embedderId: 'other:model@4' }); + expect(await run(['search', 'pricing'], other)).toMatchObject({ code: EXIT.unusable, stderr: expect.stringContaining('Index "docs" was built with test:fake@4') }); + }); + it('says so when searching an index that was never built, and needs a question', async () => { const cwd = project({ shared: 'never' }); const result = await run(['search', 'anything'], cwd);