Skip to content

Commit 55c3acf

Browse files
Fix Vectorize upsert to avoid v1 fallback for v2 indexes
Only fall back to legacy endpoints when we can positively identify a legacy index. This prevents v2 indexes from failing with incorrect_api_version. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 41248b7 commit 55c3acf

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

other/semantic-search/cloudflare.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,19 @@ async function vectorizeWriteNdjson({
162162
body: form,
163163
})
164164
return (await res.json()) as any
165-
} catch {
166-
// Fallback for legacy indexes if needed.
165+
} catch (e) {
166+
// Only fall back when we strongly suspect this is a legacy (v1) index.
167+
// Falling back for transient errors makes v2 indexes fail with
168+
// `vectorize.incorrect_api_version`.
169+
const message = e instanceof Error ? e.message : String(e)
170+
const looksLikeLegacyIndex =
171+
/\b404\b/i.test(message) ||
172+
/not found/i.test(message) ||
173+
/legacy/i.test(message) ||
174+
/deprecated-v1/i.test(message)
175+
176+
if (!looksLikeLegacyIndex) throw e
177+
167178
const pathLegacy = `/vectorize/indexes/${indexName}/${operation}`
168179
const res = await cfFetch({ accountId, apiToken }, pathLegacy, {
169180
method: 'POST',

0 commit comments

Comments
 (0)