From 9ca1cf003cec61db147b2b473e71f82c974abe9c Mon Sep 17 00:00:00 2001 From: bradcrossen Date: Thu, 29 Jun 2023 16:49:35 -0500 Subject: [PATCH] Re-add Support for SQLAlchemy <1.4 (#6895) Support for SQLAlchemy 1.3 was removed in version 0.0.203 by change #6086. Re-adding support. - Description: Imports SQLAlchemy Row at class creation time instead of at init to support SQLAlchemy <1.4. This is the only breaking change and was introduced in version 0.0.203 #6086. A similar change was merged before: https://github.com/hwchase17/langchain/pull/4647 - Dependencies: Reduces SQLAlchemy dependency to > 1.3 - Tag maintainer: @rlancemartin, @eyurtsev, @hwchase17, @wangxuqi --------- Co-authored-by: rlm --- langchain/vectorstores/analyticdb.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/langchain/vectorstores/analyticdb.py b/langchain/vectorstores/analyticdb.py index 385d666f1ec..d8986aeffa2 100644 --- a/langchain/vectorstores/analyticdb.py +++ b/langchain/vectorstores/analyticdb.py @@ -7,7 +7,6 @@ from typing import Any, Dict, Iterable, List, Optional, Sequence, Tuple, Type from sqlalchemy import REAL, Column, String, Table, create_engine, insert, text from sqlalchemy.dialects.postgresql import ARRAY, JSON, TEXT -from sqlalchemy.engine import Row try: from sqlalchemy.orm import declarative_base @@ -260,6 +259,14 @@ class AnalyticDB(VectorStore): filter: Optional[dict] = None, ) -> List[Tuple[Document, float]]: # Add the filter if provided + try: + from sqlalchemy.engine import Row + except ImportError: + raise ImportError( + "Could not import Row from sqlalchemy.engine. " + "Please 'pip install sqlalchemy>=1.4'." + ) + filter_condition = "" if filter is not None: conditions = [