Knowledge Graph
Extract entities and relationships from conversations
Memoid’s knowledge graph extracts entities and relationships, enabling rich connected queries.
Concepts
Entities
Named things in your data:
- People — “John”, “Sarah Chen”
- Organizations — “Acme Corp”, “Google”
- Places — “San Francisco”, “New York”
- Concepts — “machine learning”, “project alpha”
Relationships
Connections between entities:
- John works_at Acme Corp
- Sarah manages John
- Acme Corp located_in San Francisco
Extracting Knowledge
With Memory Addition
Enable graph extraction when adding memories:
result = client.add(
messages=[{
"role": "user",
"content": "My manager Sarah just got promoted to VP at TechCorp"
}],
user_id="user_123",
extract_graph=True
)
# Extracted entities:
# - Sarah (person)
# - VP (role)
# - TechCorp (organization)
# Extracted relationships:
# - Sarah has_role VP
# - Sarah works_at TechCorp Direct Extraction
Extract from any text:
result = client.extract_knowledge(
text="John and Sarah co-founded Acme Corp in 2020. John is the CEO.",
store=True # Save to graph
)
print(result.entities)
# [John (person), Sarah (person), Acme Corp (organization), CEO (role)]
print(result.relationships)
# [John co-founded Acme Corp, Sarah co-founded Acme Corp, John has_role CEO] Querying the Graph
Find Related Entities
result = client.graph_query(
entity="John",
depth=2 # Traverse 2 relationship hops
)
# Returns all entities within 2 hops of "John"
# John -> works_at -> Acme Corp -> located_in -> San Francisco Search by Relationship
result = client.graph_search(
query="Who works at Acme Corp?"
) Managing Entities
Add Entity
client.add_entity(
name="Acme Corp",
type="organization",
attributes={
"industry": "technology",
"founded": 2020
}
) Add Relationship
client.add_relationship(
source="John",
relation="works_at",
target="Acme Corp"
) Delete Entity
client.delete_entity("John") # Also removes relationships Entity Types
Common entity types:
personorganizationlocationroleprojectproducteventconcept
Custom types are supported.
Use Cases
User Profile Building
Extract and connect information about users:
- Preferences
- Relationships
- Activities
- Context
Organizational Knowledge
Map company structures:
- Team hierarchies
- Project assignments
- Expertise areas
Recommendation Systems
Traverse connections:
- “People who like X also…”
- “Related to your network…”
Best Practices
- Define your schema — Decide on entity and relationship types upfront
- Handle ambiguity — “Apple” could be fruit or company
- Merge carefully — Same entity may appear with different names
- Prune regularly — Remove outdated relationships