MCPcopy
hub / github.com/partykit/partykit / insert

Method insert

packages/partykit/facade/vectorize.ts:116–155  ·  view source on GitHub ↗
(
    vectors: VectorizeVector[],
    upsert = false
  )

Source from the content-addressed store, hash-verified

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);

Callers 2

upsertMethod · 0.95
client.tsFile · 0.80

Calls 2

getBatchFromArrayFunction · 0.85
joinMethod · 0.45

Tested by

no test coverage detected