MCPcopy Index your code
hub / github.com/forloopcodes/contextplus / embedFilesWithFallback

Function embedFilesWithFallback

src/tools/semantic-navigate.ts:105–127  ·  view source on GitHub ↗
(files: FileInfo[])

Source from the content-addressed store, hash-verified

103}
104
105async function embedFilesWithFallback(files: FileInfo[]): Promise<{ files: FileInfo[]; vectors: number[][]; skipped: number }> {
106 if (files.length === 0) return { files: [], vectors: [], skipped: 0 };
107 const texts = files.map((file) => `${file.header} ${file.relativePath} ${file.content}`);
108
109 try {
110 return { files, vectors: await fetchEmbeddings(texts), skipped: 0 };
111 } catch (error) {
112 const keptFiles: FileInfo[] = [];
113 const vectors: number[][] = [];
114
115 for (let i = 0; i < files.length; i++) {
116 try {
117 const [vector] = await fetchEmbeddings([texts[i]]);
118 keptFiles.push(files[i]);
119 vectors.push(vector);
120 } catch {
121 }
122 }
123
124 if (keptFiles.length === 0) throw error;
125 return { files: keptFiles, vectors, skipped: files.length - keptFiles.length };
126 }
127}
128
129function extractHeader(content: string): string {
130 const lines = content.split("\n");

Callers 1

semanticNavigateFunction · 0.85

Calls 1

fetchEmbeddingsFunction · 0.85

Tested by

no test coverage detected