@mastra/fastembed 1.3.6-alpha.0 → 1.3.6-alpha.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.
package/dist/index.js CHANGED
@@ -18389,10 +18389,11 @@ function loadTokenizerFromDir(modelDir, maxLength) {
18389
18389
  const tokensMap = JSON.parse(fs.readFileSync(tokensMapPath, "utf-8"));
18390
18390
  const tokenizer = Tokenizer.fromFile(tokenizerPath);
18391
18391
  tokenizer.setTruncation(maxLength);
18392
+ const padToken = tokenizerConfig["pad_token"];
18392
18393
  tokenizer.setPadding({
18393
18394
  maxLength,
18394
18395
  padId: config["pad_token_id"],
18395
- padToken: tokenizerConfig["pad_token"]
18396
+ padToken: isAddedTokenMap(padToken) ? padToken.content : padToken
18396
18397
  });
18397
18398
  for (const token of Object.values(tokensMap)) if (typeof token === "string") tokenizer.addSpecialTokens([token]);
18398
18399
  else if (isAddedTokenMap(token)) {
@@ -18417,8 +18418,9 @@ function getRequiredOutput(outputs, outputName) {
18417
18418
  if (!tensor) throw new Error(`Expected model output "${outputName}" was not found. Available outputs: ${Object.keys(outputs).join(", ") || "(none)"}`);
18418
18419
  return tensor;
18419
18420
  }
18420
- function getOutputDimensions(outputName, tensor) {
18421
+ function getOutputDimensions(outputName, tensor, expectedBatchSize) {
18421
18422
  if (tensor.dims.length !== 3) throw new Error(`Expected model output "${outputName}" to have 3 dimensions, received [${tensor.dims.join(", ")}]`);
18423
+ if (tensor.dims[0] !== expectedBatchSize) throw new Error(`Expected model output "${outputName}" to have batch size ${expectedBatchSize}, received ${tensor.dims[0]}`);
18422
18424
  return tensor.dims;
18423
18425
  }
18424
18426
  var FlagEmbedding = class FlagEmbedding extends Embedding {
@@ -18531,7 +18533,7 @@ var FlagEmbedding = class FlagEmbedding extends Embedding {
18531
18533
  };
18532
18534
  if (this.model === "fast-multilingual-e5-large") delete inputs.token_type_ids;
18533
18535
  const lastHiddenState = getRequiredOutput(await this.session.run(inputs), "last_hidden_state");
18534
- yield getEmbeddings(lastHiddenState.data, getOutputDimensions("last_hidden_state", lastHiddenState), this.model === "fast-all-MiniLM-L6-v2" || this.model === "fast-multilingual-e5-large" ? maskArray : void 0).map(normalize);
18536
+ yield getEmbeddings(lastHiddenState.data, getOutputDimensions("last_hidden_state", lastHiddenState, batchTexts.length), this.model === "fast-all-MiniLM-L6-v2" || this.model === "fast-multilingual-e5-large" ? maskArray : void 0).map(normalize);
18535
18537
  }
18536
18538
  }
18537
18539
  passageEmbed(texts, batchSize = 256) {
@@ -18674,7 +18676,7 @@ var SparseTextEmbedding = class SparseTextEmbedding extends SparseEmbedding {
18674
18676
  };
18675
18677
  const outputTensor = getRequiredOutput(await this.session.run(inputs), "output");
18676
18678
  const logits = outputTensor.cpuData;
18677
- const [currentBatchSize, seqLen, currentVocabSize] = getOutputDimensions("output", outputTensor);
18679
+ const [currentBatchSize, seqLen, currentVocabSize] = getOutputDimensions("output", outputTensor, batchTexts.length);
18678
18680
  const sparseVectors = [];
18679
18681
  for (let batchIdx = 0; batchIdx < currentBatchSize; batchIdx++) {
18680
18682
  const valuesArr = new Float32Array(currentVocabSize).fill(0);