Advanced RAG 01 - Self Querying Retrieval

แชร์
ฝัง
  • เผยแพร่เมื่อ 8 ก.ค. 2024
  • Colab: drp.li/T0SDK
    My Links:
    Twitter - / sam_witteveen
    Linkedin - / samwitteveen
    Github:
    github.com/samwit/langchain-t... (updated)
    github.com/samwit/llm-tutorials
    00:00 Intro
    00:47 Self Querying Diagram
    01:55 Code Time
    #langchain #openai #llm
  • วิทยาศาสตร์และเทคโนโลยี

ความคิดเห็น • 100

  • @alchemication
    @alchemication 9 หลายเดือนก่อน +3

    I am always curious to see what Langchain does under the hood. This is a super useful video, and I will dig a little deeper to see how the actual query and filters are determined. Thanks 🙏

  • @AdrienSales
    @AdrienSales 9 หลายเดือนก่อน

    Thanks a lot Sam for this new tutorial. I really like the way the documents are prepared and the precision of the RAG. Willl definitley give it a try very soon

  • @theh1ve
    @theh1ve 9 หลายเดือนก่อน +4

    This was a fantastic walk through and explanation thanks

  • @miikalewandowski7765
    @miikalewandowski7765 9 หลายเดือนก่อน +1

    Great insight. Content like this helps a lot to keep the costs low. Thanks 🎉

  • @JDWilsonJr
    @JDWilsonJr 9 หลายเดือนก่อน +1

    Perfect. Thank you.

  • @nazmulalamnazim
    @nazmulalamnazim 9 หลายเดือนก่อน +2

    This is just amazing! This could potentially change the way how we can utilize langchain. Great video 👏. Kudos!

    • @morespinach9832
      @morespinach9832 4 หลายเดือนก่อน +1

      What is langchain used for typically? This above thing could also be done with simple HF BERT type stuff too, right?

  • @ersineser7610
    @ersineser7610 5 หลายเดือนก่อน

    Thank you very much for sharing great videos.

  • @cmthimmaiah
    @cmthimmaiah 7 หลายเดือนก่อน

    Very nicely explained, thank you

  • @aa-xn5hc
    @aa-xn5hc 8 หลายเดือนก่อน +1

    this is a great video and a very interesting Colab: please continue with tutorials on this retrieval topic

  • @alexanderroodt5052
    @alexanderroodt5052 9 หลายเดือนก่อน +5

    I implemented RNG to submit together queries to make my potty mouth AI bots even more toxic. It's almost like jailbreaking them. I will remember this video for more professional things tho. Very cool!

  • @sergiosajche1596
    @sergiosajche1596 6 หลายเดือนก่อน

    Exactly what I was looking for, thanks 🎉

  • @bwilliams060
    @bwilliams060 9 หลายเดือนก่อน +1

    Great video Sam. Keen to uncover more of the hidden gems in langchain

  • @rickmarciniak2985
    @rickmarciniak2985 2 หลายเดือนก่อน

    Thank you so much for this.

  • @ozzietradie6514
    @ozzietradie6514 9 หลายเดือนก่อน

    love your work

  • @micbab-vg2mu
    @micbab-vg2mu 9 หลายเดือนก่อน

    I am building a pilot of Q&A chatbot for physicians based on RAG - thank you for video.

  • @jarekmor
    @jarekmor 9 หลายเดือนก่อน

    Great video, as always.

  • @henkhbit5748
    @henkhbit5748 9 หลายเดือนก่อน +1

    Nice feature of langchain, but it works only if the metadata are not in the scattered in the documents itself.... Thanks for the video👍

  • @shamikbanerjee9965
    @shamikbanerjee9965 9 หลายเดือนก่อน

    Such premium content.

  • @user-ul6fz8fw3l
    @user-ul6fz8fw3l 9 หลายเดือนก่อน

    Great video!

  • @algan1213
    @algan1213 7 หลายเดือนก่อน

    very interesting thx

  • @knoopx
    @knoopx 9 หลายเดือนก่อน +2

    this + an additional chain that takes user input and does some kind of automatic entity extraction and inserts them back into the vector database = best second brain software ever

    • @J3R3MI6
      @J3R3MI6 9 หลายเดือนก่อน +2

      Do you mean essentially chatting with a Vector DB and having the ability to add/incorporate new info back in to it? That would be extremely useful for building Knowledge Bases

    • @mshonle
      @mshonle 9 หลายเดือนก่อน +5

      I think there’s a good opportunity for developers to learn SpaCy to handle some NPL tasks, like named entity recognition or finding sentence boundaries, that can be used where you don’t need the full power (or costs) of an LLM. You could use GPT for rapid prototyping but then isolate the specialized tasks to spaCy or a local fine tuned Bert. The first programmers who apply this method will not only have something that costs less but also would have better traceability/interpretability.

    • @knoopx
      @knoopx 9 หลายเดือนก่อน +1

      @@J3R3MI6 yep

    • @knoopx
      @knoopx 9 หลายเดือนก่อน +3

      @@mshonle my idea is to combine both NER and LLM, turning user input into various embeddings that can be later queried via LLM. think of it as a digital diary/agenda, where you can write stuff but also retrieve with natural language.

  • @da-bb2up
    @da-bb2up 7 หลายเดือนก่อน

    Thx for the video :) can you update your vector database by a few lines ( if you want to add data to your knowledge base) automatically by running a python script or something like that?

  • @clray123
    @clray123 9 หลายเดือนก่อน +2

    Another way of putting it is that you should only be using LLM as a classifier, in order to resolve ambiguity of NL queries, then translate them into normal database queries (which you can also understand and debug, unlike all the magic LLM output). While it is clearly taking a step back from the ridiculous attempts at placing AI in the driver seat, this approach actually works for real applications and brings added value... just like OCR, voice, or image recognition brings added value to tasks that require such capabilities. And when you need reasoning, idk, maybe use a FOL theorem prover or something.

    • @s.patrickmarino7289
      @s.patrickmarino7289 9 หลายเดือนก่อน +2

      It depends on the kind of data you are looking for. If you are doing a deterministic search, having the LLM call a relational database would be a good choice. If you are looking for something a bit more fuzzy, a vector database would be the best choice. If the language model finds a tool that says, "Search for fish with green heads." Then it will use that tool. If you have a MySQL database with fish head color as a field, that will work great. If you have a bunch of random text and you want to find references to fish with green heads in that text, put the text into a vector database and search that.

    • @clray123
      @clray123 9 หลายเดือนก่อน

      @@s.patrickmarino7289The point is that vector proximity search is not that different from any other search done in a relational db. You don't need any special vector db or even LLM, just a db which supports vector-related indices and embed whatever fuzzy phrase you want to search for. You could even parse the whole NL query manually using something like Spacy (which can easily create a dependency and parts-of-speech graph for a sentence). The LLM bros are probably using these new dbs because they have no idea of what traditional dbs (combined with embedding) are capable of.

  • @tousifahamed11
    @tousifahamed11 9 หลายเดือนก่อน +3

    Waiting for next video with open source model and with csv data

  • @aroonsubway2079
    @aroonsubway2079 2 หลายเดือนก่อน

    Thanks for this great video. Just a newbie question from me: how to formulate RAG setup for this type of text data, representing activities of a person at various timestamps:
    Day1 7-00-00 : breakfast
    Day1 7-00-08 : workout
    Day1 7-00-16 : reading
    ......
    Day1 7-30-59 : cooking
    ......
    Day20 7-00-00 : breakfast
    Day20 7-00-08 : reading
    Day20 7-00-16 : workout
    ......
    Day20 7-30-59: gardening
    Considering there are 20 days and each day involves 200 timestamps, the total number of entries will be 4000. My target is to count the number of occurrences of activites at some time stamps. How should I follow your method to construct docs and metadata_field_info and the query?

  • @RailSuleymanov
    @RailSuleymanov 8 หลายเดือนก่อน +1

    Hi, thank you very much for the video. Any idea on what needs to be adjusted to run it with ChatOllama? I tried ChatOllama(model='llama2') instead of the ChatOpenAI and it fails with some "invalid JSON" object error. Perhaps I will need to look inside what's going on inside langchain, but maybe someone already figured how to overcome that issue.

  • @arindamdas70
    @arindamdas70 5 หลายเดือนก่อน

    @sam if i am using bge embedding model which llm should you suggest to use in SelfQueryRetriever, or is there a opensource implementation.

  • @ValueXPA
    @ValueXPA 9 หลายเดือนก่อน

    Awesome content,please post a video on how to chat with google drive documents.

  • @mizz6186
    @mizz6186 9 หลายเดือนก่อน +3

    Hi Sam, how would you implement semantic search with data reference when retrieving results over a large number of different documents?

    • @ninonazgaidze1360
      @ninonazgaidze1360 9 หลายเดือนก่อน

      I am also very interested in this question

  • @janhorcicka4988
    @janhorcicka4988 8 หลายเดือนก่อน +1

    Hi Sam. In your code, you are using metadata type="string or list[string]", but it seems that you cannot use `list` as a type for metadata. Can you please confirm?

  • @akash_a_desai
    @akash_a_desai 9 หลายเดือนก่อน

    how to do for csv with numrical values,i have fianace data & want to get some p& loss from it.some charts out of it,its possible using this?

  • @morespinach9832
    @morespinach9832 4 หลายเดือนก่อน

    Thank you for this, and apologies for a newbie question: this is an example of highly structured data, right? Those documents with metadata seem pretty much like an elastic search, or even structured data in a DB.

  • @GabrielRymberg
    @GabrielRymberg 9 หลายเดือนก่อน

    Great video, Sam.
    What if we had a wine that has two types of grapes?
    I tried to add another grape: "" entry to the collab, and it replaces the first.
    If we had several grapes separated by commas, e.g. grape: ", ", we now need the structured query to be a bit different:
    Instead of using the Comparator.EQ, in the following example, it would use CONTAIN
    query='Sémillon' filter=Comparison(comparator=, attribute='grape', value='Sémillon') limit=None
    [docs]class Comparator(str, Enum):
    """Enumerator of the comparison operators."""
    EQ = "eq"
    NE = "ne"
    GT = "gt"
    GTE = "gte"
    LT = "lt"
    LTE = "lte"
    CONTAIN = "contain"
    LIKE = "like"
    The question is, how to induce the structured query to use CONTAIN?

    • @BigFattyNat
      @BigFattyNat 9 หลายเดือนก่อน

      dufuq you jammerin on abt mate? llms do that all day baby.

  • @calebsuh
    @calebsuh 9 หลายเดือนก่อน

    Great explanation on the why and how of Self Querying Retrieval!
    My RAG app retrieves from 2 types of documents. I want the LLM to first look in document A, and then only look in document B if it can't find the answer. I was trying to insert meta fields to distinguish the document types, and came across Langchain's self-querying. But I think I'm barking up the wrong tree.
    Any suggestions for my use case?

    • @RailSuleymanov
      @RailSuleymanov 8 หลายเดือนก่อน

      Perhaps write some branching scenario for that case?

  • @attilavass6935
    @attilavass6935 9 หลายเดือนก่อน

    I think the topic of automatic metadata creation for Documents worth some time, for example Langchain's tagging.

    • @samwitteveenai
      @samwitteveenai  9 หลายเดือนก่อน +1

      Yeah this is certainly something you can do though it doesn't always work out perfect. I have had some funny tags when doing it before. I will add it to the list of possible videos

  • @ayushrajjaiswal2646
    @ayushrajjaiswal2646 9 หลายเดือนก่อน +4

    Hello Sam This was a really great video. But building a query retrieval system requires substantial resources so is there a way to optimize that query system to work on the least RAM or GPU and still work efficiently?

    • @samwitteveenai
      @samwitteveenai  9 หลายเดือนก่อน +2

      So a lot of it depends on the scale you are operating at. In regards to the GPU if it is just for the embeddings models the small bge models can run on cpu with ok speed. you can use an external vector store in the cloud which work pretty well. What is your use case?

    • @ayushrajjaiswal2646
      @ayushrajjaiswal2646 9 หลายเดือนก่อน +4

      @@samwitteveenai My use case is to generate recommendations on clothing datasets based on the product description

  • @knowledgegeek5744
    @knowledgegeek5744 2 หลายเดือนก่อน

    Firstly Thanks. I tried this and I used llama2 as llm and chromadb as vector store, the filter is getting detected correctly but the maximum no of records I am getting as a result are 4 even though there are more records which are satisfying the filter, please suggest

  • @quengelbeard
    @quengelbeard 4 หลายเดือนก่อน +1

    Hi Sam, great tutorial! :D
    I have 3 questions:
    1. Why do you use in the attribute description for "color", that it can be a list of strings? Is it possible to have a metadata field that is a list?
    2. Do you know if it's possible to make the self query retriever use more fields than just page_content for semantic search?
    3. Why do you use name as metadata field? Cause as far as i understand, the LLM doesn't know the exact names, so it wouldn't find the relevant document if the name is slightly missspelled from the user. Or are string metadata fields searched by semantic search and not by their exact value?
    Would really appreciate some help! I hope the questions are clear, if not, feel free to ask! :D

  • @Jonathan-rm6kt
    @Jonathan-rm6kt 7 หลายเดือนก่อน

    Anyone have luck self querying on date-like strings (e.g., 2023-12-04) in Chroma?
    I've tried metadata with string type, and also converting it to utc integer timestamps. Creating separate md fields for y/m/d seems clunky. The query constructor makes logical queries for me, but it seems there's not support for date types. Confused, would think this would be a major use-case.

  • @paulocoronado2376
    @paulocoronado2376 9 หลายเดือนก่อน

    Awesome, video!! That's so useful!! Does Self Querying Retrieval perform sorting as well? For example: "What are the oldest wines from France?"

    • @samwitteveenai
      @samwitteveenai  9 หลายเดือนก่อน +1

      Good question, I don't think so, but since they are all going into the LLM you can use that to sort them for the end user easily enough.

  • @michaeldoyle4222
    @michaeldoyle4222 5 หลายเดือนก่อน

    i suspect this is what tableau, microsoft, mongo etc all use for natural language querying

  • @alokyadav-ye2xw
    @alokyadav-ye2xw 9 หลายเดือนก่อน

    a plylist for this would be very useful

    • @s.patrickmarino7289
      @s.patrickmarino7289 9 หลายเดือนก่อน +1

      I think this is 1 out of 1. When he adds more, I suspect there will be a list.

  • @SuperLiberty2008
    @SuperLiberty2008 6 หลายเดือนก่อน

    Hey Sam! Great video, is this possible to build using flowiseai?

    • @samwitteveenai
      @samwitteveenai  6 หลายเดือนก่อน

      Yes I think you can use Flowwise to do most of the LangChain tasks etc

    • @SuperLiberty2008
      @SuperLiberty2008 6 หลายเดือนก่อน

      @@samwitteveenai Sounds great, maybe you have video or flow example? Because I didn't find something related to Self Querying Retrival in flowise. And I have very similar use case as in your video. I will be kindly appreciate for your help.

  • @xinxunzeng9639
    @xinxunzeng9639 หลายเดือนก่อน

    In the last example, llm automatically capitalized the first letter of country names. What if, in the dataset, they are not capitalized but are lowercase as you inputted?

  • @MW-wh3ze
    @MW-wh3ze 9 หลายเดือนก่อน

    Great Video❤
    Video request or hint appreciated:
    I would be interested in a video on a chatbot which builds up questions to narrow down search results on my unstructured data.

    • @samwitteveenai
      @samwitteveenai  9 หลายเดือนก่อน

      " builds up questions to narrow down search results" you mean like a memory?

    • @MW-wh3ze
      @MW-wh3ze 9 หลายเดือนก่อน

      @@samwitteveenai more like... human: please give me the carpet...ai: ok, shall i give you the red or the black one.... human: the red....ai: ok. You have what you need.
      This based on a own dataset.

    • @samwitteveenai
      @samwitteveenai  9 หลายเดือนก่อน

      You would use the prompt for doing this kind of thing more than a RAG alone.

    • @MW-wh3ze
      @MW-wh3ze 9 หลายเดือนก่อน

      @@samwitteveenai this is clear. I am wondering what could be a path forward.

  • @tonimigliato2350
    @tonimigliato2350 9 หลายเดือนก่อน

    Excellent explanation. Thank you for sharing! I would like to know if Langchain is a good choice for production. Can you tell me, please?

    • @samwitteveenai
      @samwitteveenai  9 หลายเดือนก่อน +1

      It depends on your use case. There are many people using it for LLMs apps. I use it for some things and for others I don't.

    • @tonimigliato2350
      @tonimigliato2350 9 หลายเดือนก่อน

      I get it. Thanks for answering me!

  • @tiagoc9754
    @tiagoc9754 5 หลายเดือนก่อน

    Does it work with rerank?

  • @kajalmishra3225
    @kajalmishra3225 3 หลายเดือนก่อน

    How can one query pdf contains table and text as well
    ?

  • @Tommyshelby602
    @Tommyshelby602 2 หลายเดือนก่อน

    Can we use Self Query Retrievers with Open Source LLMs such as Llama-2? If yes then how?
    I'm getting error on this statement
    retriever.get_relevant_documents('What are some red wines')
    TypeError: embedding(): argument 'indices' (position 2) must be Tensor, not StringPromptValue

  • @winxalex1
    @winxalex1 9 หลายเดือนก่อน

    I assume that LangChain sends attribute info and ask LLM: make me filter with operators and used attributes in question I sent u. So again it is semantic query. Somehow example isn't crystal clear. It is blurry what should be treated as NOSQL query/metadata (lot of manual work included) as easily we can have flavour as meta data. Anyway I bet combined search will yield speed, even with relations databases as you can easily can translate semantic question to SQL query.

  • @hqcart1
    @hqcart1 9 หลายเดือนก่อน

    is this a query builder? what is new here i don't get it? It's been there since gpt 3.5 went out.
    The real challenge is the text search where when you have "apple" in your field, and the user searches for "fruit", and does it in sub 100ms.

    • @s.patrickmarino7289
      @s.patrickmarino7289 9 หลายเดือนก่อน +2

      I suspect it will come down to having the AI decide, "I will use a vector to find this. That one I will look for it on my relational DB." It also seems to be about building different tools for different kinds of searches. Remember, this first video is a foundation Sam will be building on. The first one may not be doing anything all that exciting, but it is setting the stage for what comes next.

    • @hqcart1
      @hqcart1 9 หลายเดือนก่อน

      ​@@s.patrickmarino7289Algolia search is experminting with it, i have seen a demos where their AI search is doing the same with sub 100ms, as for query builder, chatgppt can do it since day 1.

  • @clray123
    @clray123 9 หลายเดือนก่อน

    I'm also not sure why you would use some dedicated weird vector db when you can just add vector functions to a production-ready db like ClickHouse.

    • @alx8439
      @alx8439 9 หลายเดือนก่อน

      For demo purposes I suppose. A lot of mpp databases do have vector capabilities, not just Clickhouse

    • @clray123
      @clray123 9 หลายเดือนก่อน

      @@alx8439 Yeah, Postgres also a good candidate.

    • @samwitteveenai
      @samwitteveenai  9 หลายเดือนก่อน

      it just keeps it all in the notebook easily. As I said in the video I wouldn't use OAI Embeddings either, but it makes it simple for people to see the Self Querying part.

  • @mbottambotta
    @mbottambotta 8 หลายเดือนก่อน

    love it! I fed the list of wine description and metadata to my local llm, gave it two examples of metadata_field_info and asked it to complete that info. it did so with flying colors. what a glorious feeling.

  • @cbusse7842
    @cbusse7842 9 หลายเดือนก่อน

    hey sam have you seen the latest open source model CulturaX

    • @samwitteveenai
      @samwitteveenai  9 หลายเดือนก่อน

      I see it as a dataset but didn't know there is a model with it

  • @RealEstate3D
    @RealEstate3D 8 หลายเดือนก่อน

    Unfortunately this doesn’t work with a vector store constructed with PGVector in a Postgres database😢

    • @samwitteveenai
      @samwitteveenai  8 หลายเดือนก่อน +1

      interesting why is that? They don't support meta data?

    • @RealEstate3D
      @RealEstate3D 8 หลายเดือนก่อน +1

      @@samwitteveenai langchain.retrievers.self_query.base import SelfQueryRetriever has a function def _get_builtin_translator that doesn’t implement the Translation for Postgresql

  • @marouahamdi8322
    @marouahamdi8322 4 หลายเดือนก่อน

    great video, us always ! plz i m having a big issue with the open source embedding BGE. i m gettin an error when trying to store in chroma : ValueError: Expected metadata value to be a str, int, float or bool, got None which is a
    Try filtering complex metadata from the document using langchain_community.vectorstores.utils.filter_complex_metadata.
    and i don't have none values in my data. any help?

    • @samwitteveenai
      @samwitteveenai  4 หลายเดือนก่อน

      not sure off hand . which of the BGE models are you using? make sure you have sentence_transformers installed also could be a version issue with Chroma, I have had that happen in the past

    • @marouahamdi8322
      @marouahamdi8322 4 หลายเดือนก่อน

      thank you for your answer. i m using chromadb 0.4.22, sentence-transformers 2.3.1 and BAAI/bge-base-en@@samwitteveenai

  • @prasenjitgiri919
    @prasenjitgiri919 9 หลายเดือนก่อน +1

    All of these demos are fine, but can we have a sample where function calling, these meta data works in tandem. Else these only work in isolation and not in reality. This will be video to watch. With real ingestion

    • @samwitteveenai
      @samwitteveenai  9 หลายเดือนก่อน +1

      What do you want the function calling to do? Access a tool for some inputs and RAG for others?

    • @prasenjitgiri919
      @prasenjitgiri919 9 หลายเดือนก่อน +1

      @@samwitteveenai yes. And this brilliant video of yours along with meta+semantic search.
      Such a demo will be fantastic!

  • @jantuitman
    @jantuitman 9 หลายเดือนก่อน

    Fruity nodes? I thought it was fruity notes, but maybe AI has different opinions about that.

  • @MohdAli-nz4yi
    @MohdAli-nz4yi 9 หลายเดือนก่อน

    How is this advanced??

  • @surajchemperi
    @surajchemperi 6 หลายเดือนก่อน

    This is basic RAG, not advanced as the title suggests.

  • @alizhadigerov9599
    @alizhadigerov9599 9 หลายเดือนก่อน +1

    Whoa! I always thought that semantic searcher utilizes metadata automatically. Meaning, in your example, I thought that normal vectorstore.relevant_documents will automatically pick the relevant documents by looking to the content+metadata without help from LLM.

  • @ednavas8093
    @ednavas8093 5 หลายเดือนก่อน

    Great video!