Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions langchain_postgres/vectorstores.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,11 @@ def __init__(
doesn't exist. disabling creation is useful when using ReadOnly
Databases.
"""
warnings.warn(
"PGVector is deprecated. Please use PGVectorStore instead.",
DeprecationWarning,
stacklevel=2,
)
self.async_mode = async_mode
self.embedding_function = embeddings
self._embedding_length = embedding_length
Expand Down
31 changes: 31 additions & 0 deletions tests/unit_tests/v1/test_deprecation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

import warnings
from langchain_postgres.vectorstores import PGVector
from tests.unit_tests.fake_embeddings import FakeEmbeddings

def test_pgvector_deprecation_warning() -> None:
"""Test that PGVector raises a DeprecationWarning on initialization."""
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("always")

# We expect initialization to fail due to missing connection/DB,
# but the warning should be emitted *before* that.
# Or we can mock enough to make it succeed, but a try/except block
# is safer if we want to avoid dependency on a running DB.
try:
PGVector(
embeddings=FakeEmbeddings(),
connection="postgresql://user:pass@localhost:5432/db",
collection_name="test_deprecation",
# Disable side effects that try to connect immediately
create_extension=False,
# pre_delete_collection=False is default
)
except Exception:
# We don't care if it fails to connect, as long as it warned first
pass

# Check for the specific deprecation warning
assert len(w) > 0
assert issubclass(w[-1].category, DeprecationWarning)
assert "PGVector is deprecated" in str(w[-1].message)