indexing manager p2

This commit is contained in:
Dallin Romney 2024-11-17 02:25:32 -08:00
parent af4e5ee440
commit 34627a94d4
8 changed files with 85 additions and 73 deletions

View file

@ -110,12 +110,15 @@ export class Core {
this.controlPlaneClient,
);
this.indexingManager = new IndexingStatusManager(this.messenger);
this.indexingManager = IndexingStatusManager.createSingleton(
this.messenger,
);
this.docsService = DocsService.createSingleton(
this.configHandler,
this.ide,
this.messenger,
this.indexingManager,
);
this.configHandler.onConfigUpdate(
@ -714,13 +717,13 @@ export class Core {
});
on("indexing/reindex", async (msg) => {
this.indexingManager.reindex(msg.data.id);
this.indexingManager.reindex(msg.data.identifier);
});
on("indexing/abort", async (msg) => {
this.indexingManager.abort(msg.data.id);
this.indexingManager.abort(msg.data.identifier);
});
on("indexing/setPaused", async (msg) => {
this.indexingManager.setPaused(msg.data.id, msg.data.pause);
this.indexingManager.setPaused(msg.data.identifier, msg.data.pause);
});
on("indexing/getStatuses", async (msg) => {
return this.indexingManager.statuses;

5
core/index.d.ts vendored
View file

@ -57,6 +57,11 @@ export interface IndexingStatusUpdate {
debugInfo?: string;
}
interface IndexIdentifier {
type: string;
id: string;
}
export type IndexingStatusMap = Map<
string,
Map<IndexingStatusUpdate["id"], IndexingStatusUpdate>

View file

@ -1,4 +1,4 @@
import { IndexingStatusMap, IndexingStatusUpdate } from "..";
import { IndexIdentifier, IndexingStatusMap, IndexingStatusUpdate } from "..";
import { FromCoreProtocol, ToCoreProtocol } from "../protocol";
import { IMessenger } from "../util/messenger";
@ -7,7 +7,8 @@ import { IMessenger } from "../util/messenger";
1. Pass indexingManager to the service
2. Register the service with the manager using `registerService`
E.g. docs uses startUrl as id
3.
3. Rules of engagement:
- service is responsible for checking corrupted indexes - don't check paused or deleted
*/
export class IndexingStatusManager {
private readonly messenger: IMessenger<ToCoreProtocol, FromCoreProtocol>;
@ -21,26 +22,29 @@ export class IndexingStatusManager {
this.messenger = messenger;
}
private static instance?: IndexingStatusManager;
static createSingleton(
messenger: IMessenger<ToCoreProtocol, FromCoreProtocol>,
) {
const instance = new IndexingStatusManager(messenger);
IndexingStatusManager.instance = instance;
return instance;
}
static getSingleton() {
return IndexingStatusManager.instance;
}
// Services that use an instance of this class should add their reindex functions here
registerService(type: string, fn: (id: string) => Promise<void>) {
this.reindexTypeFunctions.set(type, fn);
this.statuses.set(type, new Map());
}
reindex(type: string, id: string) {
const byType = this.statuses.get(type);
reindex({ type, id }: IndexIdentifier) {
const reindexFn = this.reindexTypeFunctions.get(type);
if (byType && reindexFn) {
const status = byType.get(id);
if (status) {
if (status.status === "deleted") {
throw new Error(
"Cannot reindex a deleted item, shouldn't ever happen",
);
}
void reindexFn(id);
}
if (reindexFn) {
void reindexFn(id);
}
}
@ -52,53 +56,38 @@ export class IndexingStatusManager {
}
}
delete(type: string, id: string) {
const byType = this.statuses.get(type);
if (byType) {
const status = byType.get(id);
if (status) {
this.handleUpdate({ ...status, status: "deleted" });
}
delete({ type, id }: IndexIdentifier) {
const status = this.statuses.get(type)?.get(id);
if (status) {
this.handleUpdate({ ...status, status: "deleted" });
}
}
abort(type: string, id: string) {
const byType = this.statuses.get(type);
if (byType) {
const status = byType.get(id);
if (status) {
this.handleUpdate({ ...status, status: "aborted" });
}
abort({ type, id }: IndexIdentifier) {
const status = this.statuses.get(type)?.get(id);
if (status) {
this.handleUpdate({ ...status, status: "aborted" });
}
}
isAborted(type: string, id: string) {
const byType = this.statuses.get(type);
if (byType) {
const status = byType.get(id);
if (status) {
return status.status === "aborted";
}
isAborted({ type, id }: IndexIdentifier) {
const status = this.statuses.get(type)?.get(id);
if (status) {
return status.status === "aborted";
}
}
setPaused(type: string, id: string, pause: boolean) {
const byType = this.statuses.get(type);
if (byType) {
const status = byType.get(id);
if (status) {
this.handleUpdate({ ...status, status: pause ? "paused" : "indexing" });
}
setPaused({ type, id }: IndexIdentifier, pause: boolean) {
const status = this.statuses.get(type)?.get(id);
if (status) {
this.handleUpdate({ ...status, status: pause ? "paused" : "indexing" });
}
}
isPaused(type: string, id: string) {
const byType = this.statuses.get(type);
if (byType) {
const status = byType.get(id);
if (status) {
return status.status === "paused";
}
isPaused({ type, id }: IndexIdentifier) {
const status = this.statuses.get(type)?.get(id);
if (status) {
return status.status === "paused";
}
}
}

View file

@ -111,8 +111,14 @@ export default class DocsService {
configHandler: ConfigHandler,
ide: IDE,
messenger?: IMessenger<ToCoreProtocol, FromCoreProtocol>,
indexingManager?: IndexingStatusManager,
) {
const docsService = new DocsService(configHandler, ide, messenger);
const docsService = new DocsService(
configHandler,
ide,
messenger,
indexingManager,
);
DocsService.instance = docsService;
return docsService;
}
@ -127,9 +133,9 @@ export default class DocsService {
DocsService.indexingType,
this.reindexDoc,
);
this.config = await configHandler.loadConfig();
await this.handleConfigUpdate({ config: this.config });
configHandler.onConfigUpdate(this.handleConfigUpdate);
const config = await configHandler.loadConfig();
await this.handleConfigUpdate({ config });
configHandler.onConfigUpdate(this.handleConfigUpdate.bind(this));
}
// Config
@ -502,7 +508,7 @@ export default class DocsService {
const [vector] = await embeddingsProvider.embed([query]);
return await this.retrieveChunks(query, vector, nRetrieve);
return await this.retrieveChunks(startUrl, vector, nRetrieve);
}
async retrieveChunks(
@ -525,7 +531,7 @@ export default class DocsService {
.where(`starturl = '${startUrl}'`)
.execute();
} catch (e: any) {
console.error("Error retrieving chunks from LanceDB", e);
console.warn("Error retrieving chunks from LanceDB", e);
}
const hasIndexedDoc = await this.hasMetadata(startUrl);
@ -597,14 +603,14 @@ export default class DocsService {
Ignores pre-indexed docs
*/
private async syncDocsOnConfigUpdate(
oldConfig: ContinueConfig,
oldConfig: ContinueConfig | undefined,
newConfig: ContinueConfig,
) {
try {
this.isSyncing = true;
// Otherwise sync the index based on config changes
const oldConfigDocs = oldConfig.docs || [];
const oldConfigDocs = oldConfig?.docs || [];
const newConfigDocs = newConfig.docs || [];
const newConfigStartUrls = newConfigDocs.map((doc) => doc.startUrl);
@ -664,7 +670,7 @@ export default class DocsService {
await this.delete(doc.startUrl);
}
} catch (e) {
console.error("Error syncing config and sqlite", e);
console.error("Error syncing docs index on config update", e);
} finally {
this.isSyncing = false;
}

View file

@ -8,6 +8,7 @@ import type {
ContextSubmenuItem,
DiffLine,
IdeSettings,
IndexIdentifier,
IndexingStatusMap,
LLMFullCompletionOptions,
MessageContent,
@ -159,13 +160,11 @@ export type ToCoreFromIdeOrWebviewProtocol = {
];
// Docs Indexing. TODO move codebase to this
"indexing/reindex": [
{ id: string; shouldClearAllOfIndexType?: boolean },
void,
];
"indexing/abort": [{ id: string }, void];
"indexing/setPaused": [{ id: string; pause: boolean }, void];
"indexing/reindex": [{ identifier: IndexIdentifier }, void];
"indexing/abort": [{ identifier: IndexIdentifier }, void];
"indexing/setPaused": [{ identifier: IndexIdentifier; pause: boolean }, void];
"indexing/getStatuses": [undefined, IndexingStatusMap];
addAutocompleteModel: [{ model: ModelDescription }, void];
"profiles/switch": [{ id: string }, undefined];

View file

@ -10,8 +10,8 @@ export type ToWebviewFromIdeOrCoreProtocol = {
configUpdate: [undefined, void];
configError: [ConfigValidationError[] | undefined, void];
getDefaultModelTitle: [undefined, string];
indexProgress: [IndexingProgressUpdate, void];
"indexing/statusUpdate": [IndexingStatusUpdate, void];
indexProgress: [IndexingProgressUpdate, void]; // Codebase
"indexing/statusUpdate": [IndexingStatusUpdate, void]; // Docs, etc.
refreshSubmenuItems: [undefined, void];
isContinueInputFocused: [undefined, boolean];
addContextItem: [

View file

@ -1,12 +1,12 @@
{
"name": "continue",
"version": "0.9.229",
"version": "0.9.230",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "continue",
"version": "0.9.229",
"version": "0.9.230",
"license": "Apache-2.0",
"dependencies": {
"@electron/rebuild": "^3.2.10",

View file

@ -135,6 +135,16 @@ function useSetup(dispatch: Dispatch<any>) {
);
});
useWebviewListener("indexing/statusUpdate", async (data) => {
console.log("Indexing status update", data);
// dispatch(
// addContextItemsAtIndex({
// index: data.historyIndex,
// contextItems: [data.item],
// }),
// );
});
useWebviewListener(
"getDefaultModelTitle",
async () => {