Back
Open Source

When 0 means exact match: the n8n Weaviate distance bug

n8n #44028 fixed a three-character bug: options.maxVectorDistance || undefined turned a valid 0 into no limit. The fix uses nullish coalescing.

JB
Josué Barros
••2 min read

The Weaviate Vector Store node dropped a hybrid Max Vector Distance of 0. The config used options.maxVectorDistance || undefined. In JavaScript, 0 is falsy, so 0 became undefined and the search ran without a distance cap.

This is one of the pull requests behind Six merged PRs in 72 hours. The series looks at the failure, the fix and the review evidence, one merge at a time.

The change: +3 / -3 across 2 files. PR 44028.

The bug

A distance of 0 means exact vector matches only. Dropping it changes the result set from “the closest exact matches” to “anything the store considers close enough.” The user set a strict filter and the node silently removed it.

The existing test expected the dropped value. That is the second bug: the test encoded the broken behavior, so the suite stayed green while the product did the wrong thing.

Why it mattered

Vector distance is a retrieval contract. A zero cap is a valid, strict query. A falsy check that treats 0 as absent is a product decision hidden in syntax, and it is especially dangerous in search because the wrong result still looks plausible.

The fix

Use ?? undefined instead of || undefined. Nullish coalescing only falls back for null or undefined, so 0, the empty string and false survive. The PR changes the existing expectation to expect 0.

The evidence

The updated test fails on master and passes with the change. The review is small: three added lines, three removed. The proof is the expectation change, not a new abstraction.

What I would repeat

Use || for “any falsy value is absent” and ?? for “only null or undefined is absent.” If the domain has a meaningful zero, empty string or false, the distinction is a bug waiting to happen. Write the test with the valid zero, not just the happy path.

Sources

If this was useful, connect with me on LinkedIn; I write about the bugs behind merged pull requests and the evidence that gets them accepted.

FAQ

What was the n8n Weaviate bug?
A Max Vector Distance of 0 was treated as undefined, so the vector search ran without the distance cap the user configured.
Why does 0 matter?
In Weaviate, a distance of 0 means exact vector matches only. It is a valid, strict filter.
What is the fix?
Replace options.maxVectorDistance || undefined with options.maxVectorDistance ?? undefined, and assert that the store receives 0.
#n8n#weaviate#javascript#vector-search#open-source

Join the Newsletter

Subscribe to get my latest content by email.

We won't send you spam. Unsubscribe at any time.