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

Make langchain compatible with SQLAlchemy<1.4.0 #11390

Merged

Conversation

mhwang-stripe
Copy link
Contributor

@mhwang-stripe mhwang-stripe commented Oct 4, 2023

Description

Currently SQLAlchemy >=1.4.0 is a hard requirement. We are unable to run from langchain.vectorstores import FAISS with SQLAlchemy <1.4.0 due to top-level imports, even if we aren't even using parts of the library that use SQLAlchemy. See Testing section for repro. Let's make it so that langchain is still compatible with SQLAlchemy <1.4.0, especially if we aren't using parts of langchain that require it.

The main conflict is that SQLAlchemy removed declarative_base from sqlalchemy.ext.declarative in 1.4.0 and moved it to sqlalchemy.orm. We can fix this by try-catching the import. This is the same fix as applied in #883.

(I see that there seems to be some refactoring going on about isolating dependencies, e.g. c87e9fb, so if this issue will be eventually fixed by isolating imports in langchain.vectorstores that also works).

Issue

I can't find a matching issue.

Dependencies

No additional dependencies

Maintainer

@hwchase17 since you reviewed #883

Testing

I didn't add a test, but I manually tested this.

  1. Current failure:
langchain==0.0.305
sqlalchemy==1.3.24
python -i
>>> from langchain.vectorstores import FAISS
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/pay/src/zoolander/vendor3/lib/python3.8/site-packages/langchain/vectorstores/__init__.py", line 58, in <module>
    from langchain.vectorstores.pgembedding import PGEmbedding
  File "/pay/src/zoolander/vendor3/lib/python3.8/site-packages/langchain/vectorstores/pgembedding.py", line 10, in <module>
    from sqlalchemy.orm import Session, declarative_base, relationship
ImportError: cannot import name 'declarative_base' from 'sqlalchemy.orm' (/pay/src/zoolander/vendor3/lib/python3.8/site-packages/sqlalchemy/orm/__init__.py)
  1. This fix:
langchain==<this PR>
sqlalchemy==1.3.24
python -i
>>> from langchain.vectorstores import FAISS
<succeeds>

@vercel
Copy link

vercel bot commented Oct 4, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
langchain ⬜️ Ignored (Inspect) Visit Preview Oct 4, 2023 5:12pm

@dosubot dosubot bot added Ɑ: vector store Related to vector store module 🤖:improvement Medium size change to existing code to handle new use-cases labels Oct 4, 2023
@eyurtsev eyurtsev self-assigned this Oct 4, 2023
@eyurtsev eyurtsev self-requested a review October 4, 2023 19:36
@eyurtsev
Copy link
Collaborator

eyurtsev commented Oct 4, 2023

@mhwang-stripe the pyproject file pins sqlalchemy current to a min version of 1.4. I"ll merge the code as is, but folks may end up with issues installing due to pip dependency resolution. But we're planning on making sqlalchemy an optional dependency at some point soon.

@eyurtsev eyurtsev added the lgtm PR looks good. Use to confirm that a PR is ready for merging. label Oct 4, 2023
@eyurtsev eyurtsev merged commit 9cea796 into langchain-ai:master Oct 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🤖:improvement Medium size change to existing code to handle new use-cases lgtm PR looks good. Use to confirm that a PR is ready for merging. Ɑ: vector store Related to vector store module
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants