MCPcopy Index your code
hub / github.com/Effect-TS/effect / makeBatchedResolver

Function makeBatchedResolver

packages/ai/ai/src/EmbeddingModel.ts:167–187  ·  view source on GitHub ↗
(
  embedMany: (input: ReadonlyArray<string>) => Effect.Effect<Array<Result>, AiError.AiError>
)

Source from the content-addressed store, hash-verified

165}) {}
166
167const makeBatchedResolver = (
168 embedMany: (input: ReadonlyArray<string>) => Effect.Effect<Array<Result>, AiError.AiError>
169) =>
170 RequestResolver.makeBatched(
171 (requests: ReadonlyArray<EmbeddingRequest>) =>
172 embedMany(requests.map((request) => request.input)).pipe(
173 Effect.flatMap(
174 Effect.forEach(
175 ({ embeddings, index }) => Request.succeed(requests[index], embeddings),
176 { discard: true }
177 )
178 ),
179 Effect.catchAll((error) =>
180 Effect.forEach(
181 requests,
182 (request) => Request.fail(request, error),
183 { discard: true }
184 )
185 )
186 )
187 )
188
189/**
190 * Creates an EmbeddingModel service with batching and caching capabilities.

Callers 2

makeFunction · 0.85
makeDataLoaderFunction · 0.85

Calls 4

embedManyFunction · 0.85
pipeMethod · 0.65
mapMethod · 0.65
failMethod · 0.65

Tested by

no test coverage detected