embeddingsprovider docs column
This commit is contained in:
parent
baca0805bf
commit
ada10398f7
3 changed files with 38 additions and 34 deletions
|
|
@ -94,7 +94,7 @@ class DocsContextProvider extends BaseContextProvider {
|
|||
query,
|
||||
this.options?.nRetrieve ?? DocsContextProvider.nRetrieve,
|
||||
);
|
||||
if(!chunks?.length) {
|
||||
if (!chunks?.length) {
|
||||
return [];
|
||||
}
|
||||
|
||||
|
|
@ -160,7 +160,7 @@ class DocsContextProvider extends BaseContextProvider {
|
|||
const docs = (await docsService.listMetadata()) ?? [];
|
||||
for (const { startUrl, title, favicon } of docs) {
|
||||
submenuItemsMap.set(startUrl, {
|
||||
title,\
|
||||
title,
|
||||
id: startUrl,
|
||||
description: new URL(startUrl).hostname,
|
||||
icon: favicon,
|
||||
|
|
|
|||
|
|
@ -17,7 +17,6 @@ import DocsContextProvider from "../../context/providers/DocsContextProvider";
|
|||
import TransformersJsEmbeddingsProvider from "../../llm/llms/TransformersJsEmbeddingsProvider";
|
||||
import { FromCoreProtocol, ToCoreProtocol } from "../../protocol";
|
||||
import { fetchFavicon, getFaviconBase64 } from "../../util/fetchFavicon";
|
||||
import { GlobalContext } from "../../util/GlobalContext";
|
||||
import { IMessenger } from "../../protocol/messenger";
|
||||
import {
|
||||
editConfigJson,
|
||||
|
|
@ -87,7 +86,6 @@ export default class DocsService {
|
|||
public isSyncing: boolean = false;
|
||||
|
||||
private docsIndexingQueue = new Set<string>();
|
||||
private globalContext = new GlobalContext();
|
||||
private lanceTableNamesSet = new Set<string>();
|
||||
|
||||
private config!: ContinueConfig;
|
||||
|
|
@ -144,7 +142,7 @@ export default class DocsService {
|
|||
|
||||
this.config.docs?.forEach((doc) => {
|
||||
if (!doc.startUrl) {
|
||||
console.error("Invalid config docs entry, no start");
|
||||
console.error("Invalid config docs entry, no start url", doc.title);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -396,11 +394,12 @@ export default class DocsService {
|
|||
return;
|
||||
}
|
||||
}
|
||||
this.docsIndexingQueue.add(startUrl);
|
||||
|
||||
this.addToConfig(siteIndexingConfig);
|
||||
|
||||
try {
|
||||
this.docsIndexingQueue.add(startUrl);
|
||||
|
||||
this.addToConfig(siteIndexingConfig);
|
||||
|
||||
this.handleStatusUpdate({
|
||||
...fixedStatus,
|
||||
status: "indexing",
|
||||
|
|
@ -710,16 +709,11 @@ export default class DocsService {
|
|||
await db.exec(`CREATE TABLE IF NOT EXISTS ${DocsService.sqlitebTableName} (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
title STRING NOT NULL,
|
||||
startUrl STRING NOT NULL UNIQUE,
|
||||
favicon STRING
|
||||
startUrl STRING NOT NULL,
|
||||
favicon STRING,
|
||||
embeddingsProviderId STRING
|
||||
)`);
|
||||
|
||||
// embeddingsProviderId was added later
|
||||
await db.exec(`ALTER TABLE ${DocsService.sqlitebTableName}
|
||||
ADD COLUMN IF NOT EXISTS embeddingsProviderId STRING;
|
||||
`);
|
||||
|
||||
this.sqliteDb = db;
|
||||
}
|
||||
|
||||
|
|
@ -756,6 +750,7 @@ export default class DocsService {
|
|||
const newConfigDocs = newConfig.docs || [];
|
||||
const newConfigStartUrls = newConfigDocs.map((doc) => doc.startUrl);
|
||||
|
||||
// NOTE since listMetadata filters by embeddings provider id embedding model changes are accounted for here
|
||||
const currentlyIndexedDocs = await this.listMetadata();
|
||||
const currentStartUrls = currentlyIndexedDocs.map((doc) => doc.startUrl);
|
||||
|
||||
|
|
@ -955,7 +950,7 @@ export default class DocsService {
|
|||
private addToConfig(siteIndexingConfig: SiteIndexingConfig) {
|
||||
// Handles the case where a user has manually added the doc to config.json
|
||||
// so it already exists in the file
|
||||
const doesDocExist = this.config.docs?.some(
|
||||
const doesEquivalentDocExist = this.config.docs?.some(
|
||||
(doc) =>
|
||||
doc.startUrl === siteIndexingConfig.startUrl &&
|
||||
doc.faviconUrl === siteIndexingConfig.faviconUrl &&
|
||||
|
|
@ -964,7 +959,7 @@ export default class DocsService {
|
|||
// doc.rootUrl === siteIndexingConfig.rootUrl,
|
||||
);
|
||||
|
||||
if (!doesDocExist) {
|
||||
if (!doesEquivalentDocExist) {
|
||||
editConfigJson((config) => ({
|
||||
...config,
|
||||
docs: [
|
||||
|
|
|
|||
|
|
@ -27,41 +27,50 @@ export async function runLanceMigrations(table: Table) {
|
|||
|
||||
export async function runSqliteMigrations(db: Database) {
|
||||
await new Promise((resolve) => {
|
||||
migrate(
|
||||
void migrate(
|
||||
"sqlite_modify_docs_columns_and_copy_to_config",
|
||||
async () => {
|
||||
try {
|
||||
const pragma = await db.all(
|
||||
`PRAGMA table_info(${DocsService.sqlitebTableName})`,
|
||||
`PRAGMA table_info(${DocsService.sqlitebTableName});`,
|
||||
);
|
||||
|
||||
const hasFaviconCol = pragma.some(
|
||||
(pragma) => pragma.name === "favicon",
|
||||
);
|
||||
if (!hasFaviconCol) {
|
||||
await db.exec(
|
||||
`ALTER TABLE ${DocsService.sqlitebTableName} ADD COLUMN favicon BLOB;`,
|
||||
);
|
||||
}
|
||||
|
||||
const hasBaseUrlCol = pragma.some(
|
||||
(pragma) => pragma.name === "baseUrl",
|
||||
);
|
||||
|
||||
if (!hasFaviconCol) {
|
||||
await db.exec(
|
||||
`ALTER TABLE ${DocsService.sqlitebTableName} ADD COLUMN favicon BLOB`,
|
||||
);
|
||||
}
|
||||
|
||||
if (hasBaseUrlCol) {
|
||||
await db.exec(
|
||||
`ALTER TABLE ${DocsService.sqlitebTableName} RENAME COLUMN baseUrl TO startUrl`,
|
||||
`ALTER TABLE ${DocsService.sqlitebTableName} RENAME COLUMN baseUrl TO startUrl;`,
|
||||
);
|
||||
}
|
||||
|
||||
const sqliteDocs = await db.all<
|
||||
Array<Pick<SqliteDocsRow, "title" | "startUrl">>
|
||||
>(`SELECT title, startUrl FROM ${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};`);
|
||||
}
|
||||
|
||||
editConfigJson((config) => ({
|
||||
...config,
|
||||
docs: [...(config.docs || []), ...sqliteDocs],
|
||||
}));
|
||||
const needsToUpdateConfig = !hasFaviconCol || hasBaseUrlCol;
|
||||
if (needsToUpdateConfig) {
|
||||
const sqliteDocs = await db.all<
|
||||
Array<Pick<SqliteDocsRow, "title" | "startUrl">>
|
||||
>(`SELECT title, startUrl FROM ${DocsService.sqlitebTableName}`);
|
||||
editConfigJson((config) => ({
|
||||
...config,
|
||||
docs: [...(config.docs || []), ...sqliteDocs],
|
||||
}));
|
||||
}
|
||||
} finally {
|
||||
resolve(undefined);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue