Langchain & Neo4j: Create Knowledge Graphs from Text

  Рет қаралды 13,010

Hands-on AI

Hands-on AI

Күн бұрын

-
python.langcha...
#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

Пікірлер: 85
@SridharKumarKannam
@SridharKumarKannam Ай бұрын
If you found this content useful, pleases consider sharing it with others who might benefit. Your support is greatly appreciated :)
@fernyd.t.6716
@fernyd.t.6716 7 күн бұрын
I am working in a big research project for over two months and I finally found the perfect video for my graph! It turned out amazing!!
@SridharKumarKannam
@SridharKumarKannam 3 күн бұрын
Thank you. If you found this content helpful, please consider sharing it with others who might benefit. Your support is greatly appreciated :)
@syntheticperson
@syntheticperson Ай бұрын
Exciting and inspiring! Thanks for sharing.
@SridharKumarKannam
@SridharKumarKannam Ай бұрын
Thanks for your support :)
@johnhelewa
@johnhelewa 4 ай бұрын
You did a great job of explaining llm graph transformer clearly.
@SridharKumarKannam
@SridharKumarKannam 4 ай бұрын
Thanks for your support :)
@SuperTipu10
@SuperTipu10 Ай бұрын
Amazing work, thank you so much!
@SridharKumarKannam
@SridharKumarKannam Ай бұрын
Thanks for your support. Pleases consider sharing it in your communities who might benefit. Your support is greatly appreciated :)
@prriyamvradhaparthasarathi9804
@prriyamvradhaparthasarathi9804 27 күн бұрын
Amazing video! It clearly explains the concept. I have one question: The nodes and relationships are created by the LLM, so every time the code is run, it generates a different output. How do we handle that? Additionally, you spoke about allowed nodes and relationships. In a real-time scenario, when we don't have much knowledge about the input file, how can we extract all the entities and relationships from the document so that we don't miss any information? Your suggestions on this would be very helpful. Thank you!
@SridharKumarKannam
@SridharKumarKannam 22 күн бұрын
1. first run without any schema - this will result in a lot of node and relationship types. 2. Analyse nodes+relations to find out which ones are important for your use case. 3. now run it with a fixed schema If you found this content helpful, please consider sharing it with others who might benefit. Your support is greatly appreciated :)
@matp3209
@matp3209 Ай бұрын
Very useful! Thanks so much!
@SridharKumarKannam
@SridharKumarKannam Ай бұрын
Thanks for your support :)
@varuntirupati2566
@varuntirupati2566 4 ай бұрын
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 4 ай бұрын
yes, these tools and technologies are still improving everyday. Sometime not too far in the future, we will get minimum acceptable accuracy required..
@Shaan_Suri
@Shaan_Suri Ай бұрын
Hi sir, thank you for your great video. Two questions for you (or for anyone else): 1) What exactly does langchain Document do? Why not just feed raw text straight into the LLM Graph Transformer and let it extract relationships/identify entities? 2) What are some resources I can use to learn specifically about how the LLM Graph Transformer works? Thank you kindly.
@SridharKumarKannam
@SridharKumarKannam Ай бұрын
(1) That the format llm_transformer expects. Your text content is still the same. (2) llm_transformer as it is shown in the video is specific to langchain, refer to the documentation. There is a ton of info on converting text to KGs, including my channel has a number of videos. All the best...
@williammariasoosai1153
@williammariasoosai1153 5 ай бұрын
Sridhar, Great job! Thanks
@SridharKumarKannam
@SridharKumarKannam 5 ай бұрын
thank you :)
@somjrgebn
@somjrgebn 3 ай бұрын
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 3 ай бұрын
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 2 ай бұрын
With structured data in your previous pgsql examples, can we still apply graphdb concepts on structure data for optimal rag retrieval?
@SridharKumarKannam
@SridharKumarKannam 2 ай бұрын
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 2 ай бұрын
@@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?
@animation-1023
@animation-1023 Ай бұрын
I am writing this query to get output "response=chain.invoke({"query":"what was the name of SPOUSE of Marie Curie?"}) response" but in output it is giving "'result': "I don't know the answer. "}" although in neo4j it is showing relationship
@SridharKumarKannam
@SridharKumarKannam Ай бұрын
Did you run the query multiple times and got the same output? All LLMs are stochastic (random) in nature, some times strange results are expected.
@nullvoid12
@nullvoid12 4 ай бұрын
You can view your graphs with Neo4j bloom also
@SridharKumarKannam
@SridharKumarKannam 4 ай бұрын
thats right, Thanks for your support :)
@lnaehhrai
@lnaehhrai Ай бұрын
Did you share the notebook? I can't find it. It will be helpful to be able to run in on our own.
@SridharKumarKannam
@SridharKumarKannam Ай бұрын
Pls check the link in the description, its a link to the tutorial. If you found this content helpful, please consider sharing it with others who might benefit. Your support is greatly appreciated :)
@jingluhan3289
@jingluhan3289 2 ай бұрын
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 2 ай бұрын
The output format from LLM models is important for these things. stackoverflow.com/questions/78521181/llmgraphtransformer-convert-to-graph-documentsdocuments-attributeerror-str
@dipanjansaha6824
@dipanjansaha6824 Ай бұрын
Instead of text, can we do it from 2 tables instead? Maybe two columns in two tables?
@SridharKumarKannam
@SridharKumarKannam Ай бұрын
You can if you have text in those columns. The source can be anything, as long as you format in the text format...
@datatalkswithchandranshu2028
@datatalkswithchandranshu2028 2 ай бұрын
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 2 ай бұрын
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.
@mystic2212
@mystic2212 2 ай бұрын
Bro youre the best, you have saved my Thesis. Only question is how to retrieve
@SridharKumarKannam
@SridharKumarKannam 2 ай бұрын
thanks for your support :)
@Prashant-s7f
@Prashant-s7f 5 ай бұрын
Hi... Do you provide any courses on machine learning or ai?
@SridharKumarKannam
@SridharKumarKannam 5 ай бұрын
I don't have any structured course year on ML but I'm planning to do one.
@matheusaltomarecruz4598
@matheusaltomarecruz4598 4 ай бұрын
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 4 ай бұрын
Langchain library is being updated very frequently. Pls check the latest docs/APIs. Did you resolve the issue ? Whats the error pls...
@Shivam-bi5uo
@Shivam-bi5uo 3 ай бұрын
great! apprecitate this!
@SridharKumarKannam
@SridharKumarKannam 3 ай бұрын
thank you very much for your support :)
@shehzadahmed1782
@shehzadahmed1782 5 ай бұрын
how to i use multiple Neoj4 database's at the same time.. is this possible
@SridharKumarKannam
@SridharKumarKannam 5 ай бұрын
you can use only one db in the free version.
@anshumangiramkar2589
@anshumangiramkar2589 5 ай бұрын
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 5 ай бұрын
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 5 ай бұрын
@@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.
@luisramos1977
@luisramos1977 4 ай бұрын
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 4 ай бұрын
you can create a .env file and paste your openapi key , OPENAI_API_KEY=your_api_key
@SridharKumarKannam
@SridharKumarKannam 4 ай бұрын
You can add key either directly in the code using this command os.environ["OPENAI_API_KEY"] = "YOUR_KEY"
@SridharKumarKannam
@SridharKumarKannam 4 ай бұрын
I've setup the key in my environmental variables in the bashrc file
@usmanjalil6711
@usmanjalil6711 2 ай бұрын
How can we process large documents. It takes so much time.
@usmanjalil6711
@usmanjalil6711 2 ай бұрын
And how can we use aconvert_to_graph_documents function
@SridharKumarKannam
@SridharKumarKannam 2 ай бұрын
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.
@malikanaser8251
@malikanaser8251 5 ай бұрын
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 4 ай бұрын
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...
@awakenwithoutcoffee
@awakenwithoutcoffee 3 ай бұрын
when do you expect GraphRag to be production ready ?
@SridharKumarKannam
@SridharKumarKannam 2 ай бұрын
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 2 ай бұрын
@@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 ?
@leed2002isa
@leed2002isa 5 ай бұрын
hello, thank you for this video it was very helpful, how do i link the project to the neo4j desktop client ?
@SridharKumarKannam
@SridharKumarKannam 5 ай бұрын
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()
@retro-gameplay-new
@retro-gameplay-new Ай бұрын
Can it will possible using Gemini Model
@SridharKumarKannam
@SridharKumarKannam Ай бұрын
Yes, it should work with Gemini and most LLMs as long as their output format is as expected. If you found this content helpful, please consider sharing it with others who might benefit. Your support is greatly appreciated :)
@weebprogrammer2979
@weebprogrammer2979 3 ай бұрын
You explained it well but the results are always inconsistent.
@SridharKumarKannam
@SridharKumarKannam 3 ай бұрын
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 3 ай бұрын
@@SridharKumarKannam I did but still not consistent results 😢
@shadyhamrouny8755
@shadyhamrouny8755 5 ай бұрын
Ollama based llms don't work with the LLMGraphTransformer do you know why?
@SridharKumarKannam
@SridharKumarKannam 5 ай бұрын
I've not tested that, what error are you getting?
@shadyhamrouny8755
@shadyhamrouny8755 5 ай бұрын
@@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 4 ай бұрын
@@SridharKumarKannam AttributeError on calling LLMGraphTransformer.convert_to_graph_documents
@somashekharb1846
@somashekharb1846 4 ай бұрын
AttributeError on calling LLMGraphTransformer.convert_to_graph_documents having this error it runs ollama server but ends with this error
@JelckedeBoer
@JelckedeBoer 4 ай бұрын
@@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
@jeffhaskin895
@jeffhaskin895 4 ай бұрын
What software is he using?
@hazardscarn
@hazardscarn 4 ай бұрын
Neo4j
@SridharKumarKannam
@SridharKumarKannam 4 ай бұрын
Thanks for your support :)
@SridharKumarKannam
@SridharKumarKannam 4 ай бұрын
Yes it is.
@RishuKumarMishra-pt9pf
@RishuKumarMishra-pt9pf 5 ай бұрын
What api key you are using and From where do you get it?
@SridharKumarKannam
@SridharKumarKannam 5 ай бұрын
many frameworks use openai by default if we don't specify a model explicitly. The key in my config files.
@rabbit1259
@rabbit1259 3 ай бұрын
Can you provide for the code
@SridharKumarKannam
@SridharKumarKannam 3 ай бұрын
the link is in the description...
Text to Knowledge Graphs
17:06
Hands-on AI
Рет қаралды 1 М.
Langchain & Neo4j: Query Your Graph Database in Natural Language
19:02
The Joker wanted to stand at the front, but unexpectedly was beaten up by Officer Rabbit
00:12
escape in roblox in real life
00:13
Kan Andrey
Рет қаралды 82 МЛН
Brawl Stars Edit😈📕
00:15
Kan Andrey
Рет қаралды 53 МЛН
Graph RAG: Improving RAG with Knowledge Graphs
15:58
Prompt Engineering
Рет қаралды 62 М.
Complete Session On Knowledge Graph and GraphDb With Langchain
2:05:00
Llama3.2 - Tiny But Mighty
10:14
Hands-on AI
Рет қаралды 164
[Webinar] LLMs for Evaluating LLMs
49:07
Arthur
Рет қаралды 10 М.
GraphRAG: The Marriage of Knowledge Graphs and RAG: Emil Eifrem
19:15
Local GraphRAG with LLaMa 3.1 - LangChain, Ollama & Neo4j
15:01
Coding Crash Courses
Рет қаралды 19 М.
Microsoft GraphRAG: The Best RAG + KG Architecture
16:34
Hands-on AI
Рет қаралды 3,6 М.
Understand & Visualise Microsoft GraphRAG
33:16
Hands-on AI
Рет қаралды 2,4 М.
Build an Advanced RAG Chatbot with Neo4j Knowledge Graph
7:42
Leann Chen
Рет қаралды 13 М.
The Joker wanted to stand at the front, but unexpectedly was beaten up by Officer Rabbit
00:12