Skip to content

Commit

Permalink
Merge pull request #44 from justyns/index-server-only
Browse files Browse the repository at this point in the history
Disable indexing on clients, index only on server
  • Loading branch information
justyns authored Jul 15, 2024
2 parents b702669 + d545254 commit c25da29
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/embeddings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { indexObjects, queryObjects } from "$sbplugs/index/plug_api.ts";
import { renderToText } from "$sb/lib/tree.ts";
import { currentEmbeddingProvider, initIfNeeded } from "../src/init.ts";
import { log } from "./utils.ts";
import { editor } from "$sb/syscalls.ts";
import { editor, system } from "$sb/syscalls.ts";
import { aiSettings, configureSelectedModel } from "./init.ts";
import * as cache from "./cache.ts";

Expand All @@ -18,6 +18,11 @@ import * as cache from "./cache.ts";
* them.
*/
export async function indexEmbeddings({ name: page, tree }: IndexTreeEvent) {
// TODO: Can we sync indexes from server to client? Without this, each client generates its own embeddings and summaries
if (await system.getEnv() !== "server") {
return;
}

await initIfNeeded();

// Only index pages if the user enabled it, and skip anything they want to exclude
Expand All @@ -29,7 +34,8 @@ export async function indexEmbeddings({ name: page, tree }: IndexTreeEvent) {
if (
!aiSettings.indexEmbeddings ||
excludePages.includes(page) ||
page.startsWith("_")
page.startsWith("_") ||
/\.conflicted\.\d+$/.test(page)
) {
return;
}
Expand Down Expand Up @@ -94,6 +100,10 @@ export async function indexEmbeddings({ name: page, tree }: IndexTreeEvent) {
* Generate a summary for a page, and then indexes it.
*/
export async function indexSummary({ name: page, tree }: IndexTreeEvent) {
// TODO: Can we sync indexes from server to client? Without this, each client generates its own embeddings and summaries
if (await system.getEnv() !== "server") {
return;
}
await initIfNeeded();

// Only index pages if the user enabled it, and skip anything they want to exclude
Expand Down Expand Up @@ -194,6 +204,7 @@ export async function searchEmbeddings(
query: string,
numResults = 10,
): Promise<EmbeddingResult[]> {
// TODO: Is there a way to always search on the server instead of using the client's index?
await initIfNeeded();
const queryEmbedding = await currentEmbeddingProvider.generateEmbeddings({
text: query,
Expand Down

0 comments on commit c25da29

Please sign in to comment.