Fix Vector<float[]> serialization + non-generic enumeration with FloatVectorizer (#566)#569
Merged
Merged
Conversation
The Write path in VectorJsonConverter guarded the flat-array branch for a
FloatVectorizer with `value is Vector<double[]>`, which is never true for a
Vector<float[]>. As a result the embedding was written as an object
({"Value":...,"Vector":[...]}) instead of a flat array, while the index
(correctly) points the bare path at a VECTOR field. RediSearch could not
extract a vector from the object, so the document failed to index
(hash_indexing_failures) and every search - including the unfiltered
enumeration IRedisCollection<T> issues - returned empty even though the
document was present in Redis.
Correct the type guard to Vector<float[]> and add a functional regression
test covering insert + plain enumeration + zero indexing failures.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
🛡️ Jit Security Scan Results✅ No security findings were detected in this PR
Security scan by Jit
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #566.
A model using
Vector<float[]>with[FloatVectorizer]returned to a GraphQL layer (Hot Chocolate) came back as an empty collection even though the document was present in Redis. Investigation turned up two independent bugs, both fixed here.1.
Vector<float[]>serialized as an object instead of a flat arrayIn
VectorJsonConverter.Write, the flat-array fast path for aFloatVectorizerwas guarded by:For a
Vector<float[]>,value is Vector<double[]>is always false, so the embedding fell through to the generic path and was written as a structured object:But for a
FloatVectorizerthe index points the bare path ($.Vec AS Vec VECTOR …) at the field. RediSearch can't extract a vector from an object, so the document failed to index (hash_indexing_failuresincrements,num_docsstays 0) —JSON.SETstill succeeds, which is why the data is visible in the console but absent from every search. TheReadpath already assumesVector<float[]>, confirming theWriteguard was a copy/paste bug.Fix: correct the guard to
value is Vector<float[]>.2. Non-generic
IEnumerable.GetEnumerator()always threwRedisCollection's explicitIEnumerable.GetEnumerator()routed throughProvider.Execute<IEnumerable>(Expression), which only implements scalar terminal operators (First/Sum/Count/…) and threwNotImplementedExceptionfor every enumeration shape. Hot Chocolate enumerates resolver results through the non-genericIEnumerableinterface, so handing it the collection as anIQueryablealways failed — independent of the vector field.Fix: defer to the generic
GetEnumerator()(the canonicalforeach/.ToList()path).Validation
Reproduced the reporter's exact setup locally (ASP.NET Core + Hot Chocolate, the issue's
Floatermodel, referencing the local build). Before: stored{"Value":...,"Vector":[...]},num_docs 0,hash_indexing_failures 1, GraphQL{"floaters":[]}. After: stored[0.1,0.2],num_docs 1,0failures, GraphQL returns the document.Tests
FloatVectorIsIndexedAndEnumerable— inserts aVector<float[]>+[FloatVectorizer]doc (a combo with zero prior coverage), assertshash_indexing_failures == 0, and asserts a plain enumeration returns it.EnumeratesThroughNonGenericIEnumerable— enumerates a collection (bare andWhere-filtered) through the non-genericIEnumerableinterface.Both verified to fail on the old code and pass with the fixes.
🤖 Generated with Claude Code