Graphs and RAG
1. Graphs and RAG
Welcome to Graph RAG with LangChain and Neo4j!2. Meet your instructor
I'm Adam Cowley, Manager of Developer Education at Neo4j and instructor for this course. I teach developers and data scientists how to use Neo4j through GraphAcademy, our free online training platform. I have over twenty years experience developing web and mobile applications, including ten years working with Neo4j.3. The R in RAG
In the last course, you learned that vector-based Retrieval-Augmented Generation, or RAG, improves the responses4. The R in RAG
generated by Large Language Models by fetching data from external sources.5. The R in RAG
This often involves converting data into vector embeddings, which encode the text into numbers that capture its semantic meaning. Then, using semantic search to find similar documents based on a user input.6. Where does semantic search fail?
While this approach works for vague, fuzzy or open-ended questions, for example "What does Paul Graham think about Generative AI?" The approximate nature of distance based semantic similarity means this approach falls short when the question requires a more precise, numerical or logic based answer. If the text retrieved does not mention the exact answer, the LLM will be unable to confidently answer the question "How many Generative AI Startups has Paul Graham invested in?"7. Vectors vs. knowledge graphs
GraphRAG addresses these limitations by organizing the unstructured text data into a structured graph of nodes and relationships.8. Vectors vs. knowledge graphs
Nodes represent things, and are categorized by labels. Think of these as rows in a table or documents in a collection.9. Vectors vs. knowledge graphs
Any two nodes can be connected by one or more relationships, each of which will have a type and a direction.10. Knowledge graphs and Neo4j
Throughout this course, we will use Neo4j, the world's leading graph database to store and query a knowledge graph. Neo4j does not require schema changes for updates, so new labels and relationship types can be added to adapt as the application grows. We will use the langchain-neo4j integration library, along with LangChain’s Expression Language, LCEL, to extract a knowledge graph from text and use it to improve LLM-generated responses.11. Nodes represent things
The langchain_neo4j library has a helper class for representing nodes. We define the type of node, in this example a Book, provide a unique identifier and, optionally, a dictionary of properties that describe the node.12. Relationships connect nodes
We will create relationships between nodes with the Relationship class. Let's say we want to create a relationship between the Book and its authors.13. Relationships connect nodes
We define the book as the source14. Relationships connect nodes
and the author as the destination of the relationship.15. Relationships connect nodes
The type of relationship is WRITTEN_BY, and we may also provide a dictionary of properties that describe the relationship in more detail.16. Connecting to Neo4j
We will add the nodes and relationships to a graph, and then store that graph in a Neo4j database using the Neo4jGraph class. To connect to the database, we create an instance of the class with our database credentials. In this course, we've created a database instance for you to connect to, but see the documentation below to create a database for your own projects.17. Saving graph documents
Then, to save nodes and relationships to the graph, create an instance of GraphDocument - a wrapper for a list of nodes and relationships. GraphDocuments are saved to the database with the .add_graph_documents() method of the Neo4jGraph class.18. So, what is GraphRAG?
The term Graph RAG encapsulates the process of19. So, what is GraphRAG?
extracting nodes and relationships from unstructured text. Then querying the resulting knowledge graph, sometimes in combination with vector search, to retrieve the necessary information for the task. We will explore these points in more detail as you go through the course.20. Let's practice!
For now, it is time to create your first nodes and relationships.Create Your Free Account
or
By continuing, you accept our Terms of Use, our Privacy Policy and that your data is stored in the USA.