What is Knowledge Graph and How it's used in Gen AI?
For past 1 year I have been working as a component designer in telecom and have extensively used Graph Database with Kafka for proactive assurance.
During last residency at ISB we were introduced to Knowledge graph and Neo4j's use case in building it. In this blog we will understand the basics of Graph DB and how it's used in Gen AI.
What is Knowledge Graph ?
Traditional database are tabular in nature with foreign key used to create relationships and to infer relations using aggregate or group by function. Graph db established relationship in the structure itself.
A- worksat-> XYZ.
A and XYZ are called Nodes and worksat is the relationship built between them. Each Node can hold multiple properties which are unique/common to itself.
For instance:
Example
Nodes
Relationships
领英推荐
Explanation
Cypher Query
from py2neo import Graph, Node, Relationship
# Connect to the Neo4j database
graph = Graph("bolt://localhost:7687", auth=("neo4j", "password"))
# Create Nodes
person = Node("Person", name="A", age=30, height=175)
company = Node("Company", name="XYZ", location="New York")
# Create Relationship
works_at = Relationship(person, "WORKS_AT", company)
# Add Nodes and Relationship to the graph
graph.create(works_at)
Query in Graph DB
# Query to find all people who work at a specific company
query = """
MATCH (p:Person)-[:WORKS_AT]->(c:Company {name: 'XYZ'})
RETURN p.name, p.age, p.height
"""
results = graph.run(query)
for record in results:
print(f"Name: {record['p.name']}, Age: {record['p.age']}, Height: {record['p.height']}")
When to use Graph DB?
Graph DB should be used when you are not bound by ACID properties ie (Atomicity, Consistency, Isolation and Durability). They are widely used where relationship and connections are of paramount importance and are generally avoided for transactional dataset.
Knowledge Graph in LLM
Unstructured data is used to finetune and pretrain LLM by incorporating Knowledge graph we can give more contextual information. Knowledge Graphs enable LLMs to provide more comprehensive answers by contextualizing the retrieved information. This is done through vector searches that locate relevant nodes within the graph, identifying the shortest paths or neighborhoods around these nodes.
Conclusion
By incorporating Knowledge Graph we can increase the understanding and uncover new relations for our existing LLM use case.
Special thanks to Prof. Sunila Gollapudi for introducing the Knowledge graph and it's practical use case in the last residency class.
Co-Founder of Altrosyn and DIrector at CDTECH | Inventor | Manufacturer
7 个月A Knowledge Graph is a structured representation of knowledge as a network of entities and their relationships. In Gen AI, KGs provide factual grounding and context for text generation, enabling models to produce more accurate, relevant, and coherent outputs. They enhance tasks like question answering, summarization, and dialogue systems by leveraging semantic understanding. Think of it like this: while Transformer models excel at capturing linguistic patterns, KGs offer the world knowledge base they need to make sense of those patterns. This symbiotic relationship empowers Gen AI to move beyond simple pattern matching towards true comprehension and reasoning. How does the schema design in a Knowledge Graph, particularly the use of RDF triples, compare to the concept of embeddings in word2vec or BERT, considering their respective strengths and limitations in representing semantic relationships?