MCPcopy Index your code
hub / github.com/simstudioai/sim / buildGeminiProvider

Function buildGeminiProvider

apps/sim/lib/knowledge/embeddings.ts:160–180  ·  view source on GitHub ↗
(modelName: string, apiKey: string)

Source from the content-addressed store, hash-verified

158}
159
160function buildGeminiProvider(modelName: string, apiKey: string): ResolvedProvider['buildRequest'] {
161 return (inputs, inputType) => ({
162 apiUrl: `https://generativelanguage.googleapis.com/v1beta/models/${modelName}:batchEmbedContents`,
163 headers: {
164 'Content-Type': 'application/json',
165 'x-goog-api-key': apiKey,
166 },
167 body: {
168 requests: inputs.map((text) => ({
169 model: `models/${modelName}`,
170 content: { parts: [{ text }] },
171 taskType: inputType === 'query' ? 'RETRIEVAL_QUERY' : 'RETRIEVAL_DOCUMENT',
172 outputDimensionality: EMBEDDING_DIMENSIONS,
173 })),
174 },
175 parse: (json) => {
176 const data = json as { embeddings: Array<{ values: number[] }> }
177 return data.embeddings.map((item) => l2Normalize(item.values))
178 },
179 })
180}
181
182/**
183 * Returns the embedding model to use for new knowledge bases.

Callers 1

resolveProviderFunction · 0.85

Calls 1

l2NormalizeFunction · 0.85

Tested by

no test coverage detected