fix: send the query embedding as a vector in external pgvector retrieval

External knowledge bases on the pgvector provider failed on every search with "operator does not exist: vector <=> double precision[]", so they looked empty to users. This happened regardless of the VECTOR_DB setting.

The query embedding was bound as a plain Python list. register_vector only adapts pgvector's own Vector type and numpy arrays, so psycopg sent the list as a float array, which the <=> operator does not accept. Wrapping the embedding in pgvector.Vector sends it as a real vector.

Vector is imported from the package root, which works on the pinned pgvector 0.4.2 and on 0.5.x, where the pgvector.psycopg re-export no longer exists.

Verified against a pgvector Postgres: before the fix the reported error reproduces; after it, results come back ranked by cosine distance and filtered to the collection, including schema-qualified tables, halfvec columns and 1536-dimension embeddings.

Fixes #26663
This commit is contained in:
Classic298 2026-09-24 10:38:33 +02:00
parent bbfa876afd
commit 24bbde7277

View file

@ -208,6 +208,7 @@ async def _retrieve_milvus(connection, auth_config, knowledge, query, count, emb
async def _retrieve_pgvector(connection, auth_config, knowledge, query, count, embedding_function) -> list[dict]:
try:
import psycopg
from pgvector import Vector
from pgvector.psycopg import register_vector
from psycopg.rows import dict_row
except ImportError as exc:
@ -275,7 +276,7 @@ async def _retrieve_pgvector(connection, auth_config, knowledge, query, count, e
table_name=table_identifier,
collection=collection_identifier,
),
(vector, collection_name, count),
(Vector(vector), collection_name, count),
)
return cur.fetchall()