feat: switch embeddings from Voyage AI to Google Gemini text-embedding-004
- embedText: call Gemini REST API (768-dim) instead of Voyage (1024-dim) - Migration: drop+recreate incidents.embedding as vector(768), update match_incidents function, swap VOYAGE_API_KEY → GOOGLE_AI_API_KEY in app_settings - Settings UI: relabel to "Google AI API Key (Embeddings)" - All call sites updated (incidents POST, similar GET) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CPf5Rc8QPx6V8KLEEgfKEQ
This commit is contained in:
@@ -18,7 +18,7 @@ export async function GET(
|
||||
if (!profile || !['hse', 'admin'].includes(profile.role))
|
||||
return NextResponse.json({ error: 'Forbidden' }, { status: 403 })
|
||||
|
||||
const voyageKey = await getApiKey(supabase, 'VOYAGE_API_KEY')
|
||||
const googleAiKey = await getApiKey(supabase, 'GOOGLE_AI_API_KEY')
|
||||
|
||||
const { data: incident } = await supabase
|
||||
.from('incidents')
|
||||
@@ -34,7 +34,7 @@ export async function GET(
|
||||
if (inc.embedding) {
|
||||
embeddingVec = JSON.parse(inc.embedding) as number[]
|
||||
} else {
|
||||
embeddingVec = await embedText(inc.description, voyageKey)
|
||||
embeddingVec = await embedText(inc.description, googleAiKey)
|
||||
// Closed incidents are locked at the DB level — the trigger would reject
|
||||
// this backfill. The vector still serves the similarity query below.
|
||||
if (inc.status !== 'closed') {
|
||||
|
||||
@@ -182,9 +182,9 @@ export async function POST(request: Request) {
|
||||
// Embed description asynchronously for future similarity search
|
||||
const supabaseForEmbed = supabase
|
||||
import('@/lib/settings').then(({ getApiKey }) =>
|
||||
getApiKey(supabaseForEmbed, 'VOYAGE_API_KEY').then(voyageKey =>
|
||||
getApiKey(supabaseForEmbed, 'GOOGLE_AI_API_KEY').then(googleAiKey =>
|
||||
import('@/lib/claude/embed').then(({ embedText }) =>
|
||||
embedText(input.description.trim(), voyageKey).then(embedding =>
|
||||
embedText(input.description.trim(), googleAiKey).then(embedding =>
|
||||
supabase.from('incidents').update({
|
||||
embedding: `[${embedding.join(',')}]` as unknown as string,
|
||||
}).eq('id', incident.id)
|
||||
|
||||
@@ -6,7 +6,7 @@ import { createClient } from '@/lib/supabase/server'
|
||||
const ALLOWED_KEYS = [
|
||||
'ANTHROPIC_API_KEY',
|
||||
'DEEPSEEK_API_KEY',
|
||||
'VOYAGE_API_KEY',
|
||||
'GOOGLE_AI_API_KEY',
|
||||
'META_WHATSAPP_PHONE_NUMBER_ID',
|
||||
'META_WHATSAPP_ACCESS_TOKEN',
|
||||
] as const
|
||||
|
||||
Reference in New Issue
Block a user