Langchain & Neo4j: Create Knowledge Graphs from Text

Поделиться
HTML-код
  • Опубликовано: 30 мар 2024
  • -
    python.langchain.com/docs/use...
    #datascience #machinelearning #deeplearning #datanalytics #predictiveanalytics #artificialintelligence #generativeai #largelanguagemodels #computervision #naturallanguageprocessing #agents #transformers #embedding #graphml #graphdatascience #datavisualization #businessintelligence #optimization #montecarlosimulation #simulation #LLMs #python #aws #azure #gcp

Комментарии • 64

  • @johnhelewa
    @johnhelewa 2 месяца назад

    You did a great job of explaining llm graph transformer clearly.

  • @williammariasoosai1153
    @williammariasoosai1153 3 месяца назад

    Sridhar, Great job! Thanks

  • @varuntirupati2566
    @varuntirupati2566 2 месяца назад +2

    The main challenge I see with Knowledge graphs is in Retriever side. Until unless if we or LLM generate the cypher query with the exactly same nodes and relationships that are present in graph database from the question we asked we are not going to get the proper response.

    • @SridharKumarKannam
      @SridharKumarKannam  2 месяца назад +1

      yes, these tools and technologies are still improving everyday. Sometime not too far in the future, we will get minimum acceptable accuracy required..

  • @Shivam-bi5uo
    @Shivam-bi5uo Месяц назад

    great! apprecitate this!

  • @timjrgebn
    @timjrgebn Месяц назад

    Very impressive output on this content volume.
    I do have a question, though. While this is great for building knowledge graphs, I'm curious how complicated these relationships can get in these knowledge graphs.
    I have more experience with formal logic, and more sophisticated logical frameworks like temporal logic, fuzzy logic, etc., try to explain relationships with more accuracy.
    It would be great if these more complicated relationships could be represented in these knowledge graphs. It would help so much in discovery and improving logical accuracy/soundness in written text.

    • @SridharKumarKannam
      @SridharKumarKannam  Месяц назад +1

      its better to define the schema explicitly for production usecases and some post processing of LLMs output for sanity checks. I've several videos on these concepts. I'll add more content on this topic...

  • @debarghyadasgupta1931
    @debarghyadasgupta1931 15 дней назад

    With structured data in your previous pgsql examples, can we still apply graphdb concepts on structure data for optimal rag retrieval?

    • @SridharKumarKannam
      @SridharKumarKannam  14 дней назад

      Structured data (sql db) is usually easy to query, if we can have a good text2LLM model, then we don't need any additional algorithmic techniques. Querying unstructured data is complex and hence we have RAG, knowledge graphs, and combination of them...

    • @debarghyadasgupta1931
      @debarghyadasgupta1931 14 дней назад

      @@SridharKumarKannam what would be your recommendation for writing optimal few-shot query examples to further optimise the sql LLM agent and also to reduce the LLM tokens overlaid and context size with bloated info?

  • @shehzadahmed1782
    @shehzadahmed1782 3 месяца назад +1

    how to i use multiple Neoj4 database's at the same time.. is this possible

  • @matheusaltomarecruz4598
    @matheusaltomarecruz4598 2 месяца назад

    Congratulations for the video. I'm facing some issues that looks like a package version problem. Could you provide the requirements for this experiment, please?

    • @SridharKumarKannam
      @SridharKumarKannam  2 месяца назад

      Langchain library is being updated very frequently. Pls check the latest docs/APIs. Did you resolve the issue ? Whats the error pls...

  • @leed2002isa
    @leed2002isa 3 месяца назад

    hello, thank you for this video it was very helpful, how do i link the project to the neo4j desktop client ?

    • @SridharKumarKannam
      @SridharKumarKannam  3 месяца назад

      This should do
      ----
      import os
      from langchain_community.graphs import Neo4jGraph
      os.environ["NEO4J_URI"] = "bolt://localhost:7687"
      os.environ["NEO4J_USERNAME"] = "neo4j"
      os.environ["NEO4J_PASSWORD"] = "password"
      graph = Neo4jGraph()

  • @malikanaser8251
    @malikanaser8251 3 месяца назад

    Hi, what happen if I run this code again for a second text? does it add it to the same kg database? if not, what should I do to add a new text to the same database?

    • @SridharKumarKannam
      @SridharKumarKannam  2 месяца назад

      It will overwrite the DB. I'm sure Neo4J has capability to add new information, but I'm not sure if thats implemented yet in the langchain wrapper. If your database is not too large, you can re-create it, by adding the new information to raw data before extracting nodes/relationships...

  • @user-zb9kn9pn9d
    @user-zb9kn9pn9d 3 месяца назад +1

    Hi... Do you provide any courses on machine learning or ai?

    • @SridharKumarKannam
      @SridharKumarKannam  3 месяца назад +1

      I don't have any structured course year on ML but I'm planning to do one.

  • @jingluhan3289
    @jingluhan3289 13 дней назад

    Only me met the error at step 6? my pthon told me that there is an error at in LLMGraphTransformer.process_response(self, document)
    593 nodes_set = set()
    594 relationships = []
    --> 595 parsed_json = self.json_repair.loads(raw_schema.content)
    AttributeError: 'str' object has no attribute 'content'

    • @SridharKumarKannam
      @SridharKumarKannam  12 дней назад

      The output format from LLM models is important for these things.
      stackoverflow.com/questions/78521181/llmgraphtransformer-convert-to-graph-documentsdocuments-attributeerror-str

  • @mystic2212
    @mystic2212 25 дней назад

    Bro youre the best, you have saved my Thesis. Only question is how to retrieve

  • @datatalkswithchandranshu2028
    @datatalkswithchandranshu2028 22 дня назад

    Using same code..my llm_transformer.convert_to_graph part not working
    ..gives error that index of list should be integer and not str
    Using hugging face llm

    • @SridharKumarKannam
      @SridharKumarKannam  20 дней назад

      The ouput format of the llms can be the issue. Pls test using openai with a small text, if its working, then the issue is HF llm op format, choose a different model.

  • @luisramos1977
    @luisramos1977 2 месяца назад

    after the code:
    llm = ChatOpenAI(temperature=0, model_name="gpt-4-0125-preview")
    I receive the error:
    ValidationError: 1 validation error for ChatOpenAI
    __root__
    Did not find openai_api_key, please add an environment variable `OPENAI_API_KEY` which contains it, or pass `openai_api_key` as a named parameter. (type=value_error)
    But, I do not find where you add such variables.

    • @codingx6654
      @codingx6654 2 месяца назад

      you can create a .env file and paste your openapi key , OPENAI_API_KEY=your_api_key

    • @SridharKumarKannam
      @SridharKumarKannam  2 месяца назад

      You can add key either directly in the code using this command os.environ["OPENAI_API_KEY"] = "YOUR_KEY"

    • @SridharKumarKannam
      @SridharKumarKannam  2 месяца назад

      I've setup the key in my environmental variables in the bashrc file

  • @anshumangiramkar2589
    @anshumangiramkar2589 3 месяца назад

    Sir, can you please explain the basics too? I mean how to install Neo4j correctly on your PC, because I tried with setting up the system env for Neo4j in Mac OS Big Sur and I struggled a lot with connecting it to my Jupyter Notebook in Python=3.11... and I see no improvement on my side. If you could enlighten me with how to establish a similar environment to run the app on my Mac/Win system, I would be grateful to you... I am watching all of your vids on Knowledge Graphs and LLMs and I have learnt a lot.

    • @SridharKumarKannam
      @SridharKumarKannam  3 месяца назад

      It is resolved? What error are you getting? After installing neo4j desktop, you need to install a couple of plugins also from neo4j desktop.

    • @anshumangiramkar2589
      @anshumangiramkar2589 3 месяца назад

      @@SridharKumarKannam The error is no bolt://localhost:7687 URL not found or running, I want to connect my Neo4J desktop to my Python Script/Notebook and try connecting both. So that, I could make use of knowledge graphs to visualize information from certain given text.

  • @awakenwithoutcoffee
    @awakenwithoutcoffee Месяц назад

    when do you expect GraphRag to be production ready ?

    • @SridharKumarKannam
      @SridharKumarKannam  26 дней назад +1

      I would think in the next few months, definitely within 6 months. There is a lot of work going on in converting free text to graphs.

    • @awakenwithoutcoffee
      @awakenwithoutcoffee 26 дней назад

      @@SridharKumarKannam nice thank you for sharing your knowledge. One of the challenges with graphRAG seems that it requires allot more tokens / time (from testing it took about 40-60 seconds for 1 answer compared to 1-4 seconds for regular RAG, but the answer was 40% better) Do you think these challenges can be solved with the rise of LPU's/inference speed increasement ?

  • @shadyhamrouny8755
    @shadyhamrouny8755 3 месяца назад

    Ollama based llms don't work with the LLMGraphTransformer do you know why?

    • @SridharKumarKannam
      @SridharKumarKannam  3 месяца назад

      I've not tested that, what error are you getting?

    • @shadyhamrouny8755
      @shadyhamrouny8755 3 месяца назад

      @@SridharKumarKannam Thanks for your response!
      ----> 9 llm_transformer = LLMGraphTransformer(llm=llm)
      215 schema = create_simple_model(allowed_nodes, allowed_relationships)
      --> 216 structured_llm = llm.with_structured_output(schema)
      217 self.chain = prompt | structured_llm
      108 warned = True
      109 emit_warning()
      --> 110 return wrapped(*args, **kwargs)
      199 @beta()
      200 def with_structured_output(
      201 self, schema: Union[Dict, Type[BaseModel]], **kwargs: Any
      202 ) -> Runnable[LanguageModelInput, Union[Dict, BaseModel]]:
      203 """Implement this if there is a way of steering the model to generate responses that match a given schema.""" # noqa: E501
      --> 204 raise NotImplementedError()
      Apparenttly Ollama doesn't output a structured output compatible with LLMGraphTransformer. I couldn't find a way around it.

    • @somashekharb1846
      @somashekharb1846 2 месяца назад

      @@SridharKumarKannam AttributeError on calling LLMGraphTransformer.convert_to_graph_documents

    • @somashekharb1846
      @somashekharb1846 2 месяца назад

      AttributeError on calling LLMGraphTransformer.convert_to_graph_documents having this error
      it runs ollama server but ends with this error

    • @JelckedeBoer
      @JelckedeBoer 2 месяца назад

      @@SridharKumarKannam Traceback (most recent call last):
      File "/home/jelcke/dev/test/txt2graph/openai-graph.py", line 38, in
      llm_transformer_filtered = LLMGraphTransformer(
      File "/home/jelcke/dev/test/txt2graph/venv/lib/python3.10/site-packages/langchain_experimental/graph_transformers/llm.py", line 216, in __init__
      structured_llm = llm.with_structured_output(schema)
      File "/home/jelcke/dev/test/txt2graph/venv/lib/python3.10/site-packages/langchain_core/language_models/base.py", line 208, in with_structured_output
      raise NotImplementedError()
      NotImplementedError

  • @nullvoid12
    @nullvoid12 2 месяца назад

    You can view your graphs with Neo4j bloom also

  • @usmanjalil6711
    @usmanjalil6711 26 дней назад

    How can we process large documents. It takes so much time.

    • @usmanjalil6711
      @usmanjalil6711 26 дней назад

      And how can we use aconvert_to_graph_documents function

    • @SridharKumarKannam
      @SridharKumarKannam  25 дней назад

      whats is document size? It is expected to take long time for large documents, for example, if its a pdf book, then all the pages needs to converted to text, a typical book can have 1000s of chunks and for each chunk embedding needs to be create and then stored in the index. Anyway, its mostly a one-off task, for check the end-to-end workflow with short text and then load the entire docs for usage.

  • @jeffhaskin895
    @jeffhaskin895 2 месяца назад

    What software is he using?

  • @RishuKumarMishra-pt9pf
    @RishuKumarMishra-pt9pf 3 месяца назад

    What api key you are using and From where do you get it?

    • @SridharKumarKannam
      @SridharKumarKannam  3 месяца назад

      many frameworks use openai by default if we don't specify a model explicitly. The key in my config files.

  • @rabbit1259
    @rabbit1259 Месяц назад

    Can you provide for the code

  • @weebprogrammer2979
    @weebprogrammer2979 Месяц назад

    You explained it well but the results are always inconsistent.

    • @SridharKumarKannam
      @SridharKumarKannam  Месяц назад

      with LLMs the results are not always the same, they are stochastic. Set the temperature to very low value. You can add some post-processing to the output of LLMs.

    • @weebprogrammer2979
      @weebprogrammer2979 Месяц назад

      @@SridharKumarKannam I did but still not consistent results 😢