(
vectors: VectorizeVector[],
upsert = false
)
| 114 | } |
| 115 | |
| 116 | async insert( |
| 117 | vectors: VectorizeVector[], |
| 118 | upsert = false |
| 119 | ): Promise<VectorizeVectorMutation> { |
| 120 | let vectorInsertCount = 0; |
| 121 | const insertedIds: string[] = []; |
| 122 | for await (const batch of getBatchFromArray(vectors)) { |
| 123 | const formData = new FormData(); |
| 124 | formData.append( |
| 125 | "vectors", |
| 126 | new File([batch.join(`\n`)], "vectors.ndjson", { |
| 127 | type: "application/x-ndjson" |
| 128 | }) |
| 129 | ); |
| 130 | |
| 131 | const idxPart = await this.fetch<VectorizeVectorMutation>( |
| 132 | `/vectorize/${this.namespace}/indexes/${this.index_name}/${ |
| 133 | upsert ? "upsert" : "insert" |
| 134 | }`, |
| 135 | { |
| 136 | method: "POST", |
| 137 | body: formData |
| 138 | } |
| 139 | ); |
| 140 | vectorInsertCount += idxPart.count; |
| 141 | insertedIds.push(...idxPart.ids); |
| 142 | |
| 143 | if (vectorInsertCount > VECTORIZE_MAX_UPSERT_VECTOR_RECORDS) { |
| 144 | console.warn( |
| 145 | `🚧 While Vectorize is in beta, we've limited uploads to 100k vectors per run. You may run this again with another batch to upload further` |
| 146 | ); |
| 147 | break; |
| 148 | } |
| 149 | } |
| 150 | |
| 151 | return { |
| 152 | count: vectorInsertCount, |
| 153 | ids: insertedIds |
| 154 | }; |
| 155 | } |
| 156 | |
| 157 | async upsert(vectors: VectorizeVector[]): Promise<VectorizeVectorMutation> { |
| 158 | return this.insert(vectors, true); |
no test coverage detected