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

Add deprecation warnings to postgres implementation that are in langchain-postgres.
This commit is contained in:
Eugene Yurtsev 2024-04-11 10:33:22 -04:00 committed by GitHub
parent f02f708f52
commit 22fd844e8a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 49 additions and 2 deletions

View File

@ -2,6 +2,7 @@ import json
import logging import logging
from typing import List from typing import List
from langchain_core._api import deprecated
from langchain_core.chat_history import BaseChatMessageHistory from langchain_core.chat_history import BaseChatMessageHistory
from langchain_core.messages import ( from langchain_core.messages import (
BaseMessage, BaseMessage,
@ -14,8 +15,25 @@ logger = logging.getLogger(__name__)
DEFAULT_CONNECTION_STRING = "postgresql://postgres:mypassword@localhost/chat_history" 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): 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__( def __init__(
self, self,

View File

@ -19,7 +19,7 @@ from typing import (
import numpy as np import numpy as np
import sqlalchemy 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 import SQLColumnExpression, delete, func
from sqlalchemy.dialects.postgresql import JSON, JSONB, UUID from sqlalchemy.dialects.postgresql import JSON, JSONB, UUID
from sqlalchemy.orm import Session, relationship from sqlalchemy.orm import Session, relationship
@ -209,9 +209,38 @@ def _results_to_docs(docs_and_scores: Any) -> List[Document]:
return [doc for doc, _ in docs_and_scores] 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): class PGVector(VectorStore):
"""`Postgres`/`PGVector` vector store. """`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. To use, you should have the ``pgvector`` python package installed.
Args: Args: