fix(memory): harden PostgreSQL knowledge graph queries (#10055)