Chat with MySQL Database with Python | LangChain Tutorial

2024 ж. 23 Ақп.
25 318 Рет қаралды

Discover how to interact with a MySQL database using Python and LangChain in our latest tutorial. This comprehensive guide walks you through the process of creating a LangChain chain, detailing every step with a helpful diagram for a clearer understanding. Whether you're a beginner or an experienced developer, this video will equip you with the knowledge to execute SQL queries using an innovative approach.
IMPORTANT: Remember to NOT use a MySQL user with WRITE privileges. Use only READ and limit the scope. Otherwise your user could ask your chain to delete data.
USEFUL LINKS:
📌 Article (follow along): alejandro-ao.com/chat-with-mysql-using-python-and-langchain/
📊 Chinook database: github.com/lerocha/chinook-database
💬 Join the Discord Help Server: link.alejandro-ao.com/HrFKZn
❤️ Buy me a coffee... or a beer (thanks): link.alejandro-ao.com/l83gNq
Timestamps:
0:00 Intro
1:02 How this works
2:59 Our test data
4:58 Load the test data
6:47 Notebook setup
9:23 Create SQL Chain Prompt
13:00 Load MySQL Database in Python
17:01 Create SQL Chain
26:02 Create run_query Function & Final Prompt
29:45 Create Full Chain
35:54 Conclusion
In this tutorial, you'll learn:
- How to set up LangChain to communicate with a MySQL database.
- The intricacies of creating and utilizing SQL queries within LangChain.
- Implementing a full chain that includes SQL query generation and natural language response construction.
- Best practices for interacting with databases using Python and LangChain.
Key Highlights:
- LangChain Integration: Learn how to create a LangChain chain for database queries.
- SQL Query Generation: Understand the process behind generating SQL queries from natural language questions.
- Interactive Diagram: A detailed diagram explains the architecture and process flow.
- Comprehensive Code Walkthrough: From setting up your environment to executing queries, every step is covered.
Who Should Watch?
This tutorial is perfect for developers, data scientists, and tech enthusiasts interested in leveraging LangChain for database interactions. Whether you're looking to enhance your projects or explore new technologies, this guide has something for everyone.
Stay Connected: Don't forget to subscribe to our channel for more tutorials on cutting-edge technologies. Join our Discord server for community discussions and updates. Join us here.
Happy Coding! 🚀

Пікірлер
  • Awesome. Looking forward to part 2....

    @student7261@student72612 ай бұрын
  • Dude, incredible tutorial, right on the money for what i needed.

    @tannerdio333@tannerdio33320 күн бұрын
  • Nice, looking forward to part 2!

    @1sanak@1sanak2 ай бұрын
    • Coming soon! 😎

      @alejandro_ao@alejandro_ao2 ай бұрын
  • This is a great tutorial. Thanks for explaining it in a way that's easy to understand

    @teddyperera8531@teddyperera85313 күн бұрын
  • Loving this video, Alejandro! 2 things I'd like to add: 1. I removed the {schema} part from the full_chain prompt and it works great. Only the sql_chain needs schema (to produce the sql query). 2. Your website is down :( Thanks for explaining every bit of your code so well!

    @krisograbek@krisograbek2 ай бұрын
  • Thanks for including MySQL and not just SQLite.

    @davidtindell950@davidtindell9502 ай бұрын
    • sure :)

      @alejandro_ao@alejandro_ao2 ай бұрын
  • I really love your tutorials, you are teaching us to create such powerful AI tools in Python that are really useful. I'm surprised that you have only 26K subscribers, you should have millions.

    @imranonthenet@imranonthenet2 ай бұрын
    • thank you man! i hope i will get there someday!

      @alejandro_ao@alejandro_ao2 ай бұрын
  • Love to watch your tutorials. It's very details.

    @heaton922@heaton9222 ай бұрын
    • thanks! keep it up!

      @alejandro_ao@alejandro_ao2 ай бұрын
  • Amazing Video. Great job

    @wg5920@wg5920Ай бұрын
  • Thanks Alejandro!

    @jatinnandwani6678@jatinnandwani66782 ай бұрын
    • Thank you man, you are amazing

      @alejandro_ao@alejandro_ao2 ай бұрын
  • First time here and I'm glad I gound your channel.Thanks for sharing!

    @funmiemore194@funmiemore1942 ай бұрын
    • hey there! welcome to the channel :) very happy to have you here :)

      @alejandro_ao@alejandro_ao2 ай бұрын
    • @@alejandro_ao Thanks!!

      @funmiemore194@funmiemore1942 ай бұрын
  • Hi, I reviewed this "Chat with MySQL DB" tutorial yet again and decided to try a more difficult SQL query: "determine the most popular artist in the database based upon total sales.". Of course, I manually ran the full Select -- with three table joins -- to make sure that this new query would work and produce the correct answer(s). To my surprise, the "natural language query" was properly processed by my modified version of your program and produced the correct response: " Iron Maiden with total sales of $138.60 " ! To further test the program, I changed the question to "top three most popular artists". The correct result was again returned: "Iron Maiden, U2, and Metallica" ! Glad to see 'U2' near the top ! Since "langchain-openai" is only at version 0.0.8 and "SQLDatabase" at 0.0.26, we may expect even more NLP Query improvements in the near future [i.e., if 'Altman' & 'Musk' do not mess everything up for all of us !?!]. P.S. Looking forward to the next MySQL vid(s) that you post !

    @davidtindell950@davidtindell9502 ай бұрын
    • I got an error when I tried your first query - the query was correct (validated in database) but it was prepended by "sql" like this: [SQL: ```sql SELECT a.Name AS Artist, SUM(il.UnitPrice * il.Quantity) AS TotalSales FROM Artist a JOIN Album al ON a.ArtistId = al.ArtistId JOIN Track t ON al.AlbumId = t.AlbumId JOIN InvoiceLine il ON t.TrackId = il.TrackId JOIN Invoice i ON il.InvoiceId = i.InvoiceId GROUP BY a.Name ORDER BY TotalSales DESC LIMIT 1; ```]

      @EricLofland@EricLofland2 ай бұрын
    • @@EricLofland Thank You! For the feedback. The natural language query worked well for me and ChatGPT4 validated the SQL Query. I have since moved on to testing SQLite and also saving query vectors in ChromaDB. Later, I will try to re-check and reproduce the MySQL Database query and compare it to your results.

      @davidtindell950@davidtindell9502 ай бұрын
    • ​@@EricLofland I reset my laptop for my extension of Alejandro's "Chat with MySQL" Python program. It ran as before and produced both the SQL and Natural Language Query. SQL: run_query("select artist.Name AS ArtistName, COUNT(*) AS TotalSales from \ invoiceline join track on invoiceline.TrackId = track.TrackId \ join album on track.AlbumId = album.AlbumId \ join artist on album.ArtistId = artist.ArtistId \ group by artist.Name order by TotalSales desc limit 3;") NLQ: user_question = 'determine the top three most popular artists in the database based upon total sales.' BOTH Results were very similar: "'The top three most popular artists in the database based on total sales are Iron Maiden with $138.60, U2 with $105.93, and Metallica with $90.09.". Further, I researched any conditions under which "sql" would be prepended to the SELECT statement. I did NOT find any examples of this artifact, however, I did find a good very recent "Medium" article on this subject by " Senthil E " at " levelup.gitconnected.com/llms-meet-sql-revolutionizing-data-querying-with-natural-language-processing-52487337f043 ". As we say "Hope This Helps!" and thanks again for your detailed feedback.

      @davidtindell950@davidtindell9502 ай бұрын
    • @@davidtindell950 Are you writing up any of your experiments/tests? I'd be interested in seeing the caching of queries and responses into a vector database.

      @warrenmarkham8891@warrenmarkham88912 ай бұрын
    • ​@@warrenmarkham8891 Hi, I expect to write a new "Medium" article fairly soon, however, I am still currently continuing my R&D. In addition to Alejandro's excellent tutorials, I have found another good tutorial that includes the employment of PyTorch for fast processing of large vector databases: " Maximize ChromaDB Embedding Vectorization Speed with NVidia CUDA GPU and Python Multiprocessing " " Johnny Code " " kzhead.info/sun/aqqvlNuvraOod2w/bejne.html " and " kzhead.info/sun/aqqvlNuvraOod2w/bejne.htmlsi=a18-dKxTYk2UvRMT ". Also, there are several good current "Medium" articles available on this research subject.

      @davidtindell950@davidtindell9502 ай бұрын
  • Love your videos, started watching all your langchain and it really has helped me and I wanted to say thanks. I would also like to see the use of agents if it isnt too much to ask

    @adnank4980@adnank49802 ай бұрын
    • hey there! thank you for telling me this :) keep it up and keep learning 🚀 i'll bring up agents here very soon!

      @alejandro_ao@alejandro_ao2 ай бұрын
  • Great stuff! Many thanks 💪

    @artislove491@artislove4912 ай бұрын
    • No problem 👍

      @alejandro_ao@alejandro_ao2 ай бұрын
  • I love your content, thanks for all your efforts ❤

    @mazinzain7121@mazinzain71212 ай бұрын
    • i appreciate it! let me know what you want to see next

      @alejandro_ao@alejandro_ao2 ай бұрын
  • Hi Alejandro. Great post! It helped me a lot. I was trying to find a Gemini alternative to a solution that I learned from a Udemy course, using LangChain and OpenAI Agents to access a SQLite database and pass the results to the OpenAI LLM. I searched for days and found nothing, until I saw your video. Now my code is running and I can see many possibilities for accessing enterprise databases to enable users to obtain results using generative AI. Thank you and greetings from Brazil.

    @msssouza2@msssouza210 күн бұрын
  • Your videos are the best!

    @bwilliams060@bwilliams0602 ай бұрын
    • you are the best

      @alejandro_ao@alejandro_ao2 ай бұрын
  • Thank you so much for this video, this is really helpful!! Looking forward to using huggingface models

    @chibuzoemelike6403@chibuzoemelike64032 ай бұрын
    • Great! Which models in particular are you interested in?

      @alejandro_ao@alejandro_ao2 ай бұрын
    • Mistral AI

      @palanikumarmsc@palanikumarmsc12 күн бұрын
  • Thank you for your videos. As a subscriber to your channel, I look forward to each new one. I would like to make a comment, and perhaps a suggestion for a future video. As a Finance Manager for the last 40+ years, I have come to find these three areas important as it relates to the retrieval of information. What every office need is a way to search: 1) URL's , EXCEL, and PDF on the internet. 2) EXCEL and CSV files locally. (and Securely) 3) PDF and DOC documents locally. (and Securely) And nowadays, you could never get a NON GUI program adopted by the office staff. And of course, all three of the search types would be incorporated into the same GUI. Python based program would be the preferred language. OLLAMA based. NO DOCKER. No wrapper programs like streamlit, etc. Thanks for your time, and keep up the good work.

    @dgm1949@dgm19492 ай бұрын
    • Hey there, thanks for following the channel and for your suggestions! I see what you mean and agree that in order to get an app adopted internally, it should be very straightforward and easy to use. However, I don't see why it shouldn't use streamlit? Streamlit is just a way to build the GUI in a few lines of code. And if what you are interested in is the privacy, you can totally host it internally and have your data never leave your network.

      @alejandro_ao@alejandro_ao2 ай бұрын
  • great as always bro

    @sam-uw3gf@sam-uw3gf2 ай бұрын
    • thank you bro

      @alejandro_ao@alejandro_ao2 ай бұрын
  • Thanks. What about long ot short term memory during conversation?

    @angelsmobile7876@angelsmobile78762 ай бұрын
  • Thanks for useful video)

    @natawebmaster@natawebmaster2 ай бұрын
    • it's my pleasure :)

      @alejandro_ao@alejandro_ao2 ай бұрын
  • Hey, thanks for the video. However, few questions if you don't mind: 1. Do we need to assign the sql_chain inputs again when building a full_chain ? Won't it remember from its own structure. I see that as complexity grows, we end up adding a whole bunch of assignment in full chain. 2. For full chain, is there a way to use pipe operator to let the sql_chain response be passed to the next step where you run_query ? Basically, RunnablePassthrough.assign(sql_chain) | run_query | prompt | llm | StrOutput... ? Thanks again for your wonderful tutorials.

    @Jaypatel512@Jaypatel5122 ай бұрын
  • I love you!! You are the best!!!

    @Matepediaoficial@Matepediaoficial2 ай бұрын
    • i love you more

      @alejandro_ao@alejandro_ao2 ай бұрын
  • Excellent! ♥

    @user-im3zw4ge7b@user-im3zw4ge7b2 ай бұрын
    • i really need to update my video on memory. i'll look into it!

      @alejandro_ao@alejandro_ao2 ай бұрын
  • Amazing video!! Thanks for creating it!! Is there a way to apply the same principles but with another LLMs (open-source)?? If I had gone over all the database I am working with and I had identified the queries related to the most frequent questions, how can I finetune my queries to these frequent questions? ..should I think about adding RAG logic to it?

    @fbravoc9748@fbravoc97482 ай бұрын
  • Fabulous!

    @BrandonFoltz@BrandonFoltz2 ай бұрын
    • hey Brandon! thanks!

      @alejandro_ao@alejandro_ao2 ай бұрын
  • Awesome. Could you include streaming in part 2 as well?

    @guanjwcn@guanjwcn2 ай бұрын
    • streaming is coming very soon 😎

      @alejandro_ao@alejandro_ao2 ай бұрын
  • You really made my day. i was trying to figure out this code from Langchain templates from many days. But you gave a perfect clarity giving step by step understanding. Thanks alot for that. Can u further enhance this in your next video as said in the end of the video with ollama & vizualization from the response using PandasAI or LIDA AI or something better please.

    @abhaypkyek@abhaypkyek2 ай бұрын
    • it's great to hear this! thank you for letting me know. and congrats for finally getting through it! keep it up 👍 that's actually a great idea. i'll see if i can put it in the next video or make a dedicated video about this!

      @alejandro_ao@alejandro_ao2 ай бұрын
  • Thanks for posting this. Very helpful. is there any open source LLM which can convert Natural language to SQL ? would Llama, Flan T5 etc work instead of gpt ?

    @av1743@av17432 ай бұрын
  • for the GUI, what tool would you suggest one can use to return a table, just like in mysql

    @victorchrist9899@victorchrist9899Ай бұрын
  • Can you create langchain based streaming chatbot? Would be very helpful. Thanks for creating high quality contents!

    @geekyprogrammer4831@geekyprogrammer48312 ай бұрын
    • coming very soon!

      @alejandro_ao@alejandro_ao2 ай бұрын
  • Hey very nice, I had one query , LLM based Application to assess the quality of language being used by parents and give practice sessions to improve them. Can you show us "It is a kind of Therapy for special children to make understand the words

    @dr.aravindacvnmamit3770@dr.aravindacvnmamit37702 ай бұрын
  • Thanks!

    @madhutera298@madhutera2982 ай бұрын
    • Hi - how does this work when the response returns table data - example - show me top 10 artists by song streaming count?

      @madhutera298@madhutera2982 ай бұрын
    • hey there! thank you so much for the tip!! it totally would work. the results are always a table actually. what happens is that the LLM receives a table-like prompt and reads it as though it were simple text. so in this case, your LLM would receive the table in the prompt and return something like "the top 10 artists are...." and it may even give you more details depending on your initial instructions :)

      @alejandro_ao@alejandro_ao2 ай бұрын
  • Great tutorial as usual Alejandro! Is it possible to do this with SQL Server? I look at the documentation and it doesn't appear so but maybe I'm missing something.

    @drummermike5150@drummermike51502 ай бұрын
    • Thanks! I am not sure how it would work with MS SQL Server. I suppose you would need a driver to connect it. Since SQLAlchemy supports it, I suppose that it can be done. Maybe if you add the driver to the URI like we did here, but instead of adding the MySQL driver, you add one for MS SQL Server? I checked and this driver might work, but I am not on Windows, so I have no way of testing it right away: ```python from langchain_community.utilities import SQLDatabase db_uri = "mssql+pyodbc://username:password@hostname:port/DatabaseName?driver=SQL+Server" db = SQLDatabase.from_uri(db_uri) ```

      @alejandro_ao@alejandro_ao2 ай бұрын
    • @@alejandro_aoI'll give that a try. Thanks much!!

      @drummermike5150@drummermike51502 ай бұрын
  • Have done it with SAP Hana DB 6 month back..issue related hallucinations are faced and token size limit is also a constraint with open ai GPT 3.5 turbo

    @SanjayRoy-vz5ih@SanjayRoy-vz5ih2 ай бұрын
    • Did you make it work at the end? Or was not worth the struggle?

      @vojtechkaiser2525@vojtechkaiser25257 күн бұрын
    • @@vojtechkaiser2525 Not much work done on that further but of course you can use combination of SQL agent and combinations of prompt techniques but the issues is different as you SAP would not support or recommend working directly with SQL tables but I would still try it as Q&A bot simply as an "art of possible" solution...I am now trying to do the same using combination of OData API and through BTP using function calls and agent architecture

      @SanjayRoy-vz5ih@SanjayRoy-vz5ih7 күн бұрын
  • When i write the code in py file, the schema variable in full_chain function s returning an error (it expect dict type and get_schema return str), do you have any idea on how to fix it ? i've checked langchain doc + you article but i still cant find a solution... thanks for all the tutorials i've learned a lot, keep going !

    @anismairi865@anismairi8652 ай бұрын
    • Having the same issue

      @justinchang3573@justinchang3573Ай бұрын
  • Thanks so much Alejandro! Great contents. Btw seems your website is down today>?

    @youngchrisyang@youngchrisyang2 ай бұрын
    • hey there, thanks! can you check again? i think my dns has been struggling with some changes i did recently :S

      @alejandro_ao@alejandro_aoАй бұрын
    • @@alejandro_ao Thank you Alejandro. All works fine now!

      @youngchrisyang@youngchrisyangАй бұрын
  • ❤❤Can u apply RAG on schema to accommodate bigger Databases with huge tables in next video?

    @user-pr6nm2di6d@user-pr6nm2di6d2 ай бұрын
  • Awesome tutorial! I tried to implement the same on collar, using a sqlite database(chinook). but consistently get the error:"'NoneType' object has no attribute 'get_table_info'" when I try to ge the table schema. Any work arounds?

    @machinelearningzone.6230@machinelearningzone.623018 күн бұрын
  • I was wondering if your calendly link is working for consultations ?it seems that its down

    @abdulrahmanalrabah8324@abdulrahmanalrabah832419 күн бұрын
  • Hey , is it possible to run DML queries using chains or agents?

    @scratch6594@scratch65949 күн бұрын
  • Could you please elaborate on the following with respect to SQL agents: Handling Relationships with Multiple Tables: How can we manage relations involving multiple tables, specifically with primary and foreign keys, given token limitations and potentially multiple agents? Similarity Search in Databases: How can we perform a similarity search within a SQL database? For example, if we have several film plots stored in the database, how can we find films with similar plots? Orchestration Between SQL and JSON Databases (MongoDB): How can we orchestrate data between SQL databases and JSON-based databases like MongoDB without converting everything to SQL, which can be time-consuming? Displaying Subsets of Tables: How can we present a subset of data from multiple tables in the database to the user? Should we parse JSON or CSV formats for this purpose? Utility of Graph Databases: Can Graph databases provide solutions to the above challenges?

    @protimaranipaul7107@protimaranipaul71074 күн бұрын
  • Hi, been following you for a long time, very cool content. Can you please tell me how to use Langchain for MSSQL or Postgres?

    @KurskikhA@KurskikhA2 ай бұрын
    • hey there! thanks for following the content :) i'll be putting up a video about postgres soon. i actually haven't tested if this would work using a mssql driver. but look, apparently you can pass in a driver just like we did here with mysql, but for MSSQL: docs.sqlalchemy.org/en/20/dialects/mssql.html#module-sqlalchemy.dialects.mssql.pyodbc

      @alejandro_ao@alejandro_ao2 ай бұрын
  • Hi Alejandro I have been trying to do the same thing. The problem I do not have credit in OpenAI and i wanted to know if there is any other way using opensource models to achieve the same result..specially in LangChain. Is there any other way?

    @tanzeelmohammed9157@tanzeelmohammed9157Ай бұрын
  • Great tutorial, Thanks a lot. I am watching from India and your website is not opening. Don't know why.

    @user-kx4cg7su8b@user-kx4cg7su8b2 ай бұрын
  • Can we not using Oracle DB for this test?

    @isvic007@isvic007Ай бұрын
  • Should I make predictions about the future based on the data in my table?

    @ArunPrasathR-sp6lt@ArunPrasathR-sp6ltАй бұрын
  • Thank you. This is a real interesting idea. I wonder how complex of a question you can ask it. Can it come up with a query which requires a merging of tables, or returning multiple values? You have me curious.

    @jimgsewell@jimgsewell2 ай бұрын
    • I have used this method to join across a db of 34 tables to form a master document archive for customer data. I was happy with it.

      @mwdcodeninja@mwdcodeninja2 ай бұрын
    • absolutely, it all depends on your LLM's accuracy at executing the queries. in my experience, GPT3 16k is very good. as @sanjayojha1 mentioned, a coding-specific LLM might give you even better results. just don't forget to limit the scope of your MySQL user to avoid security problems!

      @alejandro_ao@alejandro_ao2 ай бұрын
    • @@mwdcodeninja wow, it's glad you've been able to use this before and it performs a join. I'm working on a project with bigquery which has so many data, it doesn't give the desired output as it doesn't perform join, I'll be glad if we can connect and work on it together. Thank you in advance

      @chibuzoemelike6403@chibuzoemelike64032 ай бұрын
    • @@alejandro_ao please how do we implement a code specific LLM to the chain.

      @chibuzoemelike6403@chibuzoemelike64032 ай бұрын
    • @@chibuzoemelike6403 would you be able to share the schema?

      @mwdcodeninja@mwdcodeninja2 ай бұрын
  • ❤❤❤

    @mohsenghafari7652@mohsenghafari76522 ай бұрын
  • Awesome videos.. really appreciate your efforts 👍 Could you please make a video to create a chat bot for WordPress websites.. because scrapping the content from WordPress websites is a bit tricky and passing them to divide into chunks are throwing errors...please help

    @monica.b181@monica.b1812 ай бұрын
    • @UC1oXUA7qgs0GZc_yk46K2OQ hi, I am grateful you replied to my comment 😊🙏 Actually I don't have access to deal with database..the idea of my project is to create a webchat bot for dynamic WordPress websites, where I can scrape all the content from sitemap.xml and then divide it into chunks -> store in any database like faiss or vector store and finally with streamlit I would able to chat with the content on the site. So I need your help in this, as I am beginner and new to these technologies. Please

      @monica.b181@monica.b1812 ай бұрын
    • @UC1oXUA7qgs0GZc_yk46K2OQ hi, I am grateful you replied to my comment 😊🙏 Actually I don't have access to deal with database..the idea of my project is to create a webchat bot for dynamic WordPress websites, where I can scrape all the content from sitemap.xml and then divide it into chunks -> store in any database like faiss or vector store and finally with streamlit I would able to chat with the content on the site. So I need your help in this, as I am beginner and new to these technologies. Please

      @monica.b181@monica.b1812 ай бұрын
  • Thanks for such amazing resource, Alejandro.. i am getting this error: attributeerror : dict object has no attribute get_table_info.. when i try to invoke chain

    @abhishekbourai1832@abhishekbourai1832Ай бұрын
    • seems to me like your database instance is not being created. try logging the type of your SQL client to see if it was actually defined

      @alejandro_ao@alejandro_aoАй бұрын
  • Great as always. I personally find the RunnablePassthrough ugly syntax and confusing. Also, using a coding specific LLM we might get better SQL query with less hallucination.

    @sanjayojha1@sanjayojha12 ай бұрын
    • hey good to see you again. thanks! i totally agree with you that RunnablePassthrough could be better. and about the LLM, totally. not only better, but also faster, as it would be a smaller model 🤔

      @alejandro_ao@alejandro_ao2 ай бұрын
    • Please what do you mean by coding specific LLM?

      @chibuzoemelike6403@chibuzoemelike64032 ай бұрын
  • one video on SORA by openai it's look's Amaze and it's may be a Opecity between reality and virtual reality

    @KARAN_RANA36@KARAN_RANA362 ай бұрын
    • I'll do that as soon as I get my hands on it 😈

      @alejandro_ao@alejandro_ao2 ай бұрын
  • chatting with website using gemini pro plz make a video on this???????

    @nazarmohammed5681@nazarmohammed56812 ай бұрын
  • can you tell me at timestamp 14:29 what is grep SQL, i confused when I was doing , it shows it not recognizing

    @AIWALABRO@AIWALABROАй бұрын
    • hey there, that's just to only return the lines that contain the string "sql" when doing 'pip freeze'. otherwise i would get the huge list of all the packages installed. 'grep' is a unix command that allows you to filter the output text and return only the lines that contain the passed string 👍

      @alejandro_ao@alejandro_aoАй бұрын
  • Thanks for the content. The link to your blog post doesn't work for me.

    @warrenmarkham8891@warrenmarkham88912 ай бұрын
    • hey there, can you try again? i think my dns server was giving me trouble last week

      @alejandro_ao@alejandro_aoАй бұрын
    • @@alejandro_ao Still not working I'm afraid.

      @warrenmarkham8891@warrenmarkham8891Ай бұрын
    • @@warrenmarkham8891 just refreshed the DNS settings on netlify! Should be up now!!

      @alejandro_ao@alejandro_aoАй бұрын
    • @@alejandro_ao Yep, you punched the right ticket that time. It is now working great.

      @warrenmarkham8891@warrenmarkham8891Ай бұрын
  • Does this can be implemented to the large Databases ?

    @07-bmanohar70@07-bmanohar70Ай бұрын
    • absolutely, just be careful that these two things fall within your context window: - the table schemas of your database (unless you have a humungous number of tables, it should be fine). - the results from your query (as they they will be sent back to the model for interpretation). the second point is more tricky than the first one. you may want to update your prompt to make sure that it does not allow to query more than X number of records at a time.

      @alejandro_ao@alejandro_aoАй бұрын
    • @@alejandro_ao i thought about this topic to use Views to handle sets form large database and pre-agregate it there

      @MrJaczes@MrJaczes26 күн бұрын
  • It's a wonderful session but the link to your blog post doesn't working.

    @user-vj8fc2ji7b@user-vj8fc2ji7bАй бұрын
    • just fixed it! DNS propagation problem after meddling with some records on netlify :S

      @alejandro_ao@alejandro_aoАй бұрын
  • Can you do this with NoSQL like MongoDB🙏?

    @matten_zero@matten_zero2 ай бұрын
    • great idea

      @alejandro_ao@alejandro_ao2 ай бұрын
  • I made the sqldb chatbot using fastapi and every thing is working fine except that the chat memory history. Can you suggest how can we implement memory with fastapi.

    @dswithanand@dswithanandАй бұрын
    • Can you please answer this

      @dswithanand@dswithanandАй бұрын
  • There is no password in my SQL server what to put in db_uri sir

    @MADMAX-rw7jx@MADMAX-rw7jxАй бұрын
  • Could you please do with memory

    @seththunder2077@seththunder20772 ай бұрын
    • we would have to update the chain and add memory to it! i'll make a video about it!

      @alejandro_ao@alejandro_ao2 ай бұрын
    • @@alejandro_ao update the chain how?

      @seththunder2077@seththunder20772 ай бұрын
  • Nice, how to do column mapping. Like "How many creator are there" as input question but we have artist instead. I tried as below but still it not works sql_chain = ( RunnablePassthrough.assign(schema=get_schema, column_mapping=get_column_mapping) | prompt | llm.bind(stop=["\ SQLResult:"]) | StrOutputParser() ) column_mapping = { r'creator|artists': 'artist', # Add more mappings as needed } def get_column_mapping(_): column_mapping_str = " ".join([f"{key}: {value}" for key, value in column_mapping.items()]) return column_mapping_str

    @AdhisashanJ@AdhisashanJ8 күн бұрын
  • When I execute full_chain.invoke ({"question": "how many albums are there in the database?"}) it returns {'question': 'how many albums are there in the database?'}

    @monishamonisha-zt3uy@monishamonisha-zt3uyАй бұрын
    • i am facing the same issue, did you get any solution ?

      @kartiksaini-xn6ke@kartiksaini-xn6ke19 күн бұрын
  • I have a question: If the database belongs to an e-commerce website with a substantial product inventory, and a user query such as 'SHOW ME PRODUCTS' risks exceeding the ChatGPT token limit of 60000, how can this issue be effectively managed?

    @dswithanand@dswithanandАй бұрын
    • Yeah, maybe that will require a bit of prompt engineering to make sure that you never index more than X number of records. You could add something like "if you are selecting records, please never call more than 100 records in a single query" or something like that. another alternative would be to use an agent, that would make it more flexible

      @alejandro_ao@alejandro_aoАй бұрын
    • @@alejandro_ao Thanks for reply.. I tested this and it actually worked. Thanks bro

      @dswithanand@dswithanandАй бұрын
  • is open ai compulsary?

    @user-cx9bs9ig9g@user-cx9bs9ig9gАй бұрын
    • absolutely not. you can import any language model that langchain supports: python.langchain.com/docs/integrations/chat/

      @alejandro_ao@alejandro_aoАй бұрын
  • Chat with MongoDB Database is Possible?

    @Ans5462@Ans54622 ай бұрын
    • a bit more complex but totally possible. i'll make a video about it soon

      @alejandro_ao@alejandro_ao2 ай бұрын
  • tenes un canal en español?

    @florencia9427@florencia94272 ай бұрын
    • hola! lamentablemente no :( pero creo que youtube traduce los subtítulos automáticamente, no?

      @alejandro_ao@alejandro_ao2 ай бұрын
  • This tutorial looks nice in "theory". There are several things that are wrong with this approach. Firstly, it is very insecure to fetch the database schema to a third-party provider, whoever this is. These langchain packages are not very secure, even if they are used by the community. Secondly, running the generated sql query without verification is a red flag. Yes, you can play with this, but running this in production may cause a mess. Thirdly, the prompt included a very basic query. How does this work with more complex code that is typically required in a production environment? I would really like to see the accuracy of these generated queries and the probability of actually getting a correct query from the get-go. Not to mention, how would you test this in production? How would you assign roles and permissions to run queries on top of the database. Man, there are too many wrongs things with this that seemed to be avoided, because this a new flashy approach versus the traditional way. Just because it's new, it doesn't make it better.

    @AA-hb6sc@AA-hb6sc2 ай бұрын
    • 💯 agreed on your view..still there are challenges LLM struggle on column names which are complex or similar in synonyms although we are providing schema.

      @ajayjangid7830@ajayjangid78302 ай бұрын
    • I wish I knew this before 😢

      @LeeYeon-qv1tz@LeeYeon-qv1tzАй бұрын
    • @@LeeYeon-qv1tz What happened?

      @AA-hb6sc@AA-hb6scАй бұрын
    • @@AA-hb6sc I developed an application which generates query for given data and question. It worked for simple queries. I didn't check for complex query. Later when I showed this to someone, they asked complex queries. None was answered well. Iam really disappointed.

      @LeeYeon-qv1tz@LeeYeon-qv1tzАй бұрын
    • @@wheresthecode Hey buddy! Based on your response, it seems like you don't have a lot of experience with production-level systems. However, I am going to respond back: 1. sure, you can create a read-only select account. However, if you are going to send a ton of queries to the database, you are going to overload it and you have to have it properly tuned to support all these concurrent queries, especially if you have a lot of users. There are use-cases, especially with more complicated queries whether this cannot be easily achieved and it will take more than to generate the query, if it could be guaranteed that it will be correctly created. 2. nobody has time to create comments about the database schema and doing this, again adds additional data governance and security issues, which need to be mitigated. In some cases, the people that created the database schemas do not even want to reveal the column names or provide any information, because it is a breach of intellectual property. Having such a trace, could potentially mean that you are actually replicating the database schema. 3. how do you ensure that this template cannot be hacked or accessed in the process?

      @AA-hb6sc@AA-hb6scАй бұрын
  • need your email

    @drumzed1724@drumzed17242 ай бұрын
    • hello@alejandro-ao.com :)

      @alejandro_ao@alejandro_ao2 ай бұрын
  • how to manage that the first chain doest find the information in the SQL Schema?

    @alejandrocano5323@alejandrocano53232 ай бұрын
  • Should I make predictions about the future based on the data in my table?

    @ArunPrasathR-sp6lt@ArunPrasathR-sp6ltАй бұрын
    • you could, but that would require training a ML model. that's usually something that you would do separately as you will need a lot of data processing and cleaning to do that

      @alejandro_ao@alejandro_aoАй бұрын
  • chatting with website using gemini pro plz make a video on this???????

    @nazarmohammed5681@nazarmohammed56812 ай бұрын
    • hey again! and huggingface coming soon too!!!!!!!!!

      @alejandro_ao@alejandro_ao2 ай бұрын
    • @@alejandro_ao waiting for that

      @nazarmohammed5681@nazarmohammed56812 ай бұрын
    • @@alejandro_ao hugging face also using gemini

      @nazarmohammed5681@nazarmohammed56812 ай бұрын
KZhead