Це відео не доступне.
Перепрошуємо.

Chat with MySQL Database with Python | LangChain Tutorial

Поділитися
Вставка
  • Опубліковано 15 сер 2024
  • 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:
    ☎️ Get something like this for your company: link.alejandro...
    📌 Article (follow along): alejandro-ao.c...
    📊 Chinook database: github.com/ler...
    💬 Join the Discord Help Server: link.alejandro...
    ❤️ Buy me a coffee... or a beer (thanks): link.alejandro...
    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! 🚀

КОМЕНТАРІ • 181

  • @davidtindell950
    @davidtindell950 5 місяців тому +7

    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 !

    • @EricLofland
      @EricLofland 5 місяців тому +1

      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;
      ```]

    • @davidtindell950
      @davidtindell950 5 місяців тому

      @@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
      @davidtindell950 5 місяців тому

      ​@@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.

    • @warrenmarkham8891
      @warrenmarkham8891 5 місяців тому +1

      @@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.

    • @davidtindell950
      @davidtindell950 5 місяців тому

      ​@@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 " " ua-cam.com/video/7FvdwwvqrD4/v-deo.html " and " ua-cam.com/video/7FvdwwvqrD4/v-deo.htmlsi=a18-dKxTYk2UvRMT ". Also, there are several good current "Medium" articles available on this research subject.

  • @imranonthenet
    @imranonthenet 5 місяців тому +12

    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.

    • @alejandro_ao
      @alejandro_ao  5 місяців тому +2

      thank you man! i hope i will get there someday!

  • @davidtindell950
    @davidtindell950 5 місяців тому +7

    Thanks for including MySQL and not just SQLite.

  • @protimaranipaul7107
    @protimaranipaul7107 3 місяці тому +1

    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?

  • @krisograbek
    @krisograbek 5 місяців тому

    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!

  • @dgm1949
    @dgm1949 5 місяців тому

    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.

    • @alejandro_ao
      @alejandro_ao  5 місяців тому

      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.

  • @msssouza2
    @msssouza2 3 місяці тому

    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.

  • @1sanak
    @1sanak 5 місяців тому +5

    Nice, looking forward to part 2!

  • @AA-hb6sc
    @AA-hb6sc 5 місяців тому +18

    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.

    • @ajayjangid7830
      @ajayjangid7830 5 місяців тому +1

      💯 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.

    • @LeeYeon-qv1tz
      @LeeYeon-qv1tz 4 місяці тому +1

      I wish I knew this before 😢

    • @AA-hb6sc
      @AA-hb6sc 4 місяці тому

      @@LeeYeon-qv1tz What happened?

    • @LeeYeon-qv1tz
      @LeeYeon-qv1tz 4 місяці тому +2

      @@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.

    • @AA-hb6sc
      @AA-hb6sc 4 місяці тому

      @@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?

  • @brunocarvalho3229
    @brunocarvalho3229 15 днів тому

    Hey Alejandro! Amazing content, it helped a lot with the application we're building on my company right now. One question, let's say that the user wants to give some feedback on the output and wants to generate again? Would I have to run the full chain again ? Do you already have another walkthrough on this memory context? Thanks!

  • @Rajat_Jaiswal
    @Rajat_Jaiswal 2 місяці тому +1

    Thanks works well . Amazing tutorial

  • @tanzeelmohammed9157
    @tanzeelmohammed9157 4 місяці тому +1

    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?

  • @funmiemore194
    @funmiemore194 5 місяців тому +1

    First time here and I'm glad I gound your channel.Thanks for sharing!

    • @alejandro_ao
      @alejandro_ao  5 місяців тому +1

      hey there! welcome to the channel :) very happy to have you here :)

    • @funmiemore194
      @funmiemore194 5 місяців тому

      @@alejandro_ao Thanks!!

  • @anismairi865
    @anismairi865 5 місяців тому +2

    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 !

  • @TS-ml4dp
    @TS-ml4dp 2 дні тому

    Hey Alejandro , your guides are great , the best in the net. I would like to ask if you think that replace the schema with Knowledge graph is a good Idea , the reason is that in practice in large DB and DWH the meta data on tables & fields name are not align with business terms and the idea is to leverage the meta data via knowledge graph. what do you think? can you do some guide about KG?

  • @tannerdio333
    @tannerdio333 3 місяці тому

    Dude, incredible tutorial, right on the money for what i needed.

  • @adnank4980
    @adnank4980 5 місяців тому

    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

    • @alejandro_ao
      @alejandro_ao  5 місяців тому +1

      hey there! thank you for telling me this :) keep it up and keep learning 🚀 i'll bring up agents here very soon!

  • @abhishekbourai1832
    @abhishekbourai1832 4 місяці тому +1

    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

    • @alejandro_ao
      @alejandro_ao  4 місяці тому

      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

  • @teddyperera8531
    @teddyperera8531 3 місяці тому

    This is a great tutorial. Thanks for explaining it in a way that's easy to understand

    • @alejandro_ao
      @alejandro_ao  2 місяці тому

      thanks Teddy! i’m glad it was useful!

  • @heaton922
    @heaton922 5 місяців тому

    Love to watch your tutorials. It's very details.

  • @SanjayRoy-vz5ih
    @SanjayRoy-vz5ih 5 місяців тому +2

    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

    • @vojtechkaiser2525
      @vojtechkaiser2525 3 місяці тому

      Did you make it work at the end? Or was not worth the struggle?

    • @SanjayRoy-vz5ih
      @SanjayRoy-vz5ih 3 місяці тому

      @@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

  • @BrandonFoltz
    @BrandonFoltz 5 місяців тому

    Fabulous!

  • @jatinnandwani6678
    @jatinnandwani6678 5 місяців тому +3

    Thanks Alejandro!

    • @alejandro_ao
      @alejandro_ao  5 місяців тому

      Thank you man, you are amazing

  • @bitcoinjc
    @bitcoinjc 2 місяці тому +1

    Will this work with a Microsoft SQL relational database that is much bigger too?

  • @student7261
    @student7261 5 місяців тому

    Awesome. Looking forward to part 2....

  • @mazinzain7121
    @mazinzain7121 5 місяців тому

    I love your content, thanks for all your efforts ❤

    • @alejandro_ao
      @alejandro_ao  5 місяців тому

      i appreciate it! let me know what you want to see next

  • @dr.aravindacvnmamit3770
    @dr.aravindacvnmamit3770 5 місяців тому

    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

  • @Sunny-tk2fu
    @Sunny-tk2fu Місяць тому

    No doubt your tutorial is awesome but i want to just suggest that you should minimize the sibilant sound through davinci resolve or other video editing software to be making video more compelling

    • @alejandro_ao
      @alejandro_ao  Місяць тому

      this is a great suggestion. i actually use resolve but didn't know i could do that. thank you!

  • @legilord3786
    @legilord3786 Місяць тому

    thanks for the great video, does it matter how big the database is? or can a database be too big? in my case i have a database with a size of about 300mb

  • @marvinmarkham8405
    @marvinmarkham8405 2 місяці тому

    Videos are exceptional just very high level and the mic seems close when speaking so its not pleaseant for me to watch the vids with that type of mic calibration. Luckily the website is a better walkthough for me. Thanks for your work

    • @alejandro_ao
      @alejandro_ao  2 місяці тому

      hey thank you for the feedback, glad you found the tutorial useful mate. i’ll improve the sound in future vids :)

  • @AbhinavKumar-tx5er
    @AbhinavKumar-tx5er 7 днів тому

    Will it work with large dataset? lets say more than 20GB?

  • @wg5920
    @wg5920 5 місяців тому

    Amazing Video. Great job

  • @abhaypkyek
    @abhaypkyek 5 місяців тому

    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.

    • @alejandro_ao
      @alejandro_ao  5 місяців тому

      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!

  • @chibuzoemelike6403
    @chibuzoemelike6403 5 місяців тому

    Thank you so much for this video, this is really helpful!! Looking forward to using huggingface models

    • @alejandro_ao
      @alejandro_ao  5 місяців тому

      Great! Which models in particular are you interested in?

    • @palanikumarmsc
      @palanikumarmsc 3 місяці тому

      Mistral AI

  • @bwilliams060
    @bwilliams060 5 місяців тому

    Your videos are the best!

  • @yashtrisha5919
    @yashtrisha5919 2 місяці тому

    Thanks but i follow the tutorial and i am getting this error "xcept MySQLInterfaceError as err:", do i need to replace "
    " in query full_chain function?

  • @arunsnmimtimt
    @arunsnmimtimt 2 місяці тому

    @alejandro_ao,can you kindly let me know whether it can be done with out API. that is to run the same locally on desktop?

  • @user-lq1md3dw9z
    @user-lq1md3dw9z 2 місяці тому

    When running your code, I got this error: ImportError: cannot import name 'LangSmithParams' from 'langchain_core.language_models.chat_models'. Could you please post your requirements.txt? Thank you!

  • @artislove491
    @artislove491 5 місяців тому

    Great stuff! Many thanks 💪

  • @RedWhiteBlue209
    @RedWhiteBlue209 2 місяці тому

    Could you please post your requirements.txt? When running your code, I got this error: ImportError: cannot import name 'LangSmithParams' from 'langchain_core.language_models.chat_models'

  • @rameshh3821
    @rameshh3821 2 місяці тому

    Could you please let me know if it's possible to use LangChain to query multiple tables and generate data visualizations on the chatbot interface? I've seen solutions for a single CSV file using PandasAI or LIDA, but I haven't found anything that works with multiple tables stored in a database.

  • @victorchrist9899
    @victorchrist9899 4 місяці тому

    for the GUI, what tool would you suggest one can use to return a table, just like in mysql

  • @fbravoc9748
    @fbravoc9748 5 місяців тому

    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?

  • @Aidev7876
    @Aidev7876 5 місяців тому

    Thanks. What about long ot short term memory during conversation?

  • @user-pr6nm2di6d
    @user-pr6nm2di6d 5 місяців тому

    ❤❤Can u apply RAG on schema to accommodate bigger Databases with huge tables in next video?

  • @Jaypatel512
    @Jaypatel512 5 місяців тому

    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.

  • @guanjwcn
    @guanjwcn 5 місяців тому

    Awesome. Could you include streaming in part 2 as well?

    • @alejandro_ao
      @alejandro_ao  5 місяців тому

      streaming is coming very soon 😎

  • @nazarmohammed5681
    @nazarmohammed5681 5 місяців тому +1

    chatting with website using gemini pro plz make a video on this???????

  • @sam-uw3gf
    @sam-uw3gf 5 місяців тому

    great as always bro

  • @machinelearningzone.6230
    @machinelearningzone.6230 3 місяці тому

    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?

  • @Matepediaoficial
    @Matepediaoficial 5 місяців тому

    I love you!! You are the best!!!

  • @natawebmaster
    @natawebmaster 5 місяців тому

    Thanks for useful video)

  • @sanjayojha1
    @sanjayojha1 5 місяців тому

    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.

    • @alejandro_ao
      @alejandro_ao  5 місяців тому

      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 🤔

    • @chibuzoemelike6403
      @chibuzoemelike6403 5 місяців тому

      Please what do you mean by coding specific LLM?

  • @av1743
    @av1743 5 місяців тому

    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 ?

  • @user-im3zw4ge7b
    @user-im3zw4ge7b 5 місяців тому

    Excellent! ♥

    • @alejandro_ao
      @alejandro_ao  5 місяців тому

      i really need to update my video on memory. i'll look into it!

  • @alejandrocano5323
    @alejandrocano5323 5 місяців тому +1

    how to manage that the first chain doest find the information in the SQL Schema?

  • @scratch-9097
    @scratch-9097 3 місяці тому

    Hey , is it possible to run DML queries using chains or agents?

  • @abdulrahmanalrabah8324
    @abdulrahmanalrabah8324 3 місяці тому

    I was wondering if your calendly link is working for consultations ?it seems that its down

  • @drummermike5150
    @drummermike5150 5 місяців тому +1

    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.

    • @alejandro_ao
      @alejandro_ao  5 місяців тому

      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)
      ```

    • @drummermike5150
      @drummermike5150 5 місяців тому

      @@alejandro_aoI'll give that a try. Thanks much!!

  • @geekyprogrammer4831
    @geekyprogrammer4831 5 місяців тому

    Can you create langchain based streaming chatbot? Would be very helpful. Thanks for creating high quality contents!

  • @AdhisashanJ
    @AdhisashanJ 3 місяці тому

    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

  • @v.svishnu2380
    @v.svishnu2380 6 днів тому

    I have a doubt, Is it safe to connect langchain with production database ?

    • @alejandro_ao
      @alejandro_ao  4 дні тому

      I would recommend that you only do this after thorough testing. and very importantly, do not give write privileges to the MySQL user that you are using to access the database. You don’t want your LLM to be able to update or delete data in your database 👍

  • @isvic007
    @isvic007 4 місяці тому

    Can we not using Oracle DB for this test?

  • @dswithanand
    @dswithanand 4 місяці тому

    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?

    • @alejandro_ao
      @alejandro_ao  4 місяці тому +1

      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

    • @dswithanand
      @dswithanand 4 місяці тому

      @@alejandro_ao Thanks for reply.. I tested this and it actually worked. Thanks bro

  • @muneerAbro
    @muneerAbro 3 місяці тому

    Very Informative video ❤, can you create this video in PHP

    • @alejandro_ao
      @alejandro_ao  2 місяці тому +1

      hey, thanks! i would like to but unfortunately langchain does not have a PHP version that I know of :( if you are trying to create something like this for a PHP app, I would create an API that deals with these processes in python or js and then have my PHP app query this API

    • @muneerAbro
      @muneerAbro 2 місяці тому

      @@alejandro_ao welcome dear, I tried in php/ laravel, it is working fine but some time it shows response "Unable to generate query". So I am very afraid of this, If I deploy this chat on live server, If I get such response, it will be bad experience for me, can you suggest me How I get rid of this error? this error comes from chatgpt-4o openAi

  • @dswithanand
    @dswithanand 4 місяці тому

    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 4 місяці тому

      Can you please answer this

  • @07-bmanohar70
    @07-bmanohar70 5 місяців тому +1

    Does this can be implemented to the large Databases ?

    • @alejandro_ao
      @alejandro_ao  5 місяців тому +1

      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.

    • @MrJaczes
      @MrJaczes 3 місяці тому

      @@alejandro_ao i thought about this topic to use Views to handle sets form large database and pre-agregate it there

  • @user-kx4cg7su8b
    @user-kx4cg7su8b 5 місяців тому

    Great tutorial, Thanks a lot. I am watching from India and your website is not opening. Don't know why.

  • @KurskikhA
    @KurskikhA 5 місяців тому

    Hi, been following you for a long time, very cool content. Can you please tell me how to use Langchain for MSSQL or Postgres?

    • @alejandro_ao
      @alejandro_ao  5 місяців тому +1

      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

  • @youngchrisyang
    @youngchrisyang 5 місяців тому

    Thanks so much Alejandro! Great contents. Btw seems your website is down today>?

    • @alejandro_ao
      @alejandro_ao  5 місяців тому

      hey there, thanks! can you check again? i think my dns has been struggling with some changes i did recently :S

    • @youngchrisyang
      @youngchrisyang 5 місяців тому

      @@alejandro_ao Thank you Alejandro. All works fine now!

  • @AIWALABRO
    @AIWALABRO 4 місяці тому

    can you tell me at timestamp 14:29 what is grep SQL, i confused when I was doing , it shows it not recognizing

    • @alejandro_ao
      @alejandro_ao  4 місяці тому

      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 👍

  • @monishamonisha-zt3uy
    @monishamonisha-zt3uy 4 місяці тому

    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?'}

    • @kartiksaini-xn6ke
      @kartiksaini-xn6ke 3 місяці тому

      i am facing the same issue, did you get any solution ?

  • @monica.b181
    @monica.b181 5 місяців тому

    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.b181 5 місяців тому

      @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.b181 5 місяців тому

      @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

  • @jimgsewell
    @jimgsewell 5 місяців тому

    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.

    • @mwdcodeninja
      @mwdcodeninja 5 місяців тому

      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.

    • @alejandro_ao
      @alejandro_ao  5 місяців тому +1

      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!

    • @chibuzoemelike6403
      @chibuzoemelike6403 5 місяців тому

      @@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
      @chibuzoemelike6403 5 місяців тому

      @@alejandro_ao please how do we implement a code specific LLM to the chain.

    • @mwdcodeninja
      @mwdcodeninja 5 місяців тому

      @@chibuzoemelike6403 would you be able to share the schema?

  • @MADMAX-rw7jx
    @MADMAX-rw7jx 5 місяців тому

    There is no password in my SQL server what to put in db_uri sir

  • @madhutera298
    @madhutera298 5 місяців тому

    Thanks!

    • @madhutera298
      @madhutera298 5 місяців тому

      Hi - how does this work when the response returns table data - example - show me top 10 artists by song streaming count?

    • @alejandro_ao
      @alejandro_ao  5 місяців тому

      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 :)

  • @user-vj8fc2ji7b
    @user-vj8fc2ji7b 5 місяців тому

    It's a wonderful session but the link to your blog post doesn't working.

    • @alejandro_ao
      @alejandro_ao  5 місяців тому

      just fixed it! DNS propagation problem after meddling with some records on netlify :S

  • @user-cx9bs9ig9g
    @user-cx9bs9ig9g 5 місяців тому

    is open ai compulsary?

    • @alejandro_ao
      @alejandro_ao  5 місяців тому +1

      absolutely not. you can import any language model that langchain supports: python.langchain.com/docs/integrations/chat/

  • @KARAN_RANA36
    @KARAN_RANA36 5 місяців тому

    one video on SORA by openai it's look's Amaze and it's may be a Opecity between reality and virtual reality

    • @alejandro_ao
      @alejandro_ao  5 місяців тому +1

      I'll do that as soon as I get my hands on it 😈

  • @matten_zero
    @matten_zero 5 місяців тому

    Can you do this with NoSQL like MongoDB🙏?

  • @warrenmarkham8891
    @warrenmarkham8891 5 місяців тому

    Thanks for the content. The link to your blog post doesn't work for me.

    • @alejandro_ao
      @alejandro_ao  5 місяців тому

      hey there, can you try again? i think my dns server was giving me trouble last week

    • @warrenmarkham8891
      @warrenmarkham8891 5 місяців тому

      @@alejandro_ao Still not working I'm afraid.

    • @alejandro_ao
      @alejandro_ao  5 місяців тому

      @@warrenmarkham8891 just refreshed the DNS settings on netlify! Should be up now!!

    • @warrenmarkham8891
      @warrenmarkham8891 4 місяці тому

      @@alejandro_ao Yep, you punched the right ticket that time. It is now working great.

  • @Ans5462
    @Ans5462 5 місяців тому

    Chat with MongoDB Database is Possible?

    • @alejandro_ao
      @alejandro_ao  5 місяців тому

      a bit more complex but totally possible. i'll make a video about it soon

  • @seththunder2077
    @seththunder2077 5 місяців тому

    Could you please do with memory

    • @alejandro_ao
      @alejandro_ao  5 місяців тому

      we would have to update the chain and add memory to it! i'll make a video about it!

    • @seththunder2077
      @seththunder2077 5 місяців тому

      @@alejandro_ao update the chain how?

  • @mohsenghafari7652
    @mohsenghafari7652 5 місяців тому

    ❤❤❤

  • @florencia9427
    @florencia9427 5 місяців тому

    tenes un canal en español?

    • @alejandro_ao
      @alejandro_ao  5 місяців тому +1

      hola! lamentablemente no :( pero creo que youtube traduce los subtítulos automáticamente, no?

  • @RexPersicus
    @RexPersicus 15 днів тому

    There are so many missing pieces in your code in your articles and parts that you forgot in your video that has made a big challenege for implementation. If you really want to share your work with other you need to do a better job and get someone else to edit your work as you - the developer - have built so many blind spots for yourself that "things work" for you because of prior installations or setup and you keep forgetting to mention or show them in your article/video.

  • @drumzed1724
    @drumzed1724 5 місяців тому

    need your email

  • @nazarmohammed5681
    @nazarmohammed5681 5 місяців тому

    chatting with website using gemini pro plz make a video on this???????

    • @alejandro_ao
      @alejandro_ao  5 місяців тому

      hey again! and huggingface coming soon too!!!!!!!!!

    • @nazarmohammed5681
      @nazarmohammed5681 5 місяців тому

      @@alejandro_ao waiting for that

    • @nazarmohammed5681
      @nazarmohammed5681 5 місяців тому

      @@alejandro_ao hugging face also using gemini