Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

community[patch]: Add deprecation warnings to postgres implementation #20222

Merged
merged 2 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import logging
from typing import List

from langchain_core._api import deprecated
from langchain_core.chat_history import BaseChatMessageHistory
from langchain_core.messages import (
BaseMessage,
Expand All @@ -14,8 +15,25 @@
DEFAULT_CONNECTION_STRING = "postgresql://postgres:mypassword@localhost/chat_history"


@deprecated(
since="0.0.31",
message=(
"This class is deprecated and will be removed in a future version. "
"You can swap to using the `PostgresChatMessageHistory`"
" implementation in `langchain_postgres`. "
"Please do not submit further PRs to this class."
"See https://github.com/langchain-ai/langchain-postgres"
),
alternative="from langchain_postgres import PostgresChatMessageHistory;",
pending=True,
)
class PostgresChatMessageHistory(BaseChatMessageHistory):
"""Chat message history stored in a Postgres database."""
"""Chat message history stored in a Postgres database.

**DEPRECATED**: This class is deprecated and will be removed in a future version.

Use the `PostgresChatMessageHistory` implementation in `langchain_postgres`.
"""

def __init__(
self,
Expand Down
31 changes: 30 additions & 1 deletion libs/community/langchain_community/vectorstores/pgvector.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import numpy as np
import sqlalchemy
from langchain_core._api import warn_deprecated
from langchain_core._api import deprecated, warn_deprecated
from sqlalchemy import SQLColumnExpression, delete, func
from sqlalchemy.dialects.postgresql import JSON, JSONB, UUID
from sqlalchemy.orm import Session, relationship
Expand Down Expand Up @@ -209,9 +209,38 @@ def _results_to_docs(docs_and_scores: Any) -> List[Document]:
return [doc for doc, _ in docs_and_scores]


@deprecated(
since="0.0.31",
message=(
"This class is pending deprecation and may be removed in a future version. "
"You can swap to using the `PGVector`"
" implementation in `langchain_postgres`. "
"Please read the guidelines in the doc-string of this class "
"to follow prior to migrating as there are some differences "
"between the implementations. "
"See https://github.com/langchain-ai/langchain-postgres for details about"
"the new implementation."
),
alternative="from langchain_postgres import PGVector;",
pending=True,
)
class PGVector(VectorStore):
"""`Postgres`/`PGVector` vector store.

**DEPRECATED**: This class is pending deprecation and will likely receive
no updates. An improved version of this class is available in
`langchain_postgres` as `PGVector`. Please use that class instead.

When migrating please keep in mind that:
* The new implementation works with psycopg3, not with psycopg2
(This implementation does not work with psycopg3).
* Filtering syntax has changed to use $ prefixed operators for JSONB
metadata fields. (New implementation only uses JSONB field for metadata)
* The new implementation made some schema changes to address issues
with the existing implementation. So you will need to re-create
your tables and re-index your data or else carry out a manual
migration.

To use, you should have the ``pgvector`` python package installed.

Args:
Expand Down