mirror of
https://github.com/langchain-ai/langchain-postgres.git
synced 2026-07-16 01:33:18 -04:00
PGVectorStore fails with GoogleGenerativeAIEmbeddings #86
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @sergiocharpineljr on GitHub (Aug 20, 2025).
Originally assigned to: @averikitsch on GitHub.
The code below fails with the following error:
Code:
Also tried with async versions of the methods but the error is the same.
@averikitsch commented on GitHub (Aug 22, 2025):
Thank you @sergiocharpineljr for the issue. I can confirm the error you are seeing.
A current work around is using the VertexAI library (https://pypi.org/project/langchain-google-vertexai/) with the same model like:
@onestardao commented on GitHub (Aug 23, 2025):
@sergiocharpineljr
The workaround with
VertexAIEmbeddingsonly sidesteps the issue it doesn’t fix the underlying incompatibility betweenGoogleGenerativeAIEmbeddingsand PGVectorStore. This maps to an embedding/vector-store mismatch (ProblemMap No.8). If you’d like the full checklist and root-cause fix steps (beyond provider switching), let me know and I can share the reference.@emekauser commented on GitHub (Sep 5, 2025):
I am having the same issue, it makes the migration from PGVector to PGVectorStore incomplete
@onestardao commented on GitHub (Sep 6, 2025):
@emekauser
This isn’t just a provider-side glitch — it’s an embedding–vectorstore contract mismatch (ProblemMap No.8).
Using
VertexAIEmbeddingssidesteps the GoogleGenerativeAIEmbeddings + PGVectorStore incompatibility, but it doesn’t really solve the underlying schema/metric drift.If you want the minimal checklist and the root-cause steps (beyond provider switching), let me know and I can share the reference.
@emekauser commented on GitHub (Sep 9, 2025):
Here is a working Example on how to use GoogleGenerativeEmbedding with PGVectorStore
_import os
import asyncpg
import asyncio
from langchain_postgres.utils.pgvector_migrator import alist_pgvector_collection_names, amigrate_pgvector_collection
from langchain_postgres import PGEngine, PGVectorStore, Column
from langchain.schema import Document
from langchain_google_genai import GoogleGenerativeAIEmbeddings
from dotenv import load_dotenv
load_dotenv()
db_name = os.getenv("DB_NAME")
db_user = os.getenv("DB_USER")
db_password = os.getenv("DB_PASSWORD")
db_host = os.getenv("DB_HOST")
if not db_name or not db_user or not db_password or not db_host:
raise ValueError(
"Database connection details are not set in the environment variables.")
VECTOR_SIZE = 3072
COLLECTION = "smart_ai_documents"
MODEL_NAME = "models/gemini-embedding-exp-03-07"
CONNECTION = f"postgresql+asyncpg://{db_user}:{db_password}@{db_host}:5432/{db_name}"
embedding = GoogleGenerativeAIEmbeddings(model=MODEL_NAME)
engine = PGEngine.from_connection_string(url=CONNECTION)
class VectorStoreInterface:
vector_store: PGVectorStore = None
embedding: GoogleGenerativeAIEmbeddings = None
@onestardao commented on GitHub (Sep 10, 2025):
@emekauser
Looks like you ran into a vectorstore contract mismatch — PGVector isn’t failing on its own, it’s the embedding→retrieval contract breaking (GoogleGenerativeAIEmbeddings vs PGVector indexing). That’s why the async patch above only sidesteps it.
I’ve been cataloguing these kinds of failures systematically. This one maps directly to the Global Fix Map (VectorDBs & Stores section):
👉 https://github.com/onestardao/WFGY/blob/main/ProblemMap/GlobalFixMap/README.md
If you want the short version:
enforce embedding dimension contracts (check at init, fail early if mismatch)
add a ΔS drift check between stored vectors vs query vectors
block ingestion when contracts fail, instead of letting it collapse silently
That way you don’t just patch for GoogleGenAI, you cover the same class of failures across FAISS, Qdrant, Redis, etc.