Skip to content

Commit

Permalink
community[patch]: Add deprecation warnings to postgres implementation (
Browse files Browse the repository at this point in the history
…#20222)

Add deprecation warnings to postgres implementation that are in langchain-postgres.
  • Loading branch information
eyurtsev authored and hinthornw committed Apr 26, 2024
1 parent ad58b3f commit 269be35
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 2 deletions.
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

0 comments on commit 269be35

Please sign in to comment.