Logic Mesh extracts entity-relationship graphs from your documents, enabling powerful graph traversal and relationship-aware search. Instead of just finding documents that mention “John”, you can ask “Who reports to John?” or “What companies has John worked at?”
What is Logic Mesh?
Logic Mesh automatically extracts:
- Entities: People, companies, products, concepts
- Relationships: works_at, reports_to, founded, acquired, etc.
- Properties: Attributes attached to entities
Enabling Logic Mesh
During Ingestion
# Enable entity-relationship extraction
memvid put memory.mv2 --input documents/ --logic-mesh
For Existing Memories
# Enrich existing documents with graph extraction
memvid enrich memory.mv2 --engine groq
Logic Mesh extraction requires an enrichment engine. Use --logic-mesh during ingestion or run memvid enrich afterward.
Graph Traversal Commands
List All Entities
# Show all extracted entities
memvid follow entities memory.mv2
# Filter by entity type
memvid follow entities memory.mv2 --kind person
memvid follow entities memory.mv2 --kind company
memvid follow entities memory.mv2 --kind product
# Search entities by name
memvid follow entities memory.mv2 --query "John"
# Limit results
memvid follow entities memory.mv2 --limit 20
# JSON output
memvid follow entities memory.mv2 --json
Output:
Entities (87 total)
People:
- John Smith (34 relationships)
- Jane Doe (28 relationships)
- Sarah Chen (19 relationships)
Companies:
- Acme Corp (45 relationships)
- StartupXYZ (12 relationships)
- TechGiant Inc (8 relationships)
Products:
- Project Alpha (15 relationships)
- Platform v2 (9 relationships)
Traverse Relationships
# Find what John Smith is connected to
memvid follow traverse memory.mv2 --start "John Smith"
# Follow specific relationship type
memvid follow traverse memory.mv2 --start "John Smith" --link works_at
# Control traversal depth (default: 2)
memvid follow traverse memory.mv2 --start "Acme Corp" --hops 3
# Direction: outgoing, incoming, or both
memvid follow traverse memory.mv2 --start "Jane Doe" --direction incoming
Output:
Traversal from: John Smith (depth: 2)
Direct relationships (hop 1):
──[works_at]──▶ Acme Corp
──[reports_to]──▶ Jane Doe
──[leads]──▶ Project Alpha
──[expertise]──▶ Rust, Python
Extended relationships (hop 2):
Acme Corp ──[acquired]──▶ StartupXYZ
Acme Corp ──[headquartered_in]──▶ San Francisco
Jane Doe ──[reports_to]──▶ CEO Board
Project Alpha ──[uses]──▶ Platform v2
Graph Statistics
memvid follow stats memory.mv2
Output:
Logic Mesh Statistics
Entities: 87
- person: 34
- company: 18
- product: 15
- concept: 20
Relationships: 423
- works_at: 45
- reports_to: 32
- founded: 12
- acquired: 8
- uses: 56
- expertise: 89
- other: 181
Graph density: 4.86 edges/node
Connected components: 3
Largest component: 72 entities
Triple Patterns
Query relationships using Subject:Predicate:Object patterns with ? as a wildcard:
| Pattern | Meaning |
|---|
John:works_at:? | Where does John work? |
?:CEO:Acme | Who is CEO of Acme? |
?:works_at:Acme | Who works at Acme? |
John:?:Acme | How is John related to Acme? |
?:reports_to:Jane | Who reports to Jane? |
CLI Usage
# Find where John works
memvid find memory.mv2 --graph "John Smith:works_at:?"
# Find who works at Acme
memvid find memory.mv2 --graph "?:works_at:Acme Corp"
# Find all relationships between two entities
memvid find memory.mv2 --graph "John Smith:?:Acme Corp"
Combining Graph + Text Search
The real power of Logic Mesh is combining graph traversal with text search.
Graph-Filtered Search
Filter search results by relationships first, then rank by text relevance:
# Find revenue info, but only from Acme-related documents
memvid find memory.mv2 --query "revenue" --graph "?:works_at:Acme Corp"
# Find meeting notes involving John
memvid find memory.mv2 --query "meeting notes" --graph "John Smith:?:?"
Hybrid Graph + Semantic Search
Combine graph traversal with vector similarity:
# Semantic search within a relationship context
memvid find memory.mv2 --query "Q4 results" --hybrid --graph "?:works_at:Acme"
# Find similar documents to what relates to a topic
memvid find memory.mv2 --query "machine learning" --hybrid --graph "?:expertise:ML"
Common Relationship Types
Logic Mesh automatically detects common relationships:
Professional
| Relationship | Example |
|---|
works_at | John works_at Acme |
reports_to | John reports_to Jane |
manages | Jane manages Engineering |
founded | Elon founded SpaceX |
CEO | Tim CEO Apple |
Organizational
| Relationship | Example |
|---|
acquired | Acme acquired StartupXYZ |
partnered_with | Acme partnered_with TechCo |
subsidiary_of | StartupXYZ subsidiary_of Acme |
headquartered_in | Acme headquartered_in SF |
Technical
| Relationship | Example |
|---|
uses | Project uses React |
depends_on | Service depends_on Database |
integrates_with | Platform integrates_with Stripe |
expertise | John expertise Rust |
Temporal
| Relationship | Example |
|---|
started | Project started 2024-01 |
completed | Phase completed 2024-06 |
scheduled | Meeting scheduled 2024-12-15 |
SDK Usage
Python
from memvid import use
mem = use('basic', 'memory.mv2')
# Enable logic mesh during put
mem.put(
text="John Smith works at Acme Corp as a Senior Engineer.",
logic_mesh=True
)
# List entities
entities = mem.get_entities()
for entity in entities:
print(f"{entity.name} ({entity.kind}): {entity.relationship_count} relationships")
# Traverse from an entity
graph = mem.traverse(
start="John Smith",
link="works_at",
hops=2,
direction="outgoing"
)
for node in graph.nodes:
print(f"{node.name}: {node.relationships}")
# Graph-filtered search
results = mem.find(
"quarterly report",
graph_pattern="?:works_at:Acme Corp"
)
# Hybrid search
results = mem.find(
"machine learning",
hybrid=True,
graph_pattern="?:expertise:ML"
)
Node.js
import { use } from '@anthropics/memvid'
const mem = await use('basic', 'memory.mv2')
// Enable logic mesh during put
await mem.put({
content: "John Smith works at Acme Corp as a Senior Engineer.",
logicMesh: true
})
// List entities
const entities = await mem.getEntities()
for (const entity of entities) {
console.log(`${entity.name} (${entity.kind}): ${entity.relationshipCount} relationships`)
}
// Traverse from an entity
const graph = await mem.traverse({
start: "John Smith",
link: "works_at",
hops: 2,
direction: "outgoing"
})
// Graph-filtered search
const results = await mem.find("quarterly report", {
graphPattern: "?:works_at:Acme Corp"
})
Advanced Patterns
Multi-Hop Queries
Find entities connected through intermediate nodes:
# Who do people at Acme report to? (2 hops)
memvid follow traverse memory.mv2 --start "Acme Corp" --link "works_at,reports_to" --hops 2
# Find the CEO through org chart
memvid follow traverse memory.mv2 --start "John Smith" --link "reports_to" --hops 5
Compound Patterns
Combine multiple patterns:
# Find people who work at Acme AND have ML expertise
memvid find memory.mv2 --graph "?:works_at:Acme Corp" --graph "?:expertise:ML"
Negation (Exclusion)
Find entities NOT matching a pattern:
# Find all employees except those reporting to Jane
memvid follow entities memory.mv2 --kind person --exclude-pattern "?:reports_to:Jane"
Export Graph Data
N-Triples (RDF)
memvid export memory.mv2 --format ntriples --out graph.nt
<John_Smith> <works_at> <Acme_Corp> .
<John_Smith> <reports_to> <Jane_Doe> .
<John_Smith> <expertise> "Rust" .
<Acme_Corp> <acquired> <StartupXYZ> .
JSON Graph
memvid export memory.mv2 --format json --out graph.json
{
"nodes": [
{"id": "John_Smith", "kind": "person", "properties": {...}},
{"id": "Acme_Corp", "kind": "company", "properties": {...}}
],
"edges": [
{"source": "John_Smith", "target": "Acme_Corp", "relation": "works_at"},
{"source": "John_Smith", "target": "Jane_Doe", "relation": "reports_to"}
]
}
CSV
memvid export memory.mv2 --format csv --out graph.csv
subject,predicate,object,confidence,source_frame
John_Smith,works_at,Acme_Corp,0.94,frame_001
John_Smith,reports_to,Jane_Doe,0.91,frame_001
Acme_Corp,acquired,StartupXYZ,0.88,frame_045
Use Cases
Organizational Knowledge
Map your company structure:
# Ingest org documents
memvid put org.mv2 --input hr_docs/ --logic-mesh
# Find everyone's reporting structure
memvid follow traverse org.mv2 --start "CEO" --link "manages" --hops 5 --direction outgoing
# Who reports to a specific manager?
memvid find org.mv2 --graph "?:reports_to:Sarah Chen"
Research Papers
Build citation and concept graphs:
# Ingest papers
memvid put research.mv2 --input papers/ --logic-mesh
# Find papers citing a specific work
memvid find research.mv2 --graph "?:cites:Attention Is All You Need"
# Find concepts related to transformers
memvid follow traverse research.mv2 --start "Transformers" --hops 2
Customer Data
Track customer relationships:
# Find all contacts at a company
memvid find customers.mv2 --graph "?:works_at:BigCorp Inc"
# Find decision makers
memvid find customers.mv2 --graph "?:role:VP" --graph "?:works_at:BigCorp Inc"
Code Documentation
Map code dependencies:
# Find what depends on a module
memvid find codebase.mv2 --graph "?:imports:auth_module"
# Find all API endpoints
memvid follow entities codebase.mv2 --kind endpoint
Index Recommendations
For large graphs (1000+ entities):
# Build graph index for faster traversals
memvid doctor memory.mv2 --rebuild-logic-mesh
Limit Traversal Depth
Deep traversals are expensive:
# Default (recommended)
--hops 2
# Use sparingly
--hops 3 or higher
Filter Early
Apply graph filters before text search:
# Good: Graph filter narrows results first
memvid find memory.mv2 --graph "?:works_at:Acme" --query "report"
# Less efficient: Broad text search then filter
memvid find memory.mv2 --query "report" | grep Acme
Troubleshooting
”No entities found”
-
Ensure Logic Mesh is enabled:
memvid put memory.mv2 --input docs/ --logic-mesh
-
Run enrichment:
memvid enrich memory.mv2 --engine groq
-
Check stats:
memvid follow stats memory.mv2
“Relationship not detected”
- Content may be too ambiguous
- Try a better enrichment engine:
memvid enrich memory.mv2 --engine claude --force
“Traversal too slow”
- Reduce hop depth
- Rebuild logic mesh index:
memvid doctor memory.mv2 --rebuild-logic-mesh
Next Steps