| 462 | } |
| 463 | |
| 464 | async buildIndex(indexId: string, opts: { |
| 465 | latechunk?: boolean; |
| 466 | doclingChunk?: boolean; |
| 467 | chunkSize?: number; |
| 468 | chunkOverlap?: number; |
| 469 | retrievalMode?: string; |
| 470 | windowSize?: number; |
| 471 | enableEnrich?: boolean; |
| 472 | embeddingModel?: string; |
| 473 | enrichModel?: string; |
| 474 | overviewModel?: string; |
| 475 | batchSizeEmbed?: number; |
| 476 | batchSizeEnrich?: number; |
| 477 | } = {}): Promise<{ message: string }> { |
| 478 | try { |
| 479 | const response = await fetch(`${API_BASE_URL}/indexes/${indexId}/build`, { |
| 480 | method: 'POST', |
| 481 | headers: { |
| 482 | 'Content-Type': 'application/json', |
| 483 | }, |
| 484 | body: JSON.stringify({ |
| 485 | latechunk: opts.latechunk ?? false, |
| 486 | doclingChunk: opts.doclingChunk ?? false, |
| 487 | chunkSize: opts.chunkSize ?? 512, |
| 488 | chunkOverlap: opts.chunkOverlap ?? 64, |
| 489 | retrievalMode: opts.retrievalMode ?? 'hybrid', |
| 490 | windowSize: opts.windowSize ?? 2, |
| 491 | enableEnrich: opts.enableEnrich ?? true, |
| 492 | embeddingModel: opts.embeddingModel, |
| 493 | enrichModel: opts.enrichModel, |
| 494 | overviewModel: opts.overviewModel, |
| 495 | batchSizeEmbed: opts.batchSizeEmbed ?? 50, |
| 496 | batchSizeEnrich: opts.batchSizeEnrich ?? 25, |
| 497 | }), |
| 498 | }); |
| 499 | |
| 500 | if (!response.ok) { |
| 501 | const errorData = await response.json().catch(() => ({ error: 'Unknown error' })); |
| 502 | throw new Error(`Build index error: ${errorData.error || response.statusText}`); |
| 503 | } |
| 504 | |
| 505 | return await response.json(); |
| 506 | } catch (error) { |
| 507 | console.error('Build index failed:', error); |
| 508 | throw error; |
| 509 | } |
| 510 | } |
| 511 | |
| 512 | async linkIndexToSession(sessionId: string, indexId: string): Promise<{ message: string }> { |
| 513 | const resp = await fetch(`${API_BASE_URL}/sessions/${sessionId}/indexes/${indexId}`, { method: 'POST' }); |