Elffuss BraidHub

kikocis/continue public

chore: remove docs cache (#7108)

* chore: remove docs cache

* Update DocsService.ts
Changeset4e3281ed77e4f5d05487948cadd4386c3f7ebcd362cb1cf0e456c43bf3774311
AuthorPatrick Erichsen <patrick.a.erichsen@gmail.com> · 2025-08-15 14:03 -07:00
CommitterGitHub <noreply@github.com> · 2025-08-15 14:03 -07:00
Parentsaae379894b54

Browse the files at this changeset

3 files changed

deleted core/indexing/docs/DocsCache.test.ts +0 −25
@@ -1,25 +0,0 @@
1-import OpenAI from "../../llm/llms/OpenAI";
2-import { DocsCache } from "./DocsCache"; // adjust import path as needed
3-
4-describe("DocsCache", () => {
5- let openAIEmbeddings: OpenAI;
6-
7- beforeAll(() => {
8- openAIEmbeddings = new OpenAI({
9- apiKey: "",
10- model: "text-embedding-ada-002",
11- });
12- });
13-
14- test("normalizeEmbeddingId() produces a valid ID without constructor name", async () => {
15- // Get the embedding ID from OpenAI embeddings provider
16- const embeddingId = DocsCache.normalizeEmbeddingId(
17- openAIEmbeddings.embeddingId,
18- );
19-
20- // The ID should not contain the constructor name (OpenAI)
21- expect(embeddingId).toEqual(
22- `${openAIEmbeddings.model}::${openAIEmbeddings.maxEmbeddingChunkSize}`,
23- );
24- });
25-});
deleted core/indexing/docs/DocsCache.ts +0 −93
@@ -1,93 +0,0 @@
1-import request from "request";
2-import { Chunk } from "../..";
3-
4-export interface SiteIndexingResults {
5- chunks: (Chunk & { embedding: number[] })[];
6- url: string;
7- title: string;
8-}
9-
10-/**
11- * Strip off the trailing forward slash from the given URL
12- * @param url The URL of the document
13- * @returns A sanitized URL without trailing forward slash
14- */
15-const stripTrailingSlash = (url: string): string => {
16- return url.replace(/\/+$/, "");
17-};
18-
19-export class DocsCache {
20- static readonly AWS_REGION: string = "us-west-1";
21- static readonly BUCKET_NAME: string = "continue-preindexed-docs";
22-
23- /**
24- * Normalizes an embedding ID by stripping the constructor name part.
25- * This is done because we don't care about the provider, just the
26- * model and the max embedding chunk size.
27- */
28- static normalizeEmbeddingId(embeddingId: string): string {
29- // Split by "::" and remove the first part (constructor name)
30- const parts = embeddingId.split("::");
31- if (parts.length <= 1) return embeddingId; // Return original if no "::" found
32-
33- // Return everything except the first part, joining with "::"
34- return parts.slice(1).join("::");
35- }
36-
37- /**
38- * Gets the filepath for a given embedding ID and URL
39- */
40- static getFilepathForEmbeddingIdAndUrl(
41- embeddingId: string,
42- url: string,
43- ): string {
44- const normalizedEmbeddingId = DocsCache.normalizeEmbeddingId(embeddingId);
45- const sanitizedUrl = stripTrailingSlash(url);
46- const normalizedUrl = encodeURIComponent(sanitizedUrl.replace(/\//g, "_"));
47- return normalizedEmbeddingId + "/" + normalizedUrl;
48- }
49-
50- /**
51- * Gets the fully qualified S3 URL for a given filepath
52- */
53- private static getS3Url(filepath: string): string {
54- const pathname = filepath.split("/").map(encodeURIComponent).join("/");
55- return `https://${this.BUCKET_NAME}.s3.${this.AWS_REGION}.amazonaws.com/${pathname}`;
56- }
57-
58- /**
59- * Downloads cached site indexing results from S3 for a given embedding ID and URL
60- * @param embeddingId The embedding ID
61- * @param url The URL of the document
62- * @returns The downloaded data as a string
63- */
64- static async getDocsCacheForUrl(
65- embeddingId: string,
66- url: string,
67- ): Promise<string> {
68- const filepath = DocsCache.getFilepathForEmbeddingIdAndUrl(
69- embeddingId,
70- url,
71- );
72-
73- return new Promise<string>((resolve, reject) => {
74- let data = "";
75- const url = this.getS3Url(filepath);
76- const download = request({
77- url,
78- });
79-
80- download.on("response", (response: any) => {
81- if (response.statusCode !== 200) {
82- reject(
83- new Error("There was an error retrieving the pre-indexed doc"),
84- );
85- }
86- });
87-
88- download.on("error", (err: any) => reject(err));
89- download.on("data", (chunk: any) => (data += chunk));
90- download.on("end", () => resolve(data));
91- });
92- }
93-}
modified core/indexing/docs/DocsService.ts +0 −137
@@ -37,7 +37,6 @@
3737
3838 import type * as LanceType from "vectordb";
3939 import { LLMError } from "../../llm";
40-import { DocsCache, SiteIndexingResults } from "./DocsCache";
4140
4241 // Purposefully lowercase because lancedb converts
4342 export interface LanceDbDocsRow {
@@ -433,60 +432,6 @@
433432 }
434433 }
435434
436- /**
437- * Attempt to load document embeddings from cache
438- * @returns true if cache was successfully loaded, false otherwise
439- */
440- private async tryLoadFromCache(
441- startUrl: string,
442- embeddingId: string,
443- siteIndexingConfig: SiteIndexingConfig,
444- ): Promise<boolean> {
445- try {
446- // Set a initial status when retrieving cache
447- this.handleStatusUpdate({
448- type: "docs",
449- id: startUrl,
450- embeddingsProviderId: embeddingId,
451- isReindexing: false,
452- title: siteIndexingConfig.title,
453- debugInfo: "Loaded from cache",
454- icon: siteIndexingConfig.faviconUrl,
455- url: startUrl,
456- progress: 0,
457- description: "Try to retrieve cache",
458- status: "indexing",
459- });
460-
461- const cacheHit = await this.tryFetchFromCache(startUrl, embeddingId);
462-
463- if (cacheHit) {
464- console.log(`Successfully loaded cached embeddings for ${startUrl}`);
465- // Update status to complete
466- this.handleStatusUpdate({
467- type: "docs",
468- id: startUrl,
469- embeddingsProviderId: embeddingId,
470- isReindexing: false,
471- title: siteIndexingConfig.title,
472- debugInfo: "Loaded from cache",
473- icon: siteIndexingConfig.faviconUrl,
474- url: startUrl,
475- progress: 1,
476- description: "Complete",
477- status: "complete",
478- });
479-
480- return true;
481- }
482- } catch (e) {
483- console.log(`Error trying to fetch from cache: ${e}`);
484- // Continue with regular indexing
485- }
486-
487- return false;
488- }
489-
490435 // eslint-disable-next-line max-statements
491436 async indexAndAdd(
492437 siteIndexingConfig: SiteIndexingConfig,
@@ -508,19 +453,6 @@
508453 return;
509454 }
510455
511- // Try to fetch from cache first before crawling
512- if (!forceReindex) {
513- const cacheLoaded = await this.tryLoadFromCache(
514- startUrl,
515- provider.embeddingId,
516- siteIndexingConfig,
517- );
518-
519- if (cacheLoaded) {
520- return;
521- }
522- }
523-
524456 const startedWithEmbedder = provider.embeddingId;
525457
526458 // Check if doc has been successfully indexed with the given embedder
@@ -811,52 +743,6 @@
811743 }
812744 }
813745
814- /**
815- * Try to fetch embeddings from the S3 cache for any document URL
816- * @param startUrl The URL of the documentation site
817- * @param embeddingsProviderId The ID of the embeddings provider
818- * @returns True if cache hit and successfully loaded, false otherwise
819- */
820- private async tryFetchFromCache(
821- startUrl: string,
822- embeddingId: string,
823- ): Promise<boolean> {
824- try {
825- const data = await DocsCache.getDocsCacheForUrl(embeddingId, startUrl);
826-
827- // Parse the cached data
828- const siteEmbeddings = JSON.parse(data) as SiteIndexingResults;
829-
830- // Try to get a favicon for the site
831- const favicon =
832- this.statuses.get(startUrl)?.icon ||
833- (await fetchFavicon(new URL(startUrl)));
834-
835- // Always try to make the title match what users set in the config
836- const title =
837- this.statuses.get(startUrl)?.title ||
838- siteEmbeddings.title ||
839- new URL(startUrl).hostname;
840-
841- // Add the cached embeddings to our database
842- await this.add({
843- favicon,
844- siteIndexingConfig: {
845- startUrl,
846- title,
847- },
848- chunks: siteEmbeddings.chunks,
849- embeddings: siteEmbeddings.chunks.map((c) => c.embedding),
850- });
851-
852- return true;
853- } catch (e) {
854- // Cache miss or error - silently fail
855- console.log(`Cache miss for ${startUrl} with provider ${embeddingId}`);
856- return false;
857- }
858- }
859-
860746 // Retrieve docs embeds based on user input
861747 async retrieveChunksFromQuery(
862748 query: string,
@@ -940,7 +826,6 @@
940826 }
941827 }
942828 // This function attempts to retrieve chunks by vector similarity
943- // It will also attempt to fetch from cache if no results are found
944829 async retrieveChunks(
945830 startUrl: string,
946831 vector: number[],
@@ -970,28 +855,6 @@
970855 console.warn("Error retrieving chunks from LanceDB", e);
971856 }
972857
973- // If no docs are found and this isn't a retry, try fetching from cache
974- if (docs.length === 0 && !isRetry) {
975- try {
976- // Try to fetch the document from the S3 cache
977- const cacheHit = await this.tryFetchFromCache(
978- startUrl,
979- provider.embeddingId,
980- );
981-
982- if (cacheHit) {
983- // If cache hit, refresh the submenu items for docs
984- this.messenger?.send("refreshSubmenuItems", {
985- providers: ["docs"],
986- });
987- // If cache hit, retry the search once
988- return await this.retrieveChunks(startUrl, vector, nRetrieve, true);
989- }
990- } catch (e) {
991- console.warn("Error trying to fetch from cache:", e);
992- }
993- }
994-
995858 return docs.map(this.lanceDBRowToChunk);
996859 }
997860