* Adds a document to the index. * @param path Path to the document to add.
(path: string)
| 411 | * @param path Path to the document to add. |
| 412 | */ |
| 413 | public async upsertDocument(path: string): Promise<void> { |
| 414 | if (!await this.isCreated()) { |
| 415 | throw new Error('Index has not been created yet. Please run `codepilot create` first.'); |
| 416 | } |
| 417 | if (!await this.hasKeys()) { |
| 418 | throw new Error("A local vectra.keys file couldn't be found. Please run `codepilot set --key <your OpenAI key>`."); |
| 419 | } |
| 420 | |
| 421 | // Ensure index is loaded |
| 422 | const index = await this.load(); |
| 423 | |
| 424 | // Fetch document |
| 425 | const fetcher = new FileFetcher(); |
| 426 | await fetcher.fetch(path, async (uri, text, docType) => { |
| 427 | // Upsert document |
| 428 | await index.upsertDocument(uri, text, docType); |
| 429 | return true; |
| 430 | }); |
| 431 | } |
| 432 | } |
no test coverage detected