@lunora/bindings 1.0.0-alpha.71 → 1.0.0-alpha.73

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,6 @@
1
+ import{LunoraError as x}from"@lunora/errors";import{c as b,U as g}from"./concurrent-vRmSvRpF.mjs";const B=(t,a)=>{if(!a.includes("."))return t[a];let s=t;for(const e of a.split(".")){if(s===null||typeof s!="object"||Array.isArray(s))return;s=s[e]}return s},T=(t,a)=>{const s=a?.namespace,e=new Set(a?.shardedIndexNames),n=(c,l)=>{if(l!==void 0)return l;if(e.has(c)){if(s!==void 0)return s;throw new Error(`@lunora/bindings/vectors: index "${c}" belongs to a sharded table, but this DO instance has no shard key (it is the root/default DO) and no explicit namespace was given. A namespace-less operation here would reach every tenant's vectors — Vectorize indexes are account-global. Pass an explicit namespace, or issue this call from the sharded DO instance that owns the tenant.`)}},i=a?.deferAfterCommit,d=async(c,l,u)=>{await t.upsert(c,{embed:l.embed,id:l.id,input:l.input,metadata:l.metadata,namespace:u})},f=async(c,l)=>{await d(c,l,n(c,l.namespace))},o=i===void 0?f:async(c,l)=>{const u=n(c,l.namespace);await i(async()=>d(c,l,u))},r=async(c,l,u)=>{const m=await t.getByIds(c,l);return u===void 0?m:m.filter(h=>h.namespace===u)};return{deleteByIds:async(c,l,u)=>{const m=n(c,u);if(m===void 0){await t.deleteByIds(c,l);return}const h=await r(c,l,m);h.length!==0&&await t.deleteByIds(c,h.map(p=>p.id))},getByIds:async(c,l,u)=>{const m=n(c,u);return(await r(c,l,m)).map(p=>({id:p.id,metadata:p.metadata,namespace:p.namespace,values:[...p.values]}))},query:async(c,l)=>{const u=await t.query(c,{embed:l.embed,filter:l.filter,input:l.input,namespace:n(c,l.namespace),returnMetadata:l.returnMetadata??"indexed",topK:l.topK,vector:l.vector});return{count:u.count,matches:u.matches.map(m=>({id:m.id,metadata:m.metadata,score:m.score}))}},upsert:o,upsertNow:f}},w=new Set,I=t=>{w.has(t)||(w.add(t),console.warn(`[@lunora/bindings/vectors] index "${t}" syncs vectors without a namespace — in a
2
+ multi-tenant/sharded app this exposes one tenant's vectors (and any captured
3
+ metadata) to every other tenant, since Vectorize indexes are account-global.
4
+ Pass \`namespace\` (the shard/tenant key) on both write and query — query-side
5
+ namespace filtering is mandatory for multi-tenant apps. Single-tenant apps that
6
+ legitimately have no tenant key suppress this via { allowSharedNamespace: true }.`))},A=(t,a)=>{const s={};for(const e of a)e in t&&(s[e]=t[e]);return s},v=(t,a)=>{a.input.trim()===""?t.deletes.push(a.name):t.upserts.push(a)},C=(t,a,s)=>{const e=B(t,a.field);if(e!=null){if(typeof e!="string")throw new TypeError(`@lunora/bindings/vectors: inline index "${a.name}" expects a string source at "${a.field}" on table "${s}" (got ${typeof e}); use a standalone defineVectorIndex with a select() to derive text from non-string columns`);return e}},k=(t,a)=>{const s=t.tables[a.table],e=s?.vectorIndexes??[],n=Object.entries(t.vectorIndexes).filter(([,r])=>r.table===a.table);if(e.length===0&&n.length===0)return;const i=s?.softDeleteMode?.field,d=i!==void 0&&a.doc?.[i]!==void 0&&a.doc[i]!==null;if(a.op==="delete"||d)return{deletes:[...e.map(r=>r.name),...n.map(([r])=>r)],upserts:[]};const f=a.doc;if(!f)return;const o={deletes:[],upserts:[]};for(const r of e){const c=C(f,r,a.table);c===void 0?o.deletes.push(r.name):v(o,{embed:r.embed,input:c,metadata:r.metadata?A(f,r.metadata):void 0,name:r.name})}for(const[r,c]of n)v(o,{embed:c.embed,input:c.select(f),metadata:c.metadata?.(f),name:r});return o},j=t=>{const{allowSharedNamespace:a,namespace:s,schema:e,vectors:n}=t;return async i=>{const d=k(e,i);if(!d)return;const f=[...d.deletes.map(o=>async()=>{await n.deleteByIds(o,[i.id])}),...d.upserts.map(o=>async()=>{!a&&s===void 0&&I(o.name),await n.upsertNow(o.name,{embed:o.embed,id:i.id,input:o.input,metadata:o.metadata,namespace:s})})];await b(f,g,async o=>o())}},S=1e3,E=(t,a)=>{const s=[];for(let e=0;e<t.length;e+=a)s.push(t.slice(e,e+a));return s},y=t=>{if(typeof t!="object"||t===null)return"unknown";const{name:a,status:s,statusCode:e}=t,n=typeof s=="number"?s:e;if(typeof n=="number"){if(n>=500||n===401||n===403||n===408||n===429)return"service";if(n>=400)return"row"}return a==="TimeoutError"||a==="AbortError"?"service":t instanceof TypeError||t instanceof RangeError?"row":"unknown"},M=async(t,a)=>{const s=await b(t,g,async d=>{try{return{item:d,ok:!0,value:await a(d)}}catch(f){return{error:f,item:d,ok:!1}}}),e=s.flatMap(d=>d.ok?[{item:d.item,value:d.value}]:[]),n=s.flatMap(d=>d.ok?[]:[{error:d.error,item:d.item}]),i=n.find(({error:d})=>y(d)==="service");if(i)throw i.error;if(t.length>=2&&e.length===0&&n.some(({error:d})=>y(d)!=="row"))throw n[0]?.error;return{failed:n,ok:e}},D=(t,a,s,e)=>{const n=new Map,i=[];for(const{doc:d,id:f}of s){let o;try{o=k(t,{doc:d,id:f,op:"update",table:a})}catch(r){e.set(f,r);continue}for(const r of o?.deletes??[])n.set(r,[...n.get(r)??[],f]);for(const r of o?.upserts??[])i.push({id:f,upsert:r})}return{deletes:n,pending:i}},O=async(t,a,s,e)=>{const{allowSharedNamespace:n,namespace:i,upsertMany:d,vectors:f}=t;!n&&i===void 0&&I(a);const o=s.map(({id:r,upsert:c,values:l})=>({embed:()=>l,id:r,input:c.input,metadata:c.metadata,namespace:i}));for(const r of E(o,S))try{await d(a,r)}catch{const c=await M(r,async l=>f.upsertNow(a,l));for(const{error:l,item:u}of c.failed)e.set(u.id,l)}},V=async(t,a,s)=>{const e=new Map,{deletes:n,pending:i}=D(t.schema,a,s,e),d=await M(i,async({upsert:o})=>o.embed(o.input)),f=new Map;for(const{error:o,item:r}of d.failed)e.set(r.id,o);for(const{item:o,value:r}of d.ok)f.set(o.upsert.name,[...f.get(o.upsert.name)??[],{...o,values:r}]);for(const[o,r]of n)for(const c of E(r,S))await t.vectors.deleteByIds(o,c);for(const[o,r]of f)await O(t,o,r,e);return[...e].map(([o,r])=>({error:r,id:o}))},P=t=>async(a,s)=>{try{return await V(t,a,s)}catch(e){throw y(e)==="service"?new x("SERVICE_UNAVAILABLE",e instanceof Error?e.message:String(e),{cause:e}):e}},$=t=>{const a=new Map,s=(e,n,i)=>{const d=i===void 0?n:[...n,i];a.set(e,[...a.get(e)??[],JSON.stringify(d)])};for(const[e,n]of Object.entries(t.tables))for(const i of n.vectorIndexes??[])s(e,[i.name,i.field,i.dimensions,i.metric,i.metadata??[]],i.model);for(const[e,n]of Object.entries(t.vectorIndexes))s(n.table,[e,"(select)",n.dimensions,n.metric],n.model);return[...a].map(([e,n])=>{const i=t.tables[e]?.softDeleteMode?.field;return{profile:(i===void 0?n:[...n,JSON.stringify(["(softDelete)",i])]).toSorted((f,o)=>f.localeCompare(o)).join("|"),table:e}})};export{T as createContextVectors,P as createVectorBackfillSync,j as createVectorSyncHook,$ as vectorBackfillTargets};
@@ -219,6 +219,8 @@ interface TableVectorIndexLike {
219
219
  field: string;
220
220
  metadata?: ReadonlyArray<string>;
221
221
  metric?: string;
222
+ /** Declared identifier of what `embed` produces; part of the backfill fingerprint. */
223
+ model?: string;
222
224
  name: string;
223
225
  }
224
226
  interface TableDefinitionLike {
@@ -234,6 +236,8 @@ interface VectorIndexDefinitionLike {
234
236
  embed: VectorEmbedderLike;
235
237
  metadata?: (row: Record<string, unknown>) => Record<string, unknown>;
236
238
  metric?: string;
239
+ /** Declared identifier of what `embed` produces; part of the backfill fingerprint. */
240
+ model?: string;
237
241
  select: (row: Record<string, unknown>) => string;
238
242
  table: string;
239
243
  }
@@ -314,7 +318,9 @@ interface VectorBackfillFailure {
314
318
  /**
315
319
  * Index one page of rows for the shard's vector backfill. Resolves with the rows
316
320
  * that failed on their own; REJECTS when the failure is the service's rather than
317
- * a row's, so the caller holds its cursor and retries the page.
321
+ * a row's, so the caller holds its cursor and retries the page — with a
322
+ * `SERVICE_UNAVAILABLE` `LunoraError` when the error shows the failure to be
323
+ * transient, and with the raw error when only the whole page failing suggests it.
318
324
  */
319
325
  type VectorBackfillSync = (table: string, rows: ReadonlyArray<{
320
326
  doc: Record<string, unknown>;
@@ -335,10 +341,14 @@ type VectorBackfillSync = (table: string, rows: ReadonlyArray<{
335
341
  * these too, and a backfill that stopped on one would never finish.
336
342
  *
337
343
  * A SERVICE failure is transient: the embedder or Vectorize is unreachable. The
338
- * call rejects, so the page is retried. It is recognised as every attempt in a
344
+ * call rejects, so the page is retried. It is recognised by the error where the
345
+ * error says (an HTTP 5xx/408/429 status, a timeout — see {@link classifyFailure};
346
+ * these reject as `SERVICE_UNAVAILABLE`), and otherwise as every attempt in a
339
347
  * group of two or more failing, and as a failed `deleteByIds` (which has no row
340
348
  * content to blame). A batch `upsertMany` that fails is retried one row at a
341
- * time to tell the two apart.
349
+ * time to tell the two apart. A group that fails whole on every retry — each
350
+ * row refused for the same reason, with no status to show it — rejects each
351
+ * time too; the backfill writes such a page off after a few consecutive tries.
342
352
  *
343
353
  * `upsertMany` is the raw binding call, so the namespace is passed explicitly —
344
354
  * the same `namespace` the live hook scopes by.
@@ -357,11 +367,18 @@ declare const createVectorBackfillSync: (options: BackfillSyncOptions) => Vector
357
367
  * backfill, which re-walks a table whose fingerprint changed.
358
368
  *
359
369
  * Covers what the schema can see: index names, the inline source field,
360
- * dimensions, metric and inline metadata fields. A function (`embed`, a Shape B
361
- * `select`/`metadata`) has no stable identity to fingerprint — its source text
362
- * changes with unrelated rebuilds of the bundle, which would re-embed whole
363
- * tables for nothing — so changing one is announced by calling the backfill with
364
- * `restart: true`.
370
+ * dimensions, metric, inline metadata fields, the declared `model`, and the
371
+ * table's `.softDelete()` field — a row hidden by a newly chosen marker keeps
372
+ * its vector until the table is walked again. A
373
+ * function (`embed`, a Shape B `select`/`metadata`) has no stable identity to
374
+ * fingerprint — its source text changes with unrelated rebuilds of the bundle,
375
+ * which would re-embed whole tables for nothing — so the declared `model` string
376
+ * stands in for `embed`, and any other change is announced by calling the
377
+ * backfill with `restart: true`.
378
+ *
379
+ * `model` joins a descriptor only when declared, and the soft-delete field only
380
+ * when the table has one, so an index without either keeps the fingerprint it
381
+ * was recorded under and is not re-embedded for it.
365
382
  */
366
383
  declare const vectorBackfillTargets: (schema: SchemaLike) => {
367
384
  profile: string;
@@ -219,6 +219,8 @@ interface TableVectorIndexLike {
219
219
  field: string;
220
220
  metadata?: ReadonlyArray<string>;
221
221
  metric?: string;
222
+ /** Declared identifier of what `embed` produces; part of the backfill fingerprint. */
223
+ model?: string;
222
224
  name: string;
223
225
  }
224
226
  interface TableDefinitionLike {
@@ -234,6 +236,8 @@ interface VectorIndexDefinitionLike {
234
236
  embed: VectorEmbedderLike;
235
237
  metadata?: (row: Record<string, unknown>) => Record<string, unknown>;
236
238
  metric?: string;
239
+ /** Declared identifier of what `embed` produces; part of the backfill fingerprint. */
240
+ model?: string;
237
241
  select: (row: Record<string, unknown>) => string;
238
242
  table: string;
239
243
  }
@@ -314,7 +318,9 @@ interface VectorBackfillFailure {
314
318
  /**
315
319
  * Index one page of rows for the shard's vector backfill. Resolves with the rows
316
320
  * that failed on their own; REJECTS when the failure is the service's rather than
317
- * a row's, so the caller holds its cursor and retries the page.
321
+ * a row's, so the caller holds its cursor and retries the page — with a
322
+ * `SERVICE_UNAVAILABLE` `LunoraError` when the error shows the failure to be
323
+ * transient, and with the raw error when only the whole page failing suggests it.
318
324
  */
319
325
  type VectorBackfillSync = (table: string, rows: ReadonlyArray<{
320
326
  doc: Record<string, unknown>;
@@ -335,10 +341,14 @@ type VectorBackfillSync = (table: string, rows: ReadonlyArray<{
335
341
  * these too, and a backfill that stopped on one would never finish.
336
342
  *
337
343
  * A SERVICE failure is transient: the embedder or Vectorize is unreachable. The
338
- * call rejects, so the page is retried. It is recognised as every attempt in a
344
+ * call rejects, so the page is retried. It is recognised by the error where the
345
+ * error says (an HTTP 5xx/408/429 status, a timeout — see {@link classifyFailure};
346
+ * these reject as `SERVICE_UNAVAILABLE`), and otherwise as every attempt in a
339
347
  * group of two or more failing, and as a failed `deleteByIds` (which has no row
340
348
  * content to blame). A batch `upsertMany` that fails is retried one row at a
341
- * time to tell the two apart.
349
+ * time to tell the two apart. A group that fails whole on every retry — each
350
+ * row refused for the same reason, with no status to show it — rejects each
351
+ * time too; the backfill writes such a page off after a few consecutive tries.
342
352
  *
343
353
  * `upsertMany` is the raw binding call, so the namespace is passed explicitly —
344
354
  * the same `namespace` the live hook scopes by.
@@ -357,11 +367,18 @@ declare const createVectorBackfillSync: (options: BackfillSyncOptions) => Vector
357
367
  * backfill, which re-walks a table whose fingerprint changed.
358
368
  *
359
369
  * Covers what the schema can see: index names, the inline source field,
360
- * dimensions, metric and inline metadata fields. A function (`embed`, a Shape B
361
- * `select`/`metadata`) has no stable identity to fingerprint — its source text
362
- * changes with unrelated rebuilds of the bundle, which would re-embed whole
363
- * tables for nothing — so changing one is announced by calling the backfill with
364
- * `restart: true`.
370
+ * dimensions, metric, inline metadata fields, the declared `model`, and the
371
+ * table's `.softDelete()` field — a row hidden by a newly chosen marker keeps
372
+ * its vector until the table is walked again. A
373
+ * function (`embed`, a Shape B `select`/`metadata`) has no stable identity to
374
+ * fingerprint — its source text changes with unrelated rebuilds of the bundle,
375
+ * which would re-embed whole tables for nothing — so the declared `model` string
376
+ * stands in for `embed`, and any other change is announced by calling the
377
+ * backfill with `restart: true`.
378
+ *
379
+ * `model` joins a descriptor only when declared, and the soft-delete field only
380
+ * when the table has one, so an index without either keeps the fingerprint it
381
+ * was recorded under and is not re-embedded for it.
365
382
  */
366
383
  declare const vectorBackfillTargets: (schema: SchemaLike) => {
367
384
  profile: string;
@@ -1 +1 @@
1
- import{createContextVectors as t,createVectorBackfillSync as o,createVectorSyncHook as c,vectorBackfillTargets as a}from"../packem_shared/createContextVectors-Bz5Me4s6.mjs";import{createVectorAdminIntrospector as l}from"../packem_shared/createVectorAdminIntrospector-Ct8v6PxJ.mjs";import{default as s}from"../packem_shared/createVectors-Dzv0ilKE.mjs";export{t as createContextVectors,l as createVectorAdminIntrospector,o as createVectorBackfillSync,c as createVectorSyncHook,s as createVectors,a as vectorBackfillTargets};
1
+ import{createContextVectors as t,createVectorBackfillSync as o,createVectorSyncHook as c,vectorBackfillTargets as a}from"../packem_shared/createContextVectors-DiyO3pZU.mjs";import{createVectorAdminIntrospector as l}from"../packem_shared/createVectorAdminIntrospector-Ct8v6PxJ.mjs";import{default as s}from"../packem_shared/createVectors-Dzv0ilKE.mjs";export{t as createContextVectors,l as createVectorAdminIntrospector,o as createVectorBackfillSync,c as createVectorSyncHook,s as createVectors,a as vectorBackfillTargets};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lunora/bindings",
3
- "version": "1.0.0-alpha.71",
3
+ "version": "1.0.0-alpha.73",
4
4
  "description": "Lightweight Cloudflare binding helpers for Lunora — ctx.kv, ctx.images, ctx.analytics, ctx.pipelines, ctx.vectors, ctx.r2sql — one install, per-binding subpaths",
5
5
  "keywords": [
6
6
  "analytics",
@@ -65,7 +65,7 @@
65
65
  },
66
66
  "dependencies": {
67
67
  "@lunora/errors": "1.0.0-alpha.41",
68
- "@lunora/platform": "1.0.0-alpha.36"
68
+ "@lunora/platform": "1.0.0-alpha.38"
69
69
  },
70
70
  "engines": {
71
71
  "node": "^22.15.0 || >=24.11.0"
@@ -1,6 +0,0 @@
1
- import{c as w,U as v}from"./concurrent-vRmSvRpF.mjs";const M=(s,r)=>{if(!r.includes("."))return s[r];let i=s;for(const a of r.split(".")){if(i===null||typeof i!="object"||Array.isArray(i))return;i=i[a]}return i},A=(s,r)=>{const i=r?.namespace,a=new Set(r?.shardedIndexNames),d=(t,c)=>{if(c!==void 0)return c;if(a.has(t)){if(i!==void 0)return i;throw new Error(`@lunora/bindings/vectors: index "${t}" belongs to a sharded table, but this DO instance has no shard key (it is the root/default DO) and no explicit namespace was given. A namespace-less operation here would reach every tenant's vectors — Vectorize indexes are account-global. Pass an explicit namespace, or issue this call from the sharded DO instance that owns the tenant.`)}},n=r?.deferAfterCommit,f=async(t,c,u)=>{await s.upsert(t,{embed:c.embed,id:c.id,input:c.input,metadata:c.metadata,namespace:u})},l=async(t,c)=>{await f(t,c,d(t,c.namespace))},o=n===void 0?l:async(t,c)=>{const u=d(t,c.namespace);await n(async()=>f(t,c,u))},e=async(t,c,u)=>{const m=await s.getByIds(t,c);return u===void 0?m:m.filter(h=>h.namespace===u)};return{deleteByIds:async(t,c,u)=>{const m=d(t,u);if(m===void 0){await s.deleteByIds(t,c);return}const h=await e(t,c,m);h.length!==0&&await s.deleteByIds(t,h.map(p=>p.id))},getByIds:async(t,c,u)=>{const m=d(t,u);return(await e(t,c,m)).map(p=>({id:p.id,metadata:p.metadata,namespace:p.namespace,values:[...p.values]}))},query:async(t,c)=>{const u=await s.query(t,{embed:c.embed,filter:c.filter,input:c.input,namespace:d(t,c.namespace),returnMetadata:c.returnMetadata??"indexed",topK:c.topK,vector:c.vector});return{count:u.count,matches:u.matches.map(m=>({id:m.id,metadata:m.metadata,score:m.score}))}},upsert:o,upsertNow:l}},y=new Set,b=s=>{y.has(s)||(y.add(s),console.warn(`[@lunora/bindings/vectors] index "${s}" syncs vectors without a namespace — in a
2
- multi-tenant/sharded app this exposes one tenant's vectors (and any captured
3
- metadata) to every other tenant, since Vectorize indexes are account-global.
4
- Pass \`namespace\` (the shard/tenant key) on both write and query — query-side
5
- namespace filtering is mandatory for multi-tenant apps. Single-tenant apps that
6
- legitimately have no tenant key suppress this via { allowSharedNamespace: true }.`))},S=(s,r)=>{const i={};for(const a of r)a in s&&(i[a]=s[a]);return i},g=(s,r)=>{const i=s.tables[r.table],a=i?.vectorIndexes??[],d=Object.entries(s.vectorIndexes).filter(([,e])=>e.table===r.table);if(a.length===0&&d.length===0)return;const n=i?.softDeleteMode?.field,f=n!==void 0&&r.doc?.[n]!==void 0&&r.doc[n]!==null;if(r.op==="delete"||f)return{deletes:[...a.map(e=>e.name),...d.map(([e])=>e)],upserts:[]};const l=r.doc;if(!l)return;const o={deletes:[],upserts:[]};for(const e of a){const t=M(l,e.field);if(t==null)o.deletes.push(e.name);else if(typeof t=="string")o.upserts.push({embed:e.embed,input:t,metadata:e.metadata?S(l,e.metadata):void 0,name:e.name});else throw new TypeError(`@lunora/bindings/vectors: inline index "${e.name}" expects a string source at "${e.field}" on table "${r.table}" (got ${typeof t}); use a standalone defineVectorIndex with a select() to derive text from non-string columns`)}for(const[e,t]of d)o.upserts.push({embed:t.embed,input:t.select(l),metadata:t.metadata?.(l),name:e});return o},D=s=>{const{allowSharedNamespace:r,namespace:i,schema:a,vectors:d}=s;return async n=>{const f=g(a,n);if(!f)return;const l=[...f.deletes.map(o=>async()=>{await d.deleteByIds(o,[n.id])}),...f.upserts.map(o=>async()=>{!r&&i===void 0&&b(o.name),await d.upsertNow(o.name,{embed:o.embed,id:n.id,input:o.input,metadata:o.metadata,namespace:i})})];await w(l,v,async o=>o())}},I=1e3,x=(s,r)=>{const i=[];for(let a=0;a<s.length;a+=r)i.push(s.slice(a,a+r));return i},k=async(s,r)=>{const i=await w(s,v,async n=>{try{return{item:n,ok:!0,value:await r(n)}}catch(f){return{error:f,item:n,ok:!1}}}),a=i.flatMap(n=>n.ok?[{item:n.item,value:n.value}]:[]),d=i.flatMap(n=>n.ok?[]:[{error:n.error,item:n.item}]);if(s.length>=2&&a.length===0)throw d[0]?.error;return{failed:d,ok:a}},B=(s,r,i,a)=>{const d=new Map,n=[];for(const{doc:f,id:l}of i){let o;try{o=g(s,{doc:f,id:l,op:"update",table:r})}catch(e){a.set(l,e);continue}for(const e of o?.deletes??[])d.set(e,[...d.get(e)??[],l]);for(const e of o?.upserts??[])n.push({id:l,upsert:e})}return{deletes:d,pending:n}},C=async(s,r,i,a)=>{const{allowSharedNamespace:d,namespace:n,upsertMany:f,vectors:l}=s;!d&&n===void 0&&b(r);const o=i.map(({id:e,upsert:t,values:c})=>({embed:()=>c,id:e,input:t.input,metadata:t.metadata,namespace:n}));for(const e of x(o,I))try{await f(r,e)}catch{const t=await k(e,async c=>l.upsertNow(r,c));for(const{error:c,item:u}of t.failed)a.set(u.id,c)}},E=s=>async(r,i)=>{const a=new Map,{deletes:d,pending:n}=B(s.schema,r,i,a),f=await k(n,async({upsert:o})=>o.embed(o.input)),l=new Map;for(const{error:o,item:e}of f.failed)a.set(e.id,o);for(const{item:o,value:e}of f.ok)l.set(o.upsert.name,[...l.get(o.upsert.name)??[],{...o,values:e}]);for(const[o,e]of d)for(const t of x(e,I))await s.vectors.deleteByIds(o,t);for(const[o,e]of l)await C(s,o,e,a);return[...a].map(([o,e])=>({error:e,id:o}))},V=s=>{const r=new Map,i=(a,d)=>{r.set(a,[...r.get(a)??[],JSON.stringify(d)])};for(const[a,d]of Object.entries(s.tables))for(const n of d.vectorIndexes??[])i(a,[n.name,n.field,n.dimensions,n.metric,n.metadata??[]]);for(const[a,d]of Object.entries(s.vectorIndexes))i(d.table,[a,"(select)",d.dimensions,d.metric]);return[...r].map(([a,d])=>({profile:d.toSorted((n,f)=>n.localeCompare(f)).join("|"),table:a}))};export{A as createContextVectors,E as createVectorBackfillSync,D as createVectorSyncHook,V as vectorBackfillTargets};