Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions adapters/cf/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"payloadcms-vectorize": ">=1.0.0"
},
"devDependencies": {
"@cloudflare/workers-types": "^4.20240000.0",
"payloadcms-vectorize": "workspace:*"
},
"engines": {
Expand Down
43 changes: 5 additions & 38 deletions adapters/cf/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
/// <reference types="@cloudflare/workers-types" />
import type { BasePayload } from 'payload'
import { getVectorizedPayload } from 'payloadcms-vectorize'

/**
* Retrieve the Cloudflare Vectorize binding from a Payload instance.
* Throws if the binding is not found.
*/
export function getVectorizeBinding(payload: BasePayload): CloudflareVectorizeBinding {
export function getVectorizeBinding(payload: BasePayload): Vectorize {
const binding = getVectorizedPayload(payload)?.getDbAdapterCustom()
?._vectorizeBinding as CloudflareVectorizeBinding | undefined
?._vectorizeBinding as Vectorize | undefined
if (!binding) {
throw new Error('[@payloadcms-vectorize/cf] Cloudflare Vectorize binding not found')
}
Expand All @@ -27,39 +28,5 @@ export interface CloudflareVectorizePoolConfig {
*/
export type KnowledgePoolsConfig = Record<string, CloudflareVectorizePoolConfig>

/** A single vector match returned by a Vectorize query */
export interface VectorizeMatch {
id: string
score?: number
metadata?: Record<string, unknown>
}

/** Result of a Vectorize query */
export interface VectorizeQueryResult {
matches: VectorizeMatch[]
count: number
}

/** Vector to upsert into Vectorize */
export interface VectorizeVector {
id: string
values: number[]
metadata?: Record<string, unknown>
}

/**
* Cloudflare Vectorize binding interface.
* Mirrors the subset of the Vectorize API we use.
* For the full type, install `@cloudflare/workers-types`.
*/
export interface CloudflareVectorizeBinding {
query(vector: number[], options?: {
topK?: number
returnMetadata?: boolean | 'indexed' | 'all'
filter?: Record<string, unknown>
/** Vectorize metadata filtering */
where?: Record<string, unknown>
}): Promise<VectorizeQueryResult>
upsert(vectors: VectorizeVector[]): Promise<unknown>
deleteByIds(ids: string[]): Promise<unknown>
}
/** @deprecated Use the official `Vectorize` type from `@cloudflare/workers-types`. */
export type CloudflareVectorizeBinding = Vectorize
40 changes: 25 additions & 15 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@
}
]
},
"include": ["./src/**/*.ts", "./src/**/*.tsx", "./adapters/*/src/**/*.ts", "./dev/next-env.d.ts"]
"include": ["./src/**/*.ts", "./src/**/*.tsx", "./dev/next-env.d.ts"]
}
Loading