"매 entity-relationship triples 의 graph". Knowledge Graph 는 (head, relation, tail) triple 의 collection 으로 구조화된 knowledge 를 저장하는 graph database paradigm. 2012 Google 의 도입 이후 search/RAG/agents 의 backbone 으로 자리잡았으며, 2026 LLM era 에서는 GraphRAG 와 entity-linking 으로 hallucination mitigation 에 사용.
importnetworkxasnxG=nx.MultiDiGraph()G.add_edge("Anthropic","Claude",relation="created")G.add_edge("Claude","LLM",relation="instanceOf")G.add_edge("Anthropic","San Francisco",relation="locatedIn")# query: what did Anthropic create?for_,target,datainG.out_edges("Anthropic",data=True):ifdata["relation"]=="created":print(target)# Claude
LLM 으로 triple 추출
fromanthropicimportAnthropicclient=Anthropic()text="Claude Opus 4.7 was released by Anthropic in 2026."resp=client.messages.create(model="claude-opus-4-7",max_tokens=512,messages=[{"role":"user","content":f"Extract (subject, predicate, object) triples as JSON from: {text}"}])# → [["Claude Opus 4.7","releasedBy","Anthropic"], ...]
Neo4j Cypher query
// find all 2-hop neighbors of Anthropic
MATCH (a:Org {name:"Anthropic"})-[r1]->(x)-[r2]->(y)
RETURN a, r1, x, r2, y
LIMIT 100;
RDF + SPARQL
fromrdflibimportGraph,URIRef,Literalg=Graph()g.parse("dbpedia.ttl",format="turtle")q="""
SELECT ?company WHERE {
?company a <http://dbpedia.org/ontology/Company> ;
<http://dbpedia.org/property/foundedYear> "2021"^^xsd:gYear .
}
"""forrowing.query(q):print(row.company)