set client_min_messages = warning; drop extension if exists pg_liquid cascade; create extension pg_liquid; select count(*) as seeded_conversation_memory_count from liquid.query($$ DefPred("owner", "1", "liquid/node", "0", "liquid/string"). DefPred("conversation_note", "1", "liquid/node", "0", "liquid/string"). DefCompound("UserProfile", "user", "0", "liquid/string"). DefCompound("UserProfile", "display_name", "0", "liquid/string"). DefCompound("UserProfile", "timezone", "0", "liquid/string"). Edge("UserProfile", "liquid/mutable", "false"). DefCompound("ConversationMemory", "user", "0", "liquid/string"). DefCompound("ConversationMemory", "conversation_id", "0", "liquid/string"). DefCompound("ConversationMemory", "fact_key", "0", "liquid/string"). DefCompound("ConversationMemory", "fact_value", "0", "liquid/string"). Edge("ConversationMemory", "liquid/mutable", "false"). Edge("session:alice-mobile", "liquid/acts_for", "user:alice"). Edge("session:bob-mobile", "liquid/acts_for", "user:bob"). UserProfile@(user="user:alice", display_name="Alice Example", timezone="America/Toronto"). UserProfile@(user="user:bob", display_name="Bob Example", timezone="America/Chicago"). ConversationMemory@(user="user:alice", conversation_id="conv:alice:1", fact_key="diet", fact_value="vegetarian"). ConversationMemory@(user="user:alice", conversation_id="conv:alice:1", fact_key="allergy", fact_value="peanuts"). ConversationMemory@(user="user:bob", conversation_id="conv:bob:1", fact_key="goal", fact_value="build endurance"). Edge("thread:alice:1", "owner", "user:alice"). Edge("thread:bob:1", "owner", "user:bob"). Edge("thread:alice:1", "conversation_note", "Alice likes concise recipes"). Edge("thread:bob:1", "conversation_note", "Bob prefers endurance plans"). ConversationMemory@(cid=cid, user=user_id, conversation_id=conversation_id, fact_key=fact_key, fact_value=fact_value)? $$) as t(cid text, user_id text, conversation_id text, fact_key text, fact_value text); seeded_conversation_memory_count ---------------------------------- 3 (1 row) select count(*) as alice_visible_profiles_without_compound_policy from liquid.read_as('session:alice-mobile', $$ UserProfile@(cid=cid, user=user_id, display_name=display_name, timezone=timezone)? $$) as t(cid text, user_id text, display_name text, timezone text); alice_visible_profiles_without_compound_policy ------------------------------------------------ 0 (1 row) select count(*) as alice_visible_memories_without_compound_policy from liquid.read_as('session:alice-mobile', $$ ConversationMemory@(cid=cid, user=user_id, conversation_id=conversation_id, fact_key=fact_key, fact_value=fact_value)? $$) as t(cid text, user_id text, conversation_id text, fact_key text, fact_value text); alice_visible_memories_without_compound_policy ------------------------------------------------ 0 (1 row) select count(*) as alice_visible_notes_without_predicate_policy from liquid.read_as('session:alice-mobile', $$ Edge(subject_literal, "conversation_note", note_text)? $$) as t(subject_literal text, note_text text); alice_visible_notes_without_predicate_policy ---------------------------------------------- 0 (1 row) select count(*) as enabled_compound_policy_count from liquid.query($$ CompoundReadByRole@(compound_type="UserProfile", role="user"). CompoundReadByRole@(compound_type="ConversationMemory", role="user"). CompoundReadByRole@(cid=cid, compound_type=compound_type, role=role)? $$) as t(cid text, compound_type text, role text) where compound_type in ('UserProfile', 'ConversationMemory'); enabled_compound_policy_count ------------------------------- 2 (1 row) select user_id, display_name, timezone from liquid.read_as('session:alice-mobile', $$ UserProfile@(cid=cid, user=user_id, display_name=display_name, timezone=timezone)? $$) as t(cid text, user_id text, display_name text, timezone text) order by 1, 2, 3; user_id | display_name | timezone ------------+---------------+----------------- user:alice | Alice Example | America/Toronto (1 row) select conversation_id, fact_key, fact_value from liquid.read_as('session:alice-mobile', $$ ConversationMemory@(cid=cid, user="user:alice", conversation_id=conversation_id, fact_key=fact_key, fact_value=fact_value)? $$) as t(cid text, conversation_id text, fact_key text, fact_value text) order by 1, 2, 3; conversation_id | fact_key | fact_value -----------------+----------+------------ conv:alice:1 | allergy | peanuts conv:alice:1 | diet | vegetarian (2 rows) select count(*) as bob_visible_alice_profile_count from liquid.read_as('session:bob-mobile', $$ UserProfile@(cid=cid, user="user:alice", display_name=display_name, timezone=timezone)? $$) as t(cid text, display_name text, timezone text); bob_visible_alice_profile_count --------------------------------- 0 (1 row) select count(*) as bob_visible_alice_memory_count from liquid.read_as('session:bob-mobile', $$ ConversationMemory@(cid=cid, user="user:alice", conversation_id=conversation_id, fact_key=fact_key, fact_value=fact_value)? $$) as t(cid text, conversation_id text, fact_key text, fact_value text); bob_visible_alice_memory_count -------------------------------- 0 (1 row) select conversation_id, fact_key, fact_value from liquid.read_as('session:bob-mobile', $$ ConversationMemory@(cid=cid, user="user:bob", conversation_id=conversation_id, fact_key=fact_key, fact_value=fact_value)? $$) as t(cid text, conversation_id text, fact_key text, fact_value text) order by 1, 2, 3; conversation_id | fact_key | fact_value -----------------+----------+----------------- conv:bob:1 | goal | build endurance (1 row) select count(*) as untrusted_memory_count from liquid.read_as('session:untrusted', $$ ConversationMemory@(cid=cid, user=user_id, conversation_id=conversation_id, fact_key=fact_key, fact_value=fact_value)? $$) as t(cid text, user_id text, conversation_id text, fact_key text, fact_value text); untrusted_memory_count ------------------------ 0 (1 row) select count(*) as enabled_predicate_policy_count from liquid.query($$ PredicateReadBySubject@(predicate="conversation_note", relation="owner"). PredicateReadBySubject@(cid=cid, predicate=predicate, relation=relation)? $$) as t(cid text, predicate text, relation text) where predicate = 'conversation_note' and relation = 'owner'; enabled_predicate_policy_count -------------------------------- 1 (1 row) select subject_literal, note_text from liquid.read_as('session:alice-mobile', $$ Edge(subject_literal, "conversation_note", note_text)? $$) as t(subject_literal text, note_text text) order by 1, 2; subject_literal | note_text -----------------+----------------------------- thread:alice:1 | Alice likes concise recipes (1 row) select subject_literal, note_text from liquid.read_as('session:bob-mobile', $$ Edge(subject_literal, "conversation_note", note_text)? $$) as t(subject_literal text, note_text text) order by 1, 2; subject_literal | note_text -----------------+----------------------------- thread:bob:1 | Bob prefers endurance plans (1 row) select count(*) as untrusted_note_count from liquid.read_as('session:untrusted', $$ Edge(subject_literal, "conversation_note", note_text)? $$) as t(subject_literal text, note_text text); untrusted_note_count ---------------------- 0 (1 row) select count(*) as hidden_memory_value_edges from liquid.read_as('session:alice-mobile', $$ Edge(subject_literal, "fact_value", object_literal)? $$) as t(subject_literal text, object_literal text); hidden_memory_value_edges --------------------------- 0 (1 row) select count(*) as unscoped_memory_count from liquid.query($$ ConversationMemory@(cid=cid, user=user_id, conversation_id=conversation_id, fact_key=fact_key, fact_value=fact_value)? $$) as t(cid text, user_id text, conversation_id text, fact_key text, fact_value text); unscoped_memory_count ----------------------- 3 (1 row)