@payloadcms-vectorize/cf 0.6.0-beta.1 → 0.6.0-beta.2

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.
package/dist/index.js CHANGED
@@ -47,8 +47,8 @@ import search from './search.js';
47
47
  const dims = poolConfig[poolName]?.dims || 384;
48
48
  try {
49
49
  const results = await vectorizeBinding.query(new Array(dims).fill(0), {
50
- topK: 10000,
51
- returnMetadata: true,
50
+ topK: 100,
51
+ returnMetadata: 'indexed',
52
52
  where: {
53
53
  and: [
54
54
  {
@@ -64,7 +64,7 @@ import search from './search.js';
64
64
  });
65
65
  const idsToDelete = (results.matches || []).map((match)=>match.id);
66
66
  if (idsToDelete.length > 0) {
67
- await vectorizeBinding.delete(idsToDelete);
67
+ await vectorizeBinding.deleteByIds(idsToDelete);
68
68
  }
69
69
  } catch (error) {
70
70
  const errorMessage = error.message || error.toString();
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { DbAdapter } from 'payloadcms-vectorize'\nimport type { CloudflareVectorizeBinding, KnowledgePoolsConfig } from './types.js'\nimport embed from './embed.js'\nimport search from './search.js'\n\n/**\n * Configuration for Cloudflare Vectorize integration\n */\ninterface CloudflareVectorizeConfig {\n /** Knowledge pools configuration with their dimensions */\n config: KnowledgePoolsConfig\n /** Cloudflare Vectorize binding for vector storage */\n binding: CloudflareVectorizeBinding\n}\n\n/**\n * Create a Cloudflare Vectorize integration for payloadcms-vectorize\n *\n * @param options Configuration object with knowledge pools and Vectorize binding\n * @returns Object containing the DbAdapter instance\n *\n * @example\n * ```typescript\n * import { createCloudflareVectorizeIntegration } from '@payloadcms-vectorize/cf'\n *\n * const { adapter } = createCloudflareVectorizeIntegration({\n * config: {\n * default: {\n * dims: 384,\n * },\n * },\n * binding: env.VECTORIZE,\n * })\n * ```\n */\nexport const createCloudflareVectorizeIntegration = (\n options: CloudflareVectorizeConfig,\n): { adapter: DbAdapter } => {\n if (!options.binding) {\n throw new Error('[@payloadcms-vectorize/cf] Cloudflare Vectorize binding is required')\n }\n\n const poolConfig = options.config\n\n const adapter: DbAdapter = {\n getConfigExtension: () => {\n return {\n custom: {\n _cfVectorizeAdapter: true,\n _poolConfigs: poolConfig,\n _vectorizeBinding: options.binding,\n },\n }\n },\n\n search: async (payload, queryEmbedding, poolName, limit, where) => {\n return search(payload, queryEmbedding, poolName, limit, where)\n },\n\n storeEmbedding: async (payload, poolName, id, embedding) => {\n return embed(payload, poolName, id, embedding)\n },\n\n deleteEmbeddings: async (payload, poolName, sourceCollection, docId) => {\n // Delete all embeddings for this document from Cloudflare Vectorize\n // First, query to find all matching IDs\n const vectorizeBinding = options.binding\n const dims = poolConfig[poolName]?.dims || 384\n try {\n const results = await vectorizeBinding.query(new Array(dims).fill(0), {\n topK: 10000,\n returnMetadata: true,\n where: {\n and: [\n { key: 'sourceCollection', value: sourceCollection },\n { key: 'docId', value: docId },\n ],\n },\n })\n\n const idsToDelete = (results.matches || []).map((match: any) => match.id)\n\n if (idsToDelete.length > 0) {\n await vectorizeBinding.delete(idsToDelete)\n }\n } catch (error) {\n const errorMessage = (error as Error).message || (error as any).toString()\n payload.logger.error(\n `[@payloadcms-vectorize/cf] Failed to delete embeddings: ${errorMessage}`,\n )\n throw new Error(`[@payloadcms-vectorize/cf] Failed to delete embeddings: ${errorMessage}`)\n }\n },\n }\n\n return { adapter }\n}\n\nexport type { CloudflareVectorizeBinding, KnowledgePoolsConfig }\nexport type { KnowledgePoolsConfig as KnowledgePoolConfig }\n"],"names":["embed","search","createCloudflareVectorizeIntegration","options","binding","Error","poolConfig","config","adapter","getConfigExtension","custom","_cfVectorizeAdapter","_poolConfigs","_vectorizeBinding","payload","queryEmbedding","poolName","limit","where","storeEmbedding","id","embedding","deleteEmbeddings","sourceCollection","docId","vectorizeBinding","dims","results","query","Array","fill","topK","returnMetadata","and","key","value","idsToDelete","matches","map","match","length","delete","error","errorMessage","message","toString","logger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,OAAO;gBACd,MAAMC,eAAe,AAACD,MAAgBE,OAAO,IAAI,AAACF,MAAcG,QAAQ;gBACxE/B,QAAQgC,MAAM,CAACJ,KAAK,CAClB,CAAC,wDAAwD,EAAEC,cAAc;gBAE3E,MAAM,IAAItC,MAAM,CAAC,wDAAwD,EAAEsC,cAAc;YAC3F;QACF;IACF;IAEA,OAAO;QAAEnC;IAAQ;AACnB,EAAC"}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { DbAdapter } from 'payloadcms-vectorize'\nimport type { CloudflareVectorizeBinding, KnowledgePoolsConfig } from './types.js'\nimport embed from './embed.js'\nimport search from './search.js'\n\n/**\n * Configuration for Cloudflare Vectorize integration\n */\ninterface CloudflareVectorizeConfig {\n /** Knowledge pools configuration with their dimensions */\n config: KnowledgePoolsConfig\n /** Cloudflare Vectorize binding for vector storage */\n binding: CloudflareVectorizeBinding\n}\n\n/**\n * Create a Cloudflare Vectorize integration for payloadcms-vectorize\n *\n * @param options Configuration object with knowledge pools and Vectorize binding\n * @returns Object containing the DbAdapter instance\n *\n * @example\n * ```typescript\n * import { createCloudflareVectorizeIntegration } from '@payloadcms-vectorize/cf'\n *\n * const { adapter } = createCloudflareVectorizeIntegration({\n * config: {\n * default: {\n * dims: 384,\n * },\n * },\n * binding: env.VECTORIZE,\n * })\n * ```\n */\nexport const createCloudflareVectorizeIntegration = (\n options: CloudflareVectorizeConfig,\n): { adapter: DbAdapter } => {\n if (!options.binding) {\n throw new Error('[@payloadcms-vectorize/cf] Cloudflare Vectorize binding is required')\n }\n\n const poolConfig = options.config\n\n const adapter: DbAdapter = {\n getConfigExtension: () => {\n return {\n custom: {\n _cfVectorizeAdapter: true,\n _poolConfigs: poolConfig,\n _vectorizeBinding: options.binding,\n },\n }\n },\n\n search: async (payload, queryEmbedding, poolName, limit, where) => {\n return search(payload, queryEmbedding, poolName, limit, where)\n },\n\n storeEmbedding: async (payload, poolName, id, embedding) => {\n return embed(payload, poolName, id, embedding)\n },\n\n deleteEmbeddings: async (payload, poolName, sourceCollection, docId) => {\n // Delete all embeddings for this document from Cloudflare Vectorize\n // First, query to find all matching IDs\n const vectorizeBinding = options.binding\n const dims = poolConfig[poolName]?.dims || 384\n try {\n const results = await vectorizeBinding.query(new Array(dims).fill(0), {\n topK: 100,\n returnMetadata: 'indexed',\n where: {\n and: [\n { key: 'sourceCollection', value: sourceCollection },\n { key: 'docId', value: docId },\n ],\n },\n })\n\n const idsToDelete = (results.matches || []).map((match: any) => match.id)\n\n if (idsToDelete.length > 0) {\n await vectorizeBinding.deleteByIds(idsToDelete)\n }\n } catch (error) {\n const errorMessage = (error as Error).message || (error as any).toString()\n payload.logger.error(\n `[@payloadcms-vectorize/cf] Failed to delete embeddings: ${errorMessage}`,\n )\n throw new Error(`[@payloadcms-vectorize/cf] Failed to delete embeddings: ${errorMessage}`)\n }\n },\n }\n\n return { adapter }\n}\n\nexport type { CloudflareVectorizeBinding, KnowledgePoolsConfig }\nexport type { KnowledgePoolsConfig as KnowledgePoolConfig }\n"],"names":["embed","search","createCloudflareVectorizeIntegration","options","binding","Error","poolConfig","config","adapter","getConfigExtension","custom","_cfVectorizeAdapter","_poolConfigs","_vectorizeBinding","payload","queryEmbedding","poolName","limit","where","storeEmbedding","id","embedding","deleteEmbeddings","sourceCollection","docId","vectorizeBinding","dims","results","query","Array","fill","topK","returnMetadata","and","key","value","idsToDelete","matches","map","match","length","deleteByIds","error","errorMessage","message","toString","logger"],"mappings":"AAEA,OAAOA,WAAW,aAAY;AAC9B,OAAOC,YAAY,cAAa;AAYhC;;;;;;;;;;;;;;;;;;;CAmBC,GACD,OAAO,MAAMC,uCAAuC,CAClDC;IAEA,IAAI,CAACA,QAAQC,OAAO,EAAE;QACpB,MAAM,IAAIC,MAAM;IAClB;IAEA,MAAMC,aAAaH,QAAQI,MAAM;IAEjC,MAAMC,UAAqB;QACzBC,oBAAoB;YAClB,OAAO;gBACLC,QAAQ;oBACNC,qBAAqB;oBACrBC,cAAcN;oB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3
- "version": "0.6.0-beta.1",
3
+ "version": "0.6.0-beta.2",
4
4
  "description": "Cloudflare Vectorize adapter for payloadcms-vectorize",
5
5
  "license": "MIT",
6
6
  "type": "module",