Local GraphRAG with LLaMa 3.1 - LangChain, Ollama & Neo4j

Поделиться
HTML-код
  • Опубликовано: 23 янв 2025

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

  • @garic4
    @garic4 5 месяцев назад +16

    This was EXACTLY what I've been looking for. Thank you for the great walkthrough, you just got yourself a new subscriber. Cheers

  • @royalarindam
    @royalarindam 7 дней назад

    Thanks! Amazing work. An explanation on the logic of graph building will be deeply appreciated.

  • @pdctln
    @pdctln Месяц назад +2

    You are just brilliant! This is exactly what I've been looking for-great examples and very nicely illustrated. Thank you!

  • @yWorksTube
    @yWorksTube 17 дней назад +2

    We're glad that yFiles Graphs for Jupyter is featured in this video! As developers of this free extension, we love seeing it in action. Your feedback is valuable to us - let us know if there's anything missing or if you have suggestions for improvements. We're always looking to make it even better for the community!
    Happy Diagramming!

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

    This is also EXACTLY what I was looking for. Please build more upon this, maybe for an anti-fraud use case.

  • @eloiseidlitz7062
    @eloiseidlitz7062 5 месяцев назад +4

    Smart video ! It could be a good way to access easily relationships between stakeholders in any kind of business.

  • @mgmanzanillo
    @mgmanzanillo 5 месяцев назад +9

    Has any tried this code for a large amounts of documents?
    How does it scale?

  • @mgmanzanillo
    @mgmanzanillo 5 месяцев назад +3

    Could you also create sample code for instances where multiple documents are stored in a directory in either .txt or a compressed format like Parquet?
    How would it work then? Would you transform each document separately and combine them as a graph?
    Would like to get your insight.
    Thank you for the video!

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

    Hello, I had some trouble with :
    graph.add_graph_documents(
    graph_documents,
    baseEntityLabel=True,
    include_source=True
    )
    Apparently some labels and relationships were empty, which is a problem for neo4J, I handled it by making sur that at least every node and relationship had a label. Why do I have that issue you did not had ?

    • @codingcrashcourses8533
      @codingcrashcourses8533  4 месяца назад

      @@Weotcs some people had this with llama. Did it also happen with gpt 4o Mini?

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

    Can you provide some information on the montivation to change from using ChatOllama in the video to OllamaFunctions in the repo please?

  • @hitlab
    @hitlab 4 месяца назад

    does anyone know if there is a graphics package for python that works the way this one does but not for Jupyter notebook?
    Looking to build an app an want to be able to show the same kind of graph viz in a web browser.

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

      I can do a Video on that if you want to

    • @hitlab
      @hitlab 4 месяца назад

      @@codingcrashcourses8533 that would be great!

  • @bhaibhai-qe8tt
    @bhaibhai-qe8tt 3 месяца назад

    I am having this error "no validator found for , see `arbitrary_types_allowed` in Config"

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

      @@bhaibhai-qe8tt what langchain Version and pydantic Version do you use?

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

    Maybe you can help- When I execute entity_chain = llm.with_structured_output(Entities) I get the error in BaseLanguageModel.with_structured_output(self, schema, **kwargs)
    238 """Not implemented on this class."""
    239 # Implement this on child class if there is a way of steering the model to
    240 # generate responses that match a given schema.
    --> 241 raise NotImplementedError

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

      I'm using llama 3.1:8b Maybe it doesn't support the structured output method.

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

      @@aoliveira_ yep, thats the issue

    • @qytx-p8t
      @qytx-p8t 4 дня назад

      Hello! I encountered an issue when executing entity_chain = llm.with_structured_output(Entities), with the error message 'Not implemented on this class'. Have you faced a similar issue and found a solution? If so, could you kindly share how you resolved it? Thank you very much!

    • @aoliveira_
      @aoliveira_ 3 дня назад

      @@qytx-p8t I was using an Ollama model, but using OllamaLLM instead of ChatOllama class to access it.

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

    wow, great overview! Thanks!!

  • @sandeepgajula7635
    @sandeepgajula7635 4 месяца назад

    I have created a Neo4j graph but querying is getting difficult. So, Here the retrieval function varies for different inputs(like this retrieval function will work for this example only if I change the input it mayn't give me the proper results). How to overcome this problem. Can you give us a solution for querying the neo4j graph with different llms (like gemini,openai,ollma etc..)
    Thank you hoping for proper response.

  • @QuocNguyen-se7vi
    @QuocNguyen-se7vi 3 месяца назад

    please help me, i start to run the second comand line (from langchain_core.runnables import RunnablePassthrough......) and the result is false, no .evn file apppears. Please help me to fix thiss. Thank you.

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

      @@QuocNguyen-se7vi you have to create it yourself first ;).

    • @QuocNguyen-se7vi
      @QuocNguyen-se7vi 3 месяца назад

      @@codingcrashcourses8533 thank you, I see LightRAG has a better constructive knowledge graph than GraphRAG, would you take a look at it!

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

    When i use the convert to graph document function, for some reason it's not creating any nodes. Am i missing a step? From my understanding it is the LLM which will decide the nodes and the relationship between them right?

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

      @@yashbajpai231 hm, what errors do you see? Normally you are correct

  • @HarshBhatnagar-i1v
    @HarshBhatnagar-i1v 3 месяца назад

    docker compose is not working
    any suggestions ?

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

    Is this GraphRag as by microsoft's named approach? Because I don't see anything about creating communities for search

  • @Transforming-AI
    @Transforming-AI 5 месяцев назад +1

    You mentioned you received a key error at one point. I am getting that key error as well. Please share how you worked around the key error. Following your notebook, my key error is, KeyError: 'head'.

    • @codingcrashcourses8533
      @codingcrashcourses8533  5 месяцев назад +1

      @@Transforming-AI had the same issue a few times. I think the 8k Model produced this, bit not always. Or did you try the 70b or 405b Model?

    • @Transforming-AI
      @Transforming-AI 5 месяцев назад

      @@codingcrashcourses8533 I have the 8b installed, will try the 70b. Thanks.

    • @saadsafi6073
      @saadsafi6073 5 месяцев назад

      @@codingcrashcourses8533 had the same, seems to be caused by the double quotes in dummytext.txt, if you replace them (say, with single quotes) then the json will not be broken. key error was to do with missing 'head' which is one of the node keys.

    • @mingjenchen2975
      @mingjenchen2975 5 месяцев назад

      @@codingcrashcourses8533 I tried it with llama3.1:70b and it took 13 minutes on my Mac Studio.

    • @carlospareja7951
      @carlospareja7951 5 месяцев назад

      @@codingcrashcourses8533 I'm also running into this issue when running with the 8B model.

  • @Silvietta13
    @Silvietta13 4 месяца назад

    I try this approach with Ollama but It seesm when execute the row "llm_transformer.convert_to_graph_documents" it run for more time and I need to stop the run..can help me? What is it the problem? The graph DB neo4j connection?

    • @codingcrashcourses8533
      @codingcrashcourses8533  4 месяца назад

      @@Silvietta13 any errors?

    • @Silvietta13
      @Silvietta13 4 месяца назад

      @@codingcrashcourses8533 No errors!

    • @Silvietta13
      @Silvietta13 4 месяца назад

      @@codingcrashcourses8533 After 118 minutes with ollama end with this error: ValidationError: 2 validation errors for Node
      id
      none is not an allowed value (type=type_error.none.not_allowed)
      type
      none is not an allowed value (type=type_error.none.not_allowed). Error is generated from the line: graph_documents = llm_transformer.convert_to_graph_documents(documents)

    • @VanshMaurya-b3b
      @VanshMaurya-b3b 4 месяца назад

      @@Silvietta13 so what did you do?

  • @i2c_jason
    @i2c_jason 5 месяцев назад +2

    Are the graph visualizations mostly used for development, to double check what the system is 'thinking' and look for valuable clustering?

    • @codingcrashcourses8533
      @codingcrashcourses8533  5 месяцев назад

      The visualization will probably used for development, the LLM won´t use it (a vision model won´t be able to deal with it, if you think of that)

    • @i2c_jason
      @i2c_jason 5 месяцев назад +1

      @@codingcrashcourses8533 I may have missed it from the video, but is Neo4j open source / free to use always? I looked at their site and was confused. Or are you using free-tier for the demo? Would love to use this for development. Thanks!

    • @codingcrashcourses8533
      @codingcrashcourses8533  5 месяцев назад +3

      @@i2c_jason It´s free to use with Docker, you can also download a Desktop version. If you want to use it for your enterprise app, it might be different

    • @alishaw9999
      @alishaw9999 5 месяцев назад

      @@codingcrashcourses8533 can you demonstrate it with desktop version of neo4j

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

      ​@@i2c_jason It's source available, and equal to open source as long as you don't sell it as a service. So you can make a company around a service that uses it for free, but not offer it on a SaaS.

  • @miguelprctba
    @miguelprctba 5 месяцев назад +4

    Congratulations, great approach! I was wondering if you could consider using a different embedding method instead of OpenAI's, as it requires payment. What do you think?

    • @codingcrashcourses8533
      @codingcrashcourses8533  5 месяцев назад +3

      Ollama also offers an embedding model and to be honest, I think you should probably use it. You can use the same approach to use an env variable to use the ollama embeddings class like I did for the model

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

    I am encountering an error when running the command
    print(graph_retriever("Who is Nonna Lucia?"))
    Generated Query: Nonna~2 AND Lucia~2
    ClientError: {code: Neo.ClientError.Procedure.ProcedureCallFailed} {message: Failed to invoke procedure db.index.fulltext.queryNodes: Caused by: java.lang.IllegalArgumentException: There is no such fulltext schema index: entity}"

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

    Is it possible to use other models than llama 3.1? E.g GGUF models?

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

      @@jordybrakie yes, normally thats possible. But some models struggle to create the graph

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

    Excellent video (as always). I have a question about the .jar dependency. Are you able to please provide instructions on where to get updated Neo4j releases? I see that they're onto 5.25.1 now, but I don't see where I can simply download a .jar. Do we need to compile that somehow? Thanks again for the fantastic video!

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

      Aha I think I found it (neo4j apoc github repo). Thanks again!

  • @shyamvai
    @shyamvai 4 месяца назад

    I tried to git clone your repo.. it does not work.

    • @codingcrashcourses8533
      @codingcrashcourses8533  4 месяца назад +1

      why? Cloning should always work if you dont have an error in your git configuration

  • @truliapro7112
    @truliapro7112 5 месяцев назад

    How can I use this for my code project files. I need to convert whole php project with python.

    • @codingcrashcourses8533
      @codingcrashcourses8533  5 месяцев назад +1

      The code is in the description, it´s free, do whatever you want with it :).

  • @Mohidthevloger
    @Mohidthevloger 4 месяца назад

    Great video! One thing I would be interested to know that were you be able to compare the results between the two approaches Graph or Vector search? Which one is retrieving the most relevant results?

    • @codingcrashcourses8533
      @codingcrashcourses8533  4 месяца назад

      It depends on the question :). You probably want to use a Hybrid approach

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

    Great approach. As far as I understood, you still need to build a vector store for the queries, so it is not possible to get an answer only with Neo4J graphdatabase?

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

      You do! Its normal to use a hybrid approach use use results from neo4j and similarity search.

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

    Really informative and to the point tutorial! I do have 2 questions though.
    Q1. Did this approach store two sets of embeddings for the documents? One in the graph database and the other in a normal vector database?
    Q2. If I want to add more data to this graph, do I have to recompute the nodes every time or is there a way to just extend the original graphs with new nodes from the newly added content?
    Thanks!

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

      1. Yes, that approach is called hybrid approach
      2. Yes, at least as I know, there is no way around that

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

      @@codingcrashcourses8533 thanks 🙏

  • @moellerseo
    @moellerseo 5 месяцев назад

    Nice video. 🎉 Thanks

  • @PassingTheDog
    @PassingTheDog 5 месяцев назад +2

    Running this error over and over in the "graph_documents = llm_transformer.convert_to_graph_documents(documents)" cell:
    731 parsed_json = self.json_repair.loads(raw_schema)
    732 for rel in parsed_json:
    733 # Nodes need to be deduplicated using a set
    --> 734 nodes_set.add((rel["head"], rel["head_type"]))
    735 nodes_set.add((rel["tail"], rel["tail_type"]))
    737 source_node = Node(id=rel["head"], type=rel["head_type"])
    TypeError: string indices must be integers

    • @codingcrashcourses8533
      @codingcrashcourses8533  5 месяцев назад +1

      Hmhmh, some people seem to get this unfortunately. Did you use the 8B model? That could explain it, since it might create empty documents or so.

    • @Wingly113
      @Wingly113 5 месяцев назад

      @@codingcrashcourses8533 getting the same error as well

    • @codingcrashcourses8533
      @codingcrashcourses8533  5 месяцев назад

      @@Wingly113 also with 8b? I did not run in any errors with 70b of gpt4-small yet

    • @PassingTheDog
      @PassingTheDog 5 месяцев назад

      @@codingcrashcourses8533 Yup, 8b. I can't handle 70b tho...

    • @sidharthgarg2348
      @sidharthgarg2348 5 месяцев назад

      Llama 3.1 8B can also handle it, instead of ollama use llama.cpp and download llama 3.1 8B.gguf model and customise prompt template and you are good to go.i For reference you can use this repo
      github.com/s3dhanth/GraphRAG-with-Hermes-2.5-Pro-LLM-using-neo4j-database

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

    Very nice!

  • @Matthew-rb7rs
    @Matthew-rb7rs 4 месяца назад

    LangChain --version ?

  • @federicosalvati2454
    @federicosalvati2454 4 месяца назад

    where is the .env file in the repository?

    • @codingcrashcourses8533
      @codingcrashcourses8533  4 месяца назад

      @@federicosalvati2454 its not there. You need to use your own api Keys and Passwords of course

    • @federicosalvati2454
      @federicosalvati2454 4 месяца назад

      @@codingcrashcourses8533 thank you so much I am approaching coding with python and RAGs for the first time and all of this helps a lot

  • @vedprakashnautiyal
    @vedprakashnautiyal 3 дня назад

    Hey, what are your computer specs ??

    • @codingcrashcourses8533
      @codingcrashcourses8533  3 дня назад

      @@vedprakashnautiyal my PC is acturally quite old, 8 years. I got a 980 nvidia card

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

    Awesome video! The notebook is slightly different from the video. Could you please make some comments here to reflect the departure away from the video?

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

      I incorpoated issues people had with the Notebook which. Logically nothing should have changed

  • @giantworks1366
    @giantworks1366 5 месяцев назад

    Nice. Can I only use llm ollama3.1 without openAi? Thanks

    • @codingcrashcourses8533
      @codingcrashcourses8533  5 месяцев назад

      @@giantworks1366 yes, i wrote the Code in a way that you can switch from one to another via the llm_type variable. But the 8b param models seems sometimes to have issues to create the docs in the required way

  • @sylap
    @sylap 5 месяцев назад

    Thank you for this video! 👏 I've been eager to see someone cover this topic. I have a couple of questions I hope you can help me with.
    In this approach, is there a way to rerank the retrieved documents?
    Did I understand correctly that you first query the graph database, and based on the retrieved entities and relationships, it then retrieves pieces of documents from the vector store?

    • @codingcrashcourses8533
      @codingcrashcourses8533  5 месяцев назад +2

      Regarding reranking: I don´t know to be honest. I could not think of any metric to do that.
      Regarding retrieval: No! I used a hybrid approach there, but they are independent approaches. The LLM will use docs from both approaches.

    • @sylap
      @sylap 5 месяцев назад

      @@codingcrashcourses8533 Honestly, not sure if reranking is even needed for Graph based RAGs, as they are very accurate. 😄
      Thanks! 👊

  • @DePhpBug
    @DePhpBug 5 месяцев назад

    I just finished learning the ChromaDB , can the GraphRAG works with ChromaDB instead of Neo4J?

  • @tuba-inxs
    @tuba-inxs 5 месяцев назад

    Is this really an RDF Knowledge Grap, or just a Neo4J property graph. That doesn't look like a SPARQL query in your code.

    • @codingcrashcourses8533
      @codingcrashcourses8533  5 месяцев назад

      Hm I am not a Graph Expert to be honest. I had go through some tutorials myself to learn how to construct a query first, since I mainly worked with the RAG part so far. How would it look like in your opinion?

  • @Future_me_66525
    @Future_me_66525 5 месяцев назад

    How much VRAM and RAM do you think it takes to run the 70b model at minimum?

    • @Yes-lm9dq
      @Yes-lm9dq 3 месяца назад

      The amount of VRAM you would need is roughly 70 x 2 = 140gb

  • @maxlgemeinderat9202
    @maxlgemeinderat9202 5 месяцев назад

    Interesting! Is Neo4j language dependent? So is it capable of finding relations of multilingual data or does Neo4j not care about the language and only the LLM to create the knowledge graph should be multilingual?

    • @codingcrashcourses8533
      @codingcrashcourses8533  5 месяцев назад +2

      the LLM is responsible for creating the entites and documents, you will just save them in the required format in the database. Neo4J has got many libraries with different languages. The format of the documents matter.

  • @Sundaysun9633
    @Sundaysun9633 5 месяцев назад

    Cool 🤙

  • @oluwaseunakinropo6318
    @oluwaseunakinropo6318 5 месяцев назад

    Hii, amazing content as usual man, i am trying to implement this noe4j graph on my pc after downloading your code, i went to neo4jaura and downloaded a .txt file containing the database credentials but whenever i try it from your code i get this error message below, please help
    " Could not connect to Neo4j database. Please ensure that the url is correct"
    it is exactly the same thing i downloaded from their website

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

      .env file is not in his code. So, you'd have to create your own OPENAI_API_KEY and the neo4j username and password. Remember to set the NEO$J_URI to bolt://localhost:7687

  • @Yes-lm9dq
    @Yes-lm9dq 3 месяца назад

    I tried following the tutorial and encountered some issues (I suspect the issue stems from the openai fallback?). Anyways, I have created a pull request on your github. Hope that helps anyone who wants to only use local models and encountered a similar problem.

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

      @@Yes-lm9dq i will have a Look at it and merge it if it suits the issue

  • @kevli6373
    @kevli6373 5 месяцев назад

    Thank u for great video.
    Is it possible to still use ollama via langchain? I got a error when i use "if llmtype=="olllama"
    -- error message : Received unsupported message type for Ollama.
    (my_path) : LangChainDeprecationWarning: The method `BaseChatModel.__call__` was deprecated in langchain-core 0.1.7 and will be removed in 0.3.0. Use invoke instead.
    warn_deprecated(

    • @codingcrashcourses8533
      @codingcrashcourses8533  5 месяцев назад +1

      Did you change something in the codebase? Which line exactly produces this error? I have used the invoke method, to perform calls to the LLMs, so this kind of warning should not appear

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

    It took me 100 minutes to compute the graph on my 32GB i7 machine

  • @dimensionalcookie
    @dimensionalcookie 5 месяцев назад

    look like llama cant generate low resource language like Vietnamese

    • @codingcrashcourses8533
      @codingcrashcourses8533  5 месяцев назад

      no, but to honest most models have issues with that. You probably have to create the english documents first and then try to translate it

    • @dimensionalcookie
      @dimensionalcookie 5 месяцев назад

      @@codingcrashcourses8533 when i first tried it since release, it failed to generate low resource language, but i just tested in Poe, it seems to work well now. Btw thank you, your content really help.

    • @dimensionalcookie
      @dimensionalcookie 5 месяцев назад

      @@codingcrashcourses8533 I really appreciate your content. When i first test with togetherAI, it only responded with English, it seems work well now when i tested again

  • @tawakalitolamide578
    @tawakalitolamide578 5 месяцев назад

    Thank you for this video, I have been looking for a way to use local graphrag until I see this. Thank you so much.
    But I encountered an issue while using the neo4j browser. It keeps saying "Cannot load from URL 'file:///import/test_container.csv': Couldn't load the external resource at: file:///import/test_container.csv ()"
    I have tried all means to resolve this issue but the error keep persisting. Please I need your help.

    • @codingcrashcourses8533
      @codingcrashcourses8533  5 месяцев назад +1

      You got this issue when running my code? I don´t use a test_container.csv file

    • @tawakalitolamide578
      @tawakalitolamide578 5 месяцев назад

      @@codingcrashcourses8533 No, I did not get the issue while running your code. I already solved it. Thank you

  • @mahoanghai3364
    @mahoanghai3364 5 месяцев назад

    Cool. Thank a lot

  • @kevli6373
    @kevli6373 5 месяцев назад +1

    for entity in entities.names:
    response = graph.query(
    """CALL db.index.fulltext.queryNodes('entity', $query, {limit:2})
    YIELD node,score
    CALL {
    WITH node
    MATCH (node)-[r:!MENTIONS]->(neighbor)
    RETURN node.id + ' - ' + type(r) + ' -> ' + neighbor.id AS output
    UNION ALL
    WITH node
    MATCH (node)

    • @codingcrashcourses8533
      @codingcrashcourses8533  5 месяцев назад

      @@kevli6373 did you try openai models too? Or just the small 8b llama model?

    • @kevli6373
      @kevli6373 5 месяцев назад

      @@codingcrashcourses8533
      I used only openai model.
      i got a message :
      ClientError: {code: Neo.ClientError.Procedure.ProcedureCallFailed} {message: Failed to invoke procedure db.index.fulltext.queryNodes: Caused by: java.lang.IllegalArgumentException: There is no such fulltext schema index: entity}
      Output is truncated. View as a scrollable element or open in a text editor. Adjust cell output settings...
      😂

    • @kevli6373
      @kevli6373 5 месяцев назад

      @@codingcrashcourses8533 thank you reply. i used only openai model. i didnt try llama yet.

    • @kevli6373
      @kevli6373 5 месяцев назад

      @@codingcrashcourses8533 I used only OpenAI gpt 4o mini not llama. In your case, Does it work well for both ?

    • @codingcrashcourses8533
      @codingcrashcourses8533  5 месяцев назад

      @@kevli6373 I had issues with Llama 8B. Everything else worked fine :/. The LLM seems not be able to create/extract entities