(options: {
/**
* A method which processes a batch of text inputs and returns embedding
* results.
*/
readonly embedMany: (input: ReadonlyArray<string>) => Effect.Effect<Array<Result>, AiError.AiError>
/**
* The duration between batch requests during which requests are collected and
* added to the current batch.
*/
readonly window: Duration.DurationInput
/**
* Optional maximum number of requests to add to the batch before a batch
* request must be sent.
*/
readonly maxBatchSize?: number
})
| 274 | * @category Constructors |
| 275 | */ |
| 276 | export const makeDataLoader = (options: { |
| 277 | /** |
| 278 | * A method which processes a batch of text inputs and returns embedding |
| 279 | * results. |
| 280 | */ |
| 281 | readonly embedMany: (input: ReadonlyArray<string>) => Effect.Effect<Array<Result>, AiError.AiError> |
| 282 | /** |
| 283 | * The duration between batch requests during which requests are collected and |
| 284 | * added to the current batch. |
| 285 | */ |
| 286 | readonly window: Duration.DurationInput |
| 287 | /** |
| 288 | * Optional maximum number of requests to add to the batch before a batch |
| 289 | * request must be sent. |
| 290 | */ |
| 291 | readonly maxBatchSize?: number |
| 292 | }) => |
| 293 | Effect.gen(function*() { |
| 294 | const resolver = makeBatchedResolver(options.embedMany) |
| 295 | const resolverDelayed = yield* dataLoader(resolver, { |
| 296 | window: options.window, |
| 297 | maxBatchSize: options.maxBatchSize |
| 298 | }) |
| 299 | |
| 300 | function embed(input: string) { |
| 301 | return Effect.request(new EmbeddingRequest({ input }), resolverDelayed).pipe( |
| 302 | Effect.withSpan("EmbeddingModel.embed", { captureStackTrace: false }) |
| 303 | ) |
| 304 | } |
| 305 | |
| 306 | function embedMany(inputs: ReadonlyArray<string>, options?: { |
| 307 | readonly concurrency?: Types.Concurrency | undefined |
| 308 | }) { |
| 309 | return Effect.forEach(inputs, embed, { batching: true, concurrency: options?.concurrency }).pipe( |
| 310 | Effect.withSpan("EmbeddingModel.embedMany", { captureStackTrace: false }) |
| 311 | ) |
| 312 | } |
| 313 | |
| 314 | return EmbeddingModel.of({ |
| 315 | embed, |
| 316 | embedMany |
| 317 | }) |
| 318 | }) |
no test coverage detected