From 24bbde72771a9ac1754433273ea5afff53a9f871 Mon Sep 17 00:00:00 2001 From: Classic298 <27028174+Classic298@users.noreply.github.com> Date: Thu, 24 Sep 2026 10:38:33 +0200 Subject: [PATCH] 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 --- backend/open_webui/retrieval/external.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/backend/open_webui/retrieval/external.py b/backend/open_webui/retrieval/external.py index 1f0c06d8a7..269b6db8cd 100644 --- a/backend/open_webui/retrieval/external.py +++ b/backend/open_webui/retrieval/external.py @@ -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()