sql-pg: pgvector columns fail with "Invalid UTF-8 in text value"
I maintainer di solito rispondono entro 1 giorno
Valutazione
Questa issue non è ancora stata valutata.
Descrizione
What version of Effect is running?
4.1.2
What steps can reproduce the bug?
Versions used
effect4.1.2@effect/sql-pg4.1.2- Node.js 26, PostgreSQL 17.10 with pgvector 0.8.6 (
pgvector/pgvector:pg17image)
To reproduce
Run Postgres with pgvector:
docker run --rm -e POSTGRES_PASSWORD=password -p 55432:5432 pgvector/pgvector:pg17
Then run:
import { NodeRuntime } from '@effect/platform-node'
import { PgClient } from '@effect/sql-pg'
import { Effect, Redacted } from 'effect'
import { SqlClient } from 'effect/sql'
const program = Effect.gen(function* () {
const sql = yield* SqlClient.SqlClient
yield* sql`CREATE EXTENSION IF NOT EXISTS vector`
const pid = () =>
sql<{ pid: number }>`
SELECT
pg_backend_pid() AS pid
`.pipe(Effect.map(rows => rows[0]!.pid))
const before = yield* pid()
// 1. Most vectors are not valid UTF-8, so the query fails
const failure = yield* sql`
SELECT
'[1,2,3]'::vector AS embedding
`.pipe(Effect.flip)
console.log('1.', failure.message, failure.reason.cause)
// 2. The physical connection was dropped
console.log(`2. backend pid before: ${before}, after: ${yield* pid()}`)
// 3. Some vectors happen to be valid UTF-8, so they succeed and return their binary representation as a string
const garbled = yield* sql`
SELECT
'[0]'::vector AS v,
'[1,2,3]'::halfvec AS h
`
console.log('3.', garbled[0])
})
program.pipe(
Effect.provide(
PgClient.layer({
url: Redacted.make('postgres://postgres:password@localhost:55432/postgres'),
maxConnections: 1,
}),
),
NodeRuntime.runMain,
)
Output:
1. PgConnection: Failed to decode row { message: 'Invalid UTF-8 in text value', _tag: 'PgTypesCodecError' }
2. backend pid before: 70, after: 71
3. {
v: '\x00\x01\x00\x00\x00\x00\x00\x00',
h: '\x00\x03\x00\x00<\x00@\x00B\x00'
}
Expected behavior
Would have appreciated a more actionable message mentioning:
- the table/column causing the issue
- column not having registered codec
- that text decoding was a fallback
Accidentally valid UTF-8 succeeding here feels like a weird edge case. Failing early from a lack of codec would mean less surprises.
Workaround
Workaround we used:
SELECT embedding::text AS embedding FROM ...
Claude also came up with this:
Registering a codec after looking up the OID at runtime.
const types = PgTypes.makeRegistry() // passed as PgClient.layer({ types })
const [{ oid }] =
yield *
sql<{ oid: number }>`
SELECT
oid::int AS oid
FROM
pg_type
WHERE
typname = 'vector'
`
types.register(oid, {
encode: () => Result.fail(new PgTypes.CodecError({ message: 'Not implemented' })),
decode: bytes => {
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength)
const dim = view.getUint16(0)
return Result.succeed(Array.from({ length: dim }, (_, i) => view.getFloat32(4 + i * 4)))
},
})
// SELECT '[1,2,3]'::vector → [1, 2, 3]
Related: #8237, #8240, #8304.
- Lingua principale
- TypeScript
- Stelle
- 16.7k
- Fork
- 808
- Merge medio
- 11h 40m
- PR unite (30g)
- 827
Preparare l'ambiente
Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di Effect-TS/effect
-
cli: completions break for subcommand names with `:`Forse già presa @effect-bot l’ha presa 1 giorno fa. Aperta
Effect-TS/effect#10416 · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
McpServer.layerStdio: native EOF cancellation policy for active tool handlersForse già presa @effect-bot l’ha presa 1 giorno fa. Aperta
Effect-TS/effect#10412 · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
add OAuth authorization support to HTTP McpServerForse già presa @effect-bot l’ha presa 1 giorno fa. Apertaenhancement
Effect-TS/effect#10402 · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
effect/ai: support the MCP Apps extension (`io.modelcontextprotocol/ui`)Forse già presa @effect-bot l’ha presa 1 giorno fa. Aperta
Effect-TS/effect#10399 · 2 commenti · 1 reazione · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
Support `format: "password"` as `Redacted` in JSON Schema import/export and the OpenAPI generatorForse già presa @effect-bot l’ha presa 1 giorno fa. Apertaenhancement
Effect-TS/effect#10394 · 2 commenti · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di Effect-TS/effect
Issue simili
-
The sample email preview's ResizeObserver is never disconnected and keeps raising errors after leaving SettingsForse già presa Una pull request collegata a questa issue è aperta o già unita. Apertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
I maintainer di solito rispondono entro 1 giorno
-
area:ui bug effort:S priority:P2
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno
-
Typo in WSL project description on Projects pageForse già presa @akhil9tiet l’ha presa oggi. Aperta
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 75/100
microsoft/opensource.microsoft.com#1066 · 1 commento ·
-
ArcGIS Maps SDK for JavaScript c-carousel calcite-design-tokens enhancement impact - p3 - not time sensitive needs triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
Esri/calcite-design-system#15565 ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
linkwarden/linkwarden#1891 ·
I maintainer di solito rispondono entro 1 giorno