Skip to main content
Knowledge graphs connect related entities, facts, and concepts. Mem[v] automatically builds semantic graphs showing how people, topics, and events relate.

What are knowledge graphs?

Knowledge graphs represent information as interconnected triplets: Subject → Predicate → Object Examples:
  • Sarah Chenworks_atAcme Corp
  • UserprefersDark mode
  • FastAPIis_used_forBuilding APIs

Retrieve triplets

from memvai import Memv

client = Memv()

# Retrieve triplets for a memory
triplets = client.graph.retrieve_triplets(
    type="memory",
    id="mem_xyz789"
)

# Print relationships
for triplet in triplets:
    print(f"{triplet['subject']}{triplet['predicate']}{triplet['object']}")

Building knowledge graphs

Knowledge graphs are automatically built from your memories:
# Add memories with entities
client.memories.add(
    space_id="space_abc123",
    content="Alice Johnson is the CTO at TechCorp. She specializes in distributed systems."
)

client.memories.add(
    space_id="space_abc123",
    content="Alice Johnson uses Kubernetes for container orchestration."
)

# Mem[v] automatically creates triplets:
# - Alice Johnson → works_at → TechCorp
# - Alice Johnson → role → CTO
# - Alice Johnson → specializes_in → distributed systems
# - Alice Johnson → uses → Kubernetes

Use cases

Create comprehensive user profiles from their interactions and preferences.
Build company knowledge graphs with people, teams, and technologies.
Link research papers, concepts, and discoveries.
Map product requirements, dependencies, and technologies.

Best practices

Write memories as clear subject-predicate-object statements.Good: "Sarah Chen is the VP of Engineering at Acme Corp"Less good: "Sarah is pretty high up in engineering I think"
Use precise language for relationships.Good: "The API uses PostgreSQL for data storage"Less good: "We have PostgreSQL"
Use full names and clear references.Good: "John Smith manages the DevOps team"Less good: "John manages it" (ambiguous)

Next steps

Memories

Add more memories to build graphs

Advanced usage

Advanced SDK features