Skip to content

Commit

Permalink
Better shouldIndexEmbeddings logic
Browse files Browse the repository at this point in the history
  • Loading branch information
justyns committed Jul 31, 2024
1 parent 3113f30 commit 9924b54
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
20 changes: 10 additions & 10 deletions src/embeddings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ ai:
\`\`\`
`;

const settingsPageSampleNoEmbeddings = `
\`\`\`yaml
ai:
indexEmbeddings: true
indexSummaries: true
\`\`\`
`;

const secretsPageSample = `
\`\`\`yaml
OPENAI_API_KEY: bar
Expand Down Expand Up @@ -113,11 +121,7 @@ Deno.test("shouldIndexSummaries returns false when indexSummary is disabled", as
});

Deno.test("shouldIndexEmbeddings returns false when no embedding models are configured", async () => {
const modifiedSettings = settingsPageSample.replace(
/embeddingModels:[\s\S]*?(?=\n\w)/,
"embeddingModels: []",
);
await syscall("mock.setPage", "SETTINGS", modifiedSettings);
await syscall("mock.setPage", "SETTINGS", settingsPageSampleNoEmbeddings);
await syscall("mock.setPage", "SECRETS", secretsPageSample);
await initializeOpenAI();
await syscall("mock.setEnv", "server");
Expand All @@ -127,11 +131,7 @@ Deno.test("shouldIndexEmbeddings returns false when no embedding models are conf
});

Deno.test("shouldIndexSummaries returns false when no embedding models are configured", async () => {
const modifiedSettings = settingsPageSample.replace(
/embeddingModels:[\s\S]*?(?=\n\w)/,
"embeddingModels: []",
);
await syscall("mock.setPage", "SETTINGS", modifiedSettings);
await syscall("mock.setPage", "SETTINGS", settingsPageSampleNoEmbeddings);
await syscall("mock.setPage", "SECRETS", secretsPageSample);
await initializeOpenAI();
await syscall("mock.setEnv", "server");
Expand Down
14 changes: 10 additions & 4 deletions src/embeddings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,20 @@ export function canIndexPage(pageName: string): boolean {

export async function shouldIndexEmbeddings() {
await initIfNeeded();
return aiSettings.indexEmbeddings && currentEmbeddingProvider &&
currentEmbeddingModel && (await system.getEnv()) === "server";
return aiSettings.indexEmbeddings &&
currentEmbeddingProvider !== undefined &&
currentEmbeddingModel !== undefined &&
aiSettings.embeddingModels.length > 0 &&
(await system.getEnv()) === "server";
}

export async function shouldIndexSummaries() {
await initIfNeeded();
return aiSettings.indexEmbeddings && aiSettings.indexSummary &&
currentEmbeddingProvider && currentEmbeddingModel &&
return aiSettings.indexEmbeddings &&
aiSettings.indexSummary &&
currentEmbeddingProvider !== undefined &&
currentEmbeddingModel !== undefined &&
aiSettings.embeddingModels.length > 0 &&
(await system.getEnv()) === "server";
}

Expand Down

0 comments on commit 9924b54

Please sign in to comment.