Last month I wrote about keeping AI agents' shared memory apart with PostgreSQL row-level security, and released adk-memshield, an open-source memory service that does it. The pitch was simple: if the app forgets its WHERE clause, the database still refuses to hand you someone else's rows.
Then a reader, Sunnatulla, tested that pattern the way production runs it, and found a failure I hadn't tested for.
What the reader found
Their setup: PostgreSQL 17 with pgvector, 100,000 memories across three tenants, an HNSW vector index, and a light user who could see only 30 of the 33,000 rows in their tenant. A plain query was exact and fast. Then they ran the same search through prepared statements, which your driver turns on for you: psycopg 3 prepares a statement after five executions, and asyncpg prepares everything from the start.
After a few executions, Postgres can switch a prepared statement to a cached generic plan. For a nearest-neighbour ORDER BY embedding <=> ... LIMIT ...…