* Insert vector items into a collection
(collectionId, items)
| 393 | * Insert vector items into a collection |
| 394 | */ |
| 395 | async function apiInsertVectorItems(collectionId, items) { |
| 396 | ensureVectorConfig(); |
| 397 | |
| 398 | const args = await getAdditionalVectorArgs(items.map(item => item.text)); |
| 399 | const body = { |
| 400 | ...getVectorsRequestBody(args), |
| 401 | collectionId: collectionId, |
| 402 | items: items.map(item => ({ |
| 403 | hash: item.hash, |
| 404 | text: item.text, |
| 405 | index: item.index, |
| 406 | })), |
| 407 | source: getVectorSettings().source, |
| 408 | }; |
| 409 | debugLog('[API] apiInsertVectorItems request body:', body); // ADDED |
| 410 | |
| 411 | const response = await fetch('/api/vector/insert', { |
| 412 | method: 'POST', |
| 413 | headers: getRequestHeaders(), |
| 414 | credentials: 'same-origin', |
| 415 | body: JSON.stringify(body), // MODIFIED |
| 416 | }); |
| 417 | |
| 418 | if (!response.ok) { |
| 419 | const errorText = await response.text(); // ADDED |
| 420 | debugLog('[API] apiInsertVectorItems ERROR:', { status: response.status, text: errorText }); // ADDED |
| 421 | throw new Error(`Failed to insert vector items for collection ${collectionId}. Status: ${response.status}. Message: ${errorText}`); // MODIFIED |
| 422 | } |
| 423 | debugLog('[API] apiInsertVectorItems SUCCESS'); // ADDED |
| 424 | } |
| 425 | |
| 426 | /** |
| 427 | * Query a vector collection |
no test coverage detected