fix(memory): keep numpy scalars out of metadata and API JSON - #1846
Merged
3clyp50 merged 2 commits intoAug 23, 2026
Conversation
Memory consolidation stores FAISS relevance scores (numpy scalars) in document metadata. The values get pickled into the docstore and crash json.dumps with 'Object of type float32 is not JSON serializable' in helpers/api.py for handlers that return full metadata. Coerce scores to native floats at the source and serialize responses with default=float.
Jehu
force-pushed
the
fix/memory-float32-json-serialization
branch
from
August 21, 2026 06:57
4a93fbc to
c26ed80
Compare
Keep shared API serialization strict while converting legacy NumPy consolidation scores in the memory dashboard response. Add regressions for native relevance scores and legacy dashboard metadata without mutating stored documents.
Contributor
|
Thanks, the diagnosis and the source casts look right. I pushed follow-up commit I removed Legacy I added regression coverage for the cosine normalizer returning a native float, dashboard JSON serialization with a legacy Verification:
|
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.
Memory API handlers crashed with
TypeError: Object of type float32 is not JSON serializablewhenever they returned document metadata containing similarity scores (e.g. the Memory dashboard search returned a 500 instead of results).Root cause: memory consolidation stores FAISS relevance scores in
doc.metadata['_consolidation_similarity']. The scores are numpy scalars; they were pickled into the FAISS docstore and later failedjson.dumps()inApiHandler.handle_request.float.handle_requestserializes responses withjson.dumps(..., default=float), so a numpy scalar left anywhere in a handler payload can no longer produce a 500.Existing docstores keep their pickled numpy values until each document is rewritten; the
default=floatfallback keeps them JSON-serializable in the meantime. (Trade-off: a numpy integer in a payload serializes as a float, e.g.42.0; never observed in practice — only similarity floats carry numpy types.)Verification
usr/memory/default/index.pklcarried numpy_consolidation_similarityvalues.json.dumps.default=floatserializesnp.float32,np.float64, andnp.int64.python -m py_compileon the three changed files. No automated tests exist for these helpers, so validation was manual.