Retrieval-Augmented Generation (RAG)
Retrieval-Augmented Generation (RAG) is a technique that improves the responses of LLMs by providing them with relevant, up-to-date information retrieved from external sources.

Retrieval-Augmented Generation (RAG) with Vectors
This typically involves converting text into vector embeddings that encodes the semantic meaning of the text, in a format that the user understands, and then using similarity search to find relevant information.

Vector-based RAG
Vectors work well for:
-
Contextual or Meaning Based Questions
-
Synonyms or Paraphrasing
-
Fuzzy or Vague queries
-
Broad or Open-Ended questions
-
Complex queries with multiple concepts
What does Paul Graham think about Generative AI?
Vectors are ineffective for:
-
Highly Specific or Fact-Based Questions
-
Numerical or Exact-Match Queries
-
Boolean or Logical Queries
-
Ambiguous or Unclear Queries without Context
-
Specialised Knowledge
How many Generative AI Startups has Paul Graham invested in?
Unstructured data as vectors
Text | Vector embedding |
---|---|
She’s just a small town girl |
[0.12, -0.34, 0.56, 0.78, …, -0.91] |
Living in a lonely world |
[0.22, 0.45, -0.67, 0.11, …, 0.33] |
She took the midnight train |
[-0.55, 0.89, 0.12, -0.44, …, 0.67] |
Going anywhere |
[0.78, -0.23, 0.45, 0.91, …, -0.12] |
Unstructured data as a graph
Text | Vector embedding |
---|---|
She’s just a small town girl |
[0.12, -0.34, 0.56, 0.78, …, -0.91] |
Living in a lonely world |
[0.22, 0.45, -0.67, 0.11, …, 0.33] |
She took the midnight train |
[-0.55, 0.89, 0.12, -0.44, …, 0.67] |
Going anywhere |
[0.78, -0.23, 0.45, 0.91, …, -0.12] |

Knowledge Graphs
GraphRAG involves creating a knowledge graph of nodes and relationships contained in unstructured data.

Nodes
-
Nodes represent things
-
Nodes are grouped by labels
-
Nodes are described by properties as key-value pairs
A boy with thedescription
of City Boy
A Location with thename
South Detroit.

Relationships
-
Any two nodes can be connected by a relationship
-
Each relationship has a type and a direction
-
Relationships have properties as key-value pairs
The City Boy took the Midnight Train going Anywhere.

Cypher
Cypher is a A Powerful & Expressive Query Language for querying graphs.
Steps of GraphRAG
The term Graph RAG encapsulates the process of extracting nodes and relationships from unstructured text, which sit along the vector embeddings in the knowledge graph.
The knowledge graph structure can be enriched with additional features derived from graph algorithms in the Neo4j Graph Data Science library, providing deeper insights into the data’s patterns and connections.
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 we progress through the course.