-
Notifications
You must be signed in to change notification settings - Fork 14.3k
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/SQLDatabase: Fetch mode cursor
, query parameters, query by selectable, expose execution options, and documentation
#16655
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
219e0a9
to
ef7805b
Compare
ef7805b
to
45649a8
Compare
916e376
to
194d257
Compare
b3df1b5
to
9cb633b
Compare
b62229c
to
96cfc1f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is this needed? feels like the on_text method should really just accept strings
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @baskaryan. This adjustment was needed to satisfy the mypy linter, to accompany the possibility that this can now also return a SQLAlchemy Result
object here, which would otherwise fail.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we just cast the output of SQLDatabase wherever it's passed to
on_text
instead of changing theon_text
method (since it doesn't actually support non-strings)?
Hi again. I just reverted this adjustment, and added a cast at a different spot like you suggested, on behalf of 08db71b (now squashed).
Edit: Looks good so far, the current linter failures on CI are unrelated, as they also appear on a run of a different PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After rebasing this patch on top of master
, it needed a few adjustments, which have been implemented now. Based on the CI outcome, the patch may receive another round of code reviews. Thank you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi again. It looks like @eyurtsev is taking over. Thank you so much!
cursor
, query parameters, query by selectable, expose execution options, and documentation
1ea8e4d
to
d3b6d59
Compare
d3b6d59
to
8003fb3
Compare
…ctable - Add `cursor` fetch mode - Make `_execute` accept query parameters - Accept both `str` or SQLAlchemy selectables for querying
Up until now, the `SQLDatabase` utility only has been demonstrated on behalf of the "toolkit integration" section, where it is about showcasing an agent designed to interact with an SQL database. [1] Contrary to that, this patch adds a documentation page exclusively dedicated to the SQLDatabase adapter utility, and its features. [1] https://python.langchain.com/docs/integrations/toolkits/sql_database
8003fb3
to
e4d2f3e
Compare
_run_manager.on_text(result, color="yellow", verbose=self.verbose) | ||
_run_manager.on_text(str(result), color="yellow", verbose=self.verbose) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we just cast the output of SQLDatabase wherever it's passed to
on_text
instead of changing theon_text
method.
@baskaryan: Your suggestion from #16655 (comment) has been implemented here. mypy is fine with that, and we do not need to touch anything in core
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems fine to me
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am wondering if this unit test file, together with test_sql_database_schema.py, should actually move into community/tests/unit_tests, following the logic of recent refactorings, and given that the files under test are also in community?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably yes, we can follow up in a separate PR
Reviewing and comandeering to adjust a few things in the API |
@amotl are you able to give me permissions to modify the head on the given branch? (it's an option you can enable when creating the PR) I fixed a breaking change due to lack of I left another review on the original PR to see if keyset pagination is an option (instead of relying on a cursor) |
Here is a PR that contains the proposed changes: https://github.com/langchain-ai/langchain/pull/17191/files, would prefer to push here so you can 👍 👎 the differences |
Hi @eyurtsev. Thanks for the review.
Is there a way to modify it on the PR afterwards? I admit I never recognized that option, apologies. In any case, I've added you to the list of contributors, where you may be able to accept it on the invitations page. Does that help already?
Thanks. I've looked at 4f3b063 and 806ba2e, and I appreciate your improvements. Now, I hope we will get the permission problem sorted out? |
I've just digested the documentation about Allowing changes to a pull request branch created from a fork, but I don't see the Allow edits from maintainers. or Allow edits and access to secrets by maintainers. options on the PR. Within the documentation, they refer to "forks owned by a personal account". Is that the reason it doesn't work, because this fork is on an organization account? |
Right, here we go -- it does not work:
Does that help you in any other way? |
Merged the other PR in. I'll read up on the links you sent to try and figure out if there's any other way to do this -- from what i understood it sounds like there's a difference between forks owned by individuals vs. forks owned by orgs |
Definitively, I appreciate it. Thanks!
Exactly. Apparently, repos owned by orgs do not offer that feature to permit upstream authors access to their PRs. Bummer! |
- **Description:** Improve test cases for `SQLDatabase` adapter component, see [suggestion](#16655 (review)). - **Depends on:** GH-16655 - **Addressed to:** @baskaryan, @cbornet, @eyurtsev _Remark: This PR is stacked upon GH-16655, so that one will need to go in first._ Edit: Thank you for bringing in GH-17191, @eyurtsev. This is a little aftermath, improving/streamlining the corresponding test cases.
…ai#16659) - **Description:** Improve test cases for `SQLDatabase` adapter component, see [suggestion](langchain-ai#16655 (review)). - **Depends on:** langchain-aiGH-16655 - **Addressed to:** @baskaryan, @cbornet, @eyurtsev _Remark: This PR is stacked upon langchain-aiGH-16655, so that one will need to go in first._ Edit: Thank you for bringing in langchain-aiGH-17191, @eyurtsev. This is a little aftermath, improving/streamlining the corresponding test cases.
…ai#16659) - **Description:** Improve test cases for `SQLDatabase` adapter component, see [suggestion](langchain-ai#16655 (review)). - **Depends on:** langchain-aiGH-16655 - **Addressed to:** @baskaryan, @cbornet, @eyurtsev _Remark: This PR is stacked upon langchain-aiGH-16655, so that one will need to go in first._ Edit: Thank you for bringing in langchain-aiGH-17191, @eyurtsev. This is a little aftermath, improving/streamlining the corresponding test cases.
- **Description:** A generic document loader adapter for SQLAlchemy on top of LangChain's `SQLDatabaseLoader`. - **Needed by:** crate-workbench#1 - **Depends on:** GH-16655 - **Addressed to:** @baskaryan, @cbornet, @eyurtsev Hi from CrateDB again, in the same spirit like GH-16243 and GH-16244, this patch breaks out another commit from crate-workbench#1, in order to reduce the size of this patch before submitting it, and to separate concerns. To accompany the SQLAlchemy adapter implementation, the patch includes integration tests for both SQLite and PostgreSQL. Let me know if corresponding utility resources should be added at different spots. With kind regards, Andreas. ### Software Tests ```console docker compose --file libs/community/tests/integration_tests/document_loaders/docker-compose/postgresql.yml up ``` ```console cd libs/community pip install psycopg2-binary pytest -vvv tests/integration_tests -k sqldatabase ``` ``` 14 passed ``` ![image](https://github.com/langchain-ai/langchain/assets/453543/42be233c-eb37-4c76-a830-474276e01436) --------- Co-authored-by: Andreas Motl <andreas.motl@crate.io>
…ai#18281) - **Description:** A generic document loader adapter for SQLAlchemy on top of LangChain's `SQLDatabaseLoader`. - **Needed by:** crate-workbench#1 - **Depends on:** langchain-aiGH-16655 - **Addressed to:** @baskaryan, @cbornet, @eyurtsev Hi from CrateDB again, in the same spirit like langchain-aiGH-16243 and langchain-aiGH-16244, this patch breaks out another commit from crate-workbench#1, in order to reduce the size of this patch before submitting it, and to separate concerns. To accompany the SQLAlchemy adapter implementation, the patch includes integration tests for both SQLite and PostgreSQL. Let me know if corresponding utility resources should be added at different spots. With kind regards, Andreas. ### Software Tests ```console docker compose --file libs/community/tests/integration_tests/document_loaders/docker-compose/postgresql.yml up ``` ```console cd libs/community pip install psycopg2-binary pytest -vvv tests/integration_tests -k sqldatabase ``` ``` 14 passed ``` ![image](https://github.com/langchain-ai/langchain/assets/453543/42be233c-eb37-4c76-a830-474276e01436) --------- Co-authored-by: Andreas Motl <andreas.motl@crate.io>
SQLDatabase
adapter component to promote code re-use, see suggestion.SQLDatabaseLoader
document loader #16246Details
cursor
fetch modestr
and SQLAlchemy selectables as query expressionexecution_options
SQLDatabase
1See About SQLDatabase.
Footnotes
Apparently there hasn't been any yet? ↩