Skip to content

Commit

Permalink
Merge pull request #3623 from continuedev/dallin/docs-embedding-id
Browse files Browse the repository at this point in the history
Separate Docs EmbeddingProviderId migration
  • Loading branch information
sestinj authored Jan 7, 2025
2 parents 87d1c19 + c3bd2ca commit a4bde28
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 10 deletions.
19 changes: 17 additions & 2 deletions core/indexing/docs/DocsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -743,10 +743,17 @@ export default class DocsService {
}

async getFavicon(startUrl: string) {
if (!this.config.embeddingsProvider) {
console.warn(
"Attempting to get favicon without embeddings provider specified",
);
return;
}
const db = await this.getOrCreateSqliteDb();
const result = await db.get(
`SELECT favicon FROM ${DocsService.sqlitebTableName} WHERE startUrl = ?`,
`SELECT favicon FROM ${DocsService.sqlitebTableName} WHERE startUrl = ? AND embeddingsProviderId = ?`,
startUrl,
this.config.embeddingsProvider.embeddingId,
);

if (!result) {
Expand Down Expand Up @@ -1011,10 +1018,18 @@ export default class DocsService {
}

private async deleteMetadataFromSqlite(startUrl: string) {
if (!this.config.embeddingsProvider) {
console.warn(
`Attempting to delete metadata for ${startUrl} without embeddings provider specified`,
);
return;
}
const db = await this.getOrCreateSqliteDb();

await db.run(
`DELETE FROM ${DocsService.sqlitebTableName} WHERE startUrl = ?`,
`DELETE FROM ${DocsService.sqlitebTableName} WHERE startUrl = ? AND embeddingsProviderId = ?`,
startUrl,
this.config.embeddingsProvider.embeddingId,
);
}

Expand Down
31 changes: 23 additions & 8 deletions core/indexing/docs/migrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,6 @@ export async function runSqliteMigrations(db: Database) {
);
}

const hasEmbeddingsProviderColumn = pragma.some(
(pragma) => pragma.name === "embeddingsProviderId",
);
if (!hasEmbeddingsProviderColumn) {
// gotta just delete in this case since old docs will be unusable anyway
await db.exec(`DROP TABLE ${DocsService.sqlitebTableName};`);
}

const needsToUpdateConfig = !hasFaviconCol || hasBaseUrlCol;
if (needsToUpdateConfig) {
const sqliteDocs = await db.all<
Expand All @@ -78,4 +70,27 @@ export async function runSqliteMigrations(db: Database) {
() => resolve(undefined),
);
});

await new Promise((resolve) => {
void migrate(
"sqlite_delete_docs_with_no_embeddingsProviderId",
async () => {
try {
const pragma = await db.all(
`PRAGMA table_info(${DocsService.sqlitebTableName});`,
);
const hasEmbeddingsProviderColumn = pragma.some(
(pragma) => pragma.name === "embeddingsProviderId",
);
if (!hasEmbeddingsProviderColumn) {
// gotta just delete in this case since old docs will be unusable anyway
await db.exec(`DROP TABLE ${DocsService.sqlitebTableName};`);
}
} finally {
resolve(undefined);
}
},
() => resolve(undefined),
);
});
}

0 comments on commit a4bde28

Please sign in to comment.