MCPcopy Index your code
hub / github.com/CaviraOSS/OpenMemory / embedQueryForAllSectors

Function embedQueryForAllSectors

backend/src/memory/embed.ts:97–123  ·  view source on GitHub ↗
(
    query: string,
    sectors: string[],
)

Source from the content-addressed store, hash-verified

95 * API calls to a single batched call (~4.5x faster for deep tier).
96 */
97export 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)
126async function embed_with_provider(

Callers 1

hsg_queryFunction · 0.90

Calls 3

gen_syn_embFunction · 0.70
emb_geminiFunction · 0.70
embedForSectorFunction · 0.70

Tested by

no test coverage detected