(
query: string,
sectors: string[],
)
| 95 | * API calls to a single batched call (~4.5x faster for deep tier). |
| 96 | */ |
| 97 | export async function embedQueryForAllSectors( |
| 98 | query: string, |
| 99 | sectors: string[], |
| 100 | ): Promise<Record<string, number[]>> { |
| 101 | // For hybrid/fast tiers, use synthetic embeddings (already fast) |
| 102 | if (tier === "hybrid" || tier === "fast") { |
| 103 | const result: Record<string, number[]> = {}; |
| 104 | for (const s of sectors) result[s] = gen_syn_emb(query, s); |
| 105 | return result; |
| 106 | } |
| 107 | |
| 108 | // For deep/smart tiers with Gemini, batch all sectors in ONE API call |
| 109 | if (env.emb_kind === "gemini" && env.gemini_key) { |
| 110 | try { |
| 111 | const txts: Record<string, string> = {}; |
| 112 | for (const s of sectors) txts[s] = query; |
| 113 | return await emb_gemini(txts); |
| 114 | } catch (e) { |
| 115 | console.warn(`[EMBED] Gemini batch failed, falling back to sequential: ${e}`); |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | // Fallback: sequential embedding for each sector |
| 120 | const result: Record<string, number[]> = {}; |
| 121 | for (const s of sectors) result[s] = await embedForSector(query, s); |
| 122 | return result; |
| 123 | } |
| 124 | |
| 125 | // Embed with a specific provider (throws on failure) |
| 126 | async function embed_with_provider( |
no test coverage detected