fix: vector serialization bug during PGLite to Postgres migration#97
Open
irresi wants to merge 2 commits intogarrytan:masterfrom
Open
fix: vector serialization bug during PGLite to Postgres migration#97irresi wants to merge 2 commits intogarrytan:masterfrom
irresi wants to merge 2 commits intogarrytan:masterfrom
Conversation
PGLite's pgvector extension returns embeddings as strings (e.g. "[0.1,0.2,...]") not Float32Array. During migration, Array.from(string) splits into individual characters, producing invalid vector literals that Postgres rejects. Two-layer fix: - Register custom type parser in PGLite initSchema for driver-level conversion - Add defensive parseEmbedding() in rowToChunk as safety net for all engines Fixes garrytan#91 Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Contributor
Author
Verifies embedding, tags, and timeline data survive bidirectional engine migration — the actual bug path for garrytan#91. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
4 tasks
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.

Summary
Fixes #91
PGLite's pgvector extension returns embeddings as strings (e.g.
"[0.1,0.2,...]"), notFloat32Array. During migration,Array.from(string)splits into individual characters, producing invalid vector literals like"[[,0,.,1,,,...]"that Postgres rejects.Root cause
rowToChunk()inutils.tscastsrow.embedding as Float32Array— a type assertion, not a conversionupsertChunks()callsArray.from(embedding).join(',')which destructures a string char-by-charFix (two layers)
pglite-engine.ts): Register a custom type parser for pgvector's dynamic OID ininitSchema(), so PGLite returnsFloat32Arraydirectly — matches Postgres engine behaviorutils.ts): AddparseEmbedding()inrowToChunk()that normalizesstring | Array | Float32Array→Float32Array, as a safety net for all enginesFiles changed
src/core/pglite-engine.ts—_vectorParsersfield, OID lookup ininitSchema, parser ingetChunksWithEmbeddingssrc/core/utils.ts—parseEmbedding()helper, used inrowToChunktest/pglite-engine.test.ts— 2 regression tests (type check + migration round-trip)Test plan
bun test test/pglite-engine.test.ts— 57 pass, 0 failbun test— 412 pass, 0 fail (1 pre-existing failure unrelated: missingmarkedpackage)bun run test:e2eagainst pgvector container — 81 pass, 0 fail🤖 Generated with Claude Code