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

Function make

packages/ai/ai/src/EmbeddingModel.ts:199–263  ·  view source on GitHub ↗
(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>
  /**
   * Optional maximum number of text inputs to process in one batch.
   */
  readonly maxBatchSize?: number
  /**
   * Optional configuration to control how batch request results are cached.
   */
  readonly cache?: {
    /**
     * The capacity of the cache.
     */
    readonly capacity: number
    /**
     * The time-to-live for items in the cache.
     */
    readonly timeToLive: Duration.DurationInput
  }
})

Source from the content-addressed store, hash-verified

197 * @category Constructors
198 */
199export const make = (options: {
200 /**
201 * A method which processes a batch of text inputs and returns embedding
202 * results.
203 */
204 readonly embedMany: (input: ReadonlyArray<string>) => Effect.Effect<Array<Result>, AiError.AiError>
205 /**
206 * Optional maximum number of text inputs to process in one batch.
207 */
208 readonly maxBatchSize?: number
209 /**
210 * Optional configuration to control how batch request results are cached.
211 */
212 readonly cache?: {
213 /**
214 * The capacity of the cache.
215 */
216 readonly capacity: number
217 /**
218 * The time-to-live for items in the cache.
219 */
220 readonly timeToLive: Duration.DurationInput
221 }
222}) =>
223 Effect.gen(function*() {
224 const cache = yield* Option.fromNullable(options.cache).pipe(
225 Effect.flatMap((config) => Request.makeCache(config)),
226 Effect.optionFromOptional
227 )
228
229 const resolver = makeBatchedResolver(options.embedMany).pipe(
230 options.maxBatchSize ? RequestResolver.batchN(options.maxBatchSize) : identity
231 )
232
233 const embed = (input: string) => {
234 const request = Effect.request(new EmbeddingRequest({ input }), resolver)
235 return Option.match(cache, {
236 onNone: () => request,
237 onSome: (cache) =>
238 request.pipe(
239 Effect.withRequestCaching(true),
240 Effect.withRequestCache(cache)
241 )
242 })
243 }
244
245 const embedMany = (inputs: ReadonlyArray<string>, options?: {
246 readonly concurrency?: Types.Concurrency | undefined
247 }) =>
248 Effect.forEach(inputs, embed, {
249 batching: true,
250 concurrency: options?.concurrency
251 })
252
253 return EmbeddingModel.of({
254 embed: (input) =>
255 embed(input).pipe(
256 Effect.withSpan("EmbeddingModel.embed", { captureStackTrace: false })

Callers

nothing calls this directly

Calls 5

makeBatchedResolverFunction · 0.85
embedFunction · 0.85
embedManyFunction · 0.85
pipeMethod · 0.65
ofMethod · 0.65

Tested by

no test coverage detected