* Rebuilds the code index.
()
| 280 | * Rebuilds the code index. |
| 281 | */ |
| 282 | public async rebuild(): Promise<void> { |
| 283 | if (!await this.isCreated()) { |
| 284 | throw new Error('Index has not been created yet. Please run `codepilot create` first.'); |
| 285 | } |
| 286 | if (!await this.hasKeys()) { |
| 287 | throw new Error("A local vectra.keys file couldn't be found. Please run `codepilot set --key <your OpenAI key>`."); |
| 288 | } |
| 289 | |
| 290 | // Create fresh index |
| 291 | const index = await this.load(); |
| 292 | if (await index.isCatalogCreated()) { |
| 293 | await index.deleteIndex(); |
| 294 | } |
| 295 | await index.createIndex(); |
| 296 | |
| 297 | // Index files |
| 298 | const fetcher = new FileFetcher(); |
| 299 | for (const source of this._config!.sources) { |
| 300 | await fetcher.fetch(source, async (uri, text, docType) => { |
| 301 | // Ignore binary files |
| 302 | if (IGNORED_FILES.includes(path.extname(uri))) { |
| 303 | return true; |
| 304 | } |
| 305 | |
| 306 | // Ignore any disallowed extensions |
| 307 | if (this._config!.extensions && docType && !this._config!.extensions!.includes(docType)) { |
| 308 | return true; |
| 309 | } |
| 310 | |
| 311 | // Upsert document |
| 312 | console.log(Colorize.progress(`adding: ${uri}`)); |
| 313 | await index.upsertDocument(uri, text, docType); |
| 314 | return true; |
| 315 | }); |
| 316 | } |
| 317 | } |
| 318 | |
| 319 | // LLM-REGION |
| 320 |