Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/search-config-index.md
Original file line number Diff line number Diff line change
@@ -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.
2 changes: 1 addition & 1 deletion packages/cli/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ async function runSearch(question: string, values: Values, io: Io): Promise<numb
const topK = wholeNumber(values['top-k'], '--top-k') ?? 5;
const loaded = await loadConfig(io.cwd, values.config);
try {
const index = values.index ?? 'default';
const index = values.index ?? loaded.config.ingest?.index ?? 'default';
const { embedder, store, manifest } = indexConfig(loaded);
const meta = await manifest.get<{ embedder: string }>(manifestKeys(index).meta);
if (meta && meta.embedder !== embedder.id) {
Expand Down
17 changes: 15 additions & 2 deletions packages/cli/tests/cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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'] }] },
};
`
);
Expand Down Expand Up @@ -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);
Expand Down
Loading