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
You did a great job of explaining llm graph transformer clearly.
Thanks for your support :)
Sridhar, Great job! Thanks
thank you :)
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.
yes, these tools and technologies are still improving everyday. Sometime not too far in the future, we will get minimum acceptable accuracy required..
great! apprecitate this!
thank you very much for your support :)
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.
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...
With structured data in your previous pgsql examples, can we still apply graphdb concepts on structure data for optimal rag retrieval?
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...
@@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?
how to i use multiple Neoj4 database's at the same time.. is this possible
you can use only one db in the free version.
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?
Langchain library is being updated very frequently. Pls check the latest docs/APIs. Did you resolve the issue ? Whats the error pls...
hello, thank you for this video it was very helpful, how do i link the project to the neo4j desktop client ?
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()
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?
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...
Hi... Do you provide any courses on machine learning or ai?
I don't have any structured course year on ML but I'm planning to do one.
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'
The output format from LLM models is important for these things.
stackoverflow.com/questions/78521181/llmgraphtransformer-convert-to-graph-documentsdocuments-attributeerror-str
Bro youre the best, you have saved my Thesis. Only question is how to retrieve
thanks for your support :)
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
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.
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.
you can create a .env file and paste your openapi key , OPENAI_API_KEY=your_api_key
You can add key either directly in the code using this command os.environ["OPENAI_API_KEY"] = "YOUR_KEY"
I've setup the key in my environmental variables in the bashrc file
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.
It is resolved? What error are you getting? After installing neo4j desktop, you need to install a couple of plugins also from neo4j desktop.
@@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.
when do you expect GraphRag to be production ready ?
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.
@@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 ?
Ollama based llms don't work with the LLMGraphTransformer do you know why?
I've not tested that, what error are you getting?
@@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.
@@SridharKumarKannam AttributeError on calling LLMGraphTransformer.convert_to_graph_documents
AttributeError on calling LLMGraphTransformer.convert_to_graph_documents having this error
it runs ollama server but ends with this error
@@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
You can view your graphs with Neo4j bloom also
thats right, Thanks for your support :)
How can we process large documents. It takes so much time.
And how can we use aconvert_to_graph_documents function
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.
What software is he using?
Neo4j
Thanks for your support :)
Yes it is.
What api key you are using and From where do you get it?
many frameworks use openai by default if we don't specify a model explicitly. The key in my config files.
Can you provide for the code
the link is in the description...
You explained it well but the results are always inconsistent.
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.
@@SridharKumarKannam I did but still not consistent results 😢