Lilith now relies on Sophia's knowledge graph as the canonical graph database
for relationships between spiritual traditions, philosophical concepts,
historical figures, practices, texts, and places. It enables intelligent
navigation, recommendation, and exploration of contemplative wisdom across
traditions.
// Unique ID constraints
CREATE CONSTRAINT tradition_id IF NOT EXISTS
FOR (t:TRADITION) REQUIRE t.id IS UNIQUE;
CREATE CONSTRAINT concept_id IF NOT EXISTS
FOR (c:CONCEPT) REQUIRE c.id IS UNIQUE;
CREATE CONSTRAINT practice_id IF NOT EXISTS
FOR (p:PRACTICE) REQUIRE p.id IS UNIQUE;
CREATE CONSTRAINT figure_id IF NOT EXISTS
FOR (f:FIGURE) REQUIRE f.id IS UNIQUE;
CREATE CONSTRAINT text_id IF NOT EXISTS
FOR (t:TEXT) REQUIRE t.id IS UNIQUE;
CREATE CONSTRAINT place_id IF NOT EXISTS
FOR (p:PLACE) REQUIRE p.id IS UNIQUE;
// Full-text indexes for search
CREATE FULLTEXT INDEX tradition_search IF NOT EXISTS
FOR (t:TRADITION) ON EACH [t.name, t.description];
CREATE FULLTEXT INDEX concept_search IF NOT EXISTS
FOR (c:CONCEPT) ON EACH [c.name, c.definition];
CREATE FULLTEXT INDEX figure_search IF NOT EXISTS
FOR (f:FIGURE) ON EACH [f.name, f.biography];
CREATE FULLTEXT INDEX text_search IF NOT EXISTS
FOR (t:TEXT) ON EACH [t.title, t.author];
// Property indexes for filtering
CREATE INDEX tradition_name IF NOT EXISTS FOR (t:TRADITION) ON (t.name);
CREATE INDEX figure_tradition IF NOT EXISTS FOR (f:FIGURE) ON (f.tradition);
CREATE INDEX practice_difficulty IF NOT EXISTS FOR (p:PRACTICE) ON (p.difficulty);
// Find concepts that align with a given concept
MATCH (c:CONCEPT {name: "mindfulness"})-[:ALIGNS_WITH]-(related:CONCEPT)
RETURN related.name, related.tradition
// Get all practices in a tradition
MATCH (t:TRADITION {name: "Zen Buddhism"})<-[:BELONGS_TO]-(p:PRACTICE)
RETURN p.name, p.type, p.difficulty
ORDER BY p.difficulty
// Find concepts that appear in multiple traditions
MATCH (c:CONCEPT)-[:BELONGS_TO]->(t:TRADITION)
WITH c, count(DISTINCT t) AS traditionCount
WHERE traditionCount > 1
RETURN c.name, traditionCount
ORDER BY traditionCount DESC
// Find prerequisite path for a practice
MATCH path = (p:PRACTICE {name: "Shikantaza"})<-[:REQUIRES*]-(prereq:PRACTICE)
RETURN [n IN nodes(path) | n.name] AS prerequisitePath
// Find figures connected to a text
MATCH (t:TEXT {title: "Yoga Sutras"})
OPTIONAL MATCH (author:FIGURE)-[:WROTE]->(t)
OPTIONAL MATCH (commentator:FIGURE)-[:COMMENTED_ON]->(t)
RETURN t.title, author.name AS author,
collect(DISTINCT commentator.name) AS commentators
// Find orphan nodes (no relationships)
MATCH (n)
WHERE NOT (n)--()
RETURN labels(n), n.name
// Find traditions without practices
MATCH (t:TRADITION)
WHERE NOT (t)<-[:BELONGS_TO]-(:PRACTICE)
RETURN t.name
// Find concepts without tradition
MATCH (c:CONCEPT)
WHERE NOT (c)-[:BELONGS_TO]->(:TRADITION)
RETURN c.name
async function recommendPractices(userId: string, currentPractice: string) {
// Find related practices based on graph relationships
return graphStore.query(
`
MATCH (p:PRACTICE {name: $practice})
MATCH (p)-[:EXEMPLIFIES]->(:CONCEPT)<-[:EXEMPLIFIES]-(related:PRACTICE)
WHERE related.name <> p.name
WITH related, count(*) as sharedConcepts
ORDER BY sharedConcepts DESC
RETURN related.name, related.tradition, related.difficulty
LIMIT 5
`,
{ practice: currentPractice }
);
}