modelfusion 0.55.0 → 0.55.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -12,6 +12,10 @@ export interface EmbeddingModel<VALUE, SETTINGS extends EmbeddingModelSettings =
12
12
  * Limit of how many values can be sent in a single API call.
13
13
  */
14
14
  readonly maxValuesPerCall: number | undefined;
15
+ /**
16
+ * True if the model can handle multiple embedding calls in parallel.
17
+ */
18
+ readonly isParallizable: boolean;
15
19
  doEmbedValues(values: VALUE[], options?: FunctionOptions): PromiseLike<{
16
20
  response: unknown;
17
21
  embeddings: Vector[];
@@ -41,7 +41,18 @@ function embedMany(model, values, options) {
41
41
  valueGroups.push(values.slice(i, i + maxValuesPerCall));
42
42
  }
43
43
  }
44
- const responses = await Promise.all(valueGroups.map((valueGroup) => model.doEmbedValues(valueGroup, options)));
44
+ // call the model for each group:
45
+ let responses;
46
+ if (model.isParallizable) {
47
+ responses = await Promise.all(valueGroups.map((valueGroup) => model.doEmbedValues(valueGroup, options)));
48
+ }
49
+ else {
50
+ responses = [];
51
+ for (const valueGroup of valueGroups) {
52
+ const response = await model.doEmbedValues(valueGroup, options);
53
+ responses.push(response);
54
+ }
55
+ }
45
56
  const rawResponses = responses.map((response) => response.response);
46
57
  const embeddings = [];
47
58
  for (const response of responses) {
@@ -38,7 +38,18 @@ export function embedMany(model, values, options) {
38
38
  valueGroups.push(values.slice(i, i + maxValuesPerCall));
39
39
  }
40
40
  }
41
- const responses = await Promise.all(valueGroups.map((valueGroup) => model.doEmbedValues(valueGroup, options)));
41
+ // call the model for each group:
42
+ let responses;
43
+ if (model.isParallizable) {
44
+ responses = await Promise.all(valueGroups.map((valueGroup) => model.doEmbedValues(valueGroup, options)));
45
+ }
46
+ else {
47
+ responses = [];
48
+ for (const valueGroup of valueGroups) {
49
+ const response = await model.doEmbedValues(valueGroup, options);
50
+ responses.push(response);
51
+ }
52
+ }
42
53
  const rawResponses = responses.map((response) => response.response);
43
54
  const embeddings = [];
44
55
  for (const response of responses) {
@@ -51,6 +51,12 @@ class CohereTextEmbeddingModel extends AbstractModel_js_1.AbstractModel {
51
51
  writable: true,
52
52
  value: 96
53
53
  });
54
+ Object.defineProperty(this, "isParallizable", {
55
+ enumerable: true,
56
+ configurable: true,
57
+ writable: true,
58
+ value: true
59
+ });
54
60
  Object.defineProperty(this, "embeddingDimensions", {
55
61
  enumerable: true,
56
62
  configurable: true,
@@ -43,6 +43,7 @@ export declare class CohereTextEmbeddingModel extends AbstractModel<CohereTextEm
43
43
  readonly provider: "cohere";
44
44
  get modelName(): "embed-english-light-v2.0" | "embed-english-v2.0" | "embed-multilingual-v2.0";
45
45
  readonly maxValuesPerCall = 96;
46
+ readonly isParallizable = true;
46
47
  readonly embeddingDimensions: number;
47
48
  readonly contextWindowSize: number;
48
49
  private readonly tokenizer;
@@ -48,6 +48,12 @@ export class CohereTextEmbeddingModel extends AbstractModel {
48
48
  writable: true,
49
49
  value: 96
50
50
  });
51
+ Object.defineProperty(this, "isParallizable", {
52
+ enumerable: true,
53
+ configurable: true,
54
+ writable: true,
55
+ value: true
56
+ });
51
57
  Object.defineProperty(this, "embeddingDimensions", {
52
58
  enumerable: true,
53
59
  configurable: true,
@@ -42,6 +42,12 @@ class HuggingFaceTextEmbeddingModel extends AbstractModel_js_1.AbstractModel {
42
42
  writable: true,
43
43
  value: void 0
44
44
  });
45
+ Object.defineProperty(this, "isParallizable", {
46
+ enumerable: true,
47
+ configurable: true,
48
+ writable: true,
49
+ value: true
50
+ });
45
51
  Object.defineProperty(this, "contextWindowSize", {
46
52
  enumerable: true,
47
53
  configurable: true,
@@ -38,6 +38,7 @@ export declare class HuggingFaceTextEmbeddingModel extends AbstractModel<Hugging
38
38
  readonly provider = "huggingface";
39
39
  get modelName(): string;
40
40
  readonly maxValuesPerCall: number;
41
+ readonly isParallizable = true;
41
42
  readonly contextWindowSize: undefined;
42
43
  readonly embeddingDimensions: number | undefined;
43
44
  readonly tokenizer: undefined;
@@ -39,6 +39,12 @@ export class HuggingFaceTextEmbeddingModel extends AbstractModel {
39
39
  writable: true,
40
40
  value: void 0
41
41
  });
42
+ Object.defineProperty(this, "isParallizable", {
43
+ enumerable: true,
44
+ configurable: true,
45
+ writable: true,
46
+ value: true
47
+ });
42
48
  Object.defineProperty(this, "contextWindowSize", {
43
49
  enumerable: true,
44
50
  configurable: true,
@@ -47,6 +47,9 @@ class LlamaCppTextEmbeddingModel extends AbstractModel_js_1.AbstractModel {
47
47
  get modelName() {
48
48
  return null;
49
49
  }
50
+ get isParallizable() {
51
+ return this.settings.isParallizable ?? false;
52
+ }
50
53
  async tokenize(text) {
51
54
  return this.tokenizer.tokenize(text);
52
55
  }
@@ -6,12 +6,14 @@ import { EmbeddingModel, EmbeddingModelSettings } from "../../model-function/emb
6
6
  export interface LlamaCppTextEmbeddingModelSettings extends EmbeddingModelSettings {
7
7
  api?: ApiConfiguration;
8
8
  embeddingDimensions?: number;
9
+ isParallizable?: boolean;
9
10
  }
10
11
  export declare class LlamaCppTextEmbeddingModel extends AbstractModel<LlamaCppTextEmbeddingModelSettings> implements EmbeddingModel<string, LlamaCppTextEmbeddingModelSettings> {
11
12
  constructor(settings?: LlamaCppTextEmbeddingModelSettings);
12
13
  readonly provider: "llamacpp";
13
14
  get modelName(): null;
14
15
  readonly maxValuesPerCall = 1;
16
+ get isParallizable(): boolean;
15
17
  readonly contextWindowSize: undefined;
16
18
  readonly embeddingDimensions: number | undefined;
17
19
  private readonly tokenizer;
@@ -44,6 +44,9 @@ export class LlamaCppTextEmbeddingModel extends AbstractModel {
44
44
  get modelName() {
45
45
  return null;
46
46
  }
47
+ get isParallizable() {
48
+ return this.settings.isParallizable ?? false;
49
+ }
47
50
  async tokenize(text) {
48
51
  return this.tokenizer.tokenize(text);
49
52
  }
@@ -57,6 +57,12 @@ class OpenAITextEmbeddingModel extends AbstractModel_js_1.AbstractModel {
57
57
  writable: true,
58
58
  value: 2048
59
59
  });
60
+ Object.defineProperty(this, "isParallizable", {
61
+ enumerable: true,
62
+ configurable: true,
63
+ writable: true,
64
+ value: true
65
+ });
60
66
  Object.defineProperty(this, "embeddingDimensions", {
61
67
  enumerable: true,
62
68
  configurable: true,
@@ -41,6 +41,7 @@ export declare class OpenAITextEmbeddingModel extends AbstractModel<OpenAITextEm
41
41
  readonly provider: "openai";
42
42
  get modelName(): "text-embedding-ada-002";
43
43
  readonly maxValuesPerCall = 2048;
44
+ readonly isParallizable = true;
44
45
  readonly embeddingDimensions: number;
45
46
  readonly tokenizer: TikTokenTokenizer;
46
47
  readonly contextWindowSize: number;
@@ -52,6 +52,12 @@ export class OpenAITextEmbeddingModel extends AbstractModel {
52
52
  writable: true,
53
53
  value: 2048
54
54
  });
55
+ Object.defineProperty(this, "isParallizable", {
56
+ enumerable: true,
57
+ configurable: true,
58
+ writable: true,
59
+ value: true
60
+ });
55
61
  Object.defineProperty(this, "embeddingDimensions", {
56
62
  enumerable: true,
57
63
  configurable: true,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "modelfusion",
3
3
  "description": "Build multimodal applications, chatbots, and agents with JavaScript and TypeScript.",
4
- "version": "0.55.0",
4
+ "version": "0.55.1",
5
5
  "author": "Lars Grammel",
6
6
  "license": "MIT",
7
7
  "keywords": [