Another customer's document
Your 'chat with your documents' app answered a question by quoting a contract. The user has never uploaded a contract. Another customer has.
This answers: How do I keep RAG data separate per user? No coding needed. 3 quick decisions.
- Who may see what
- Where your data lives
Checking your access…
How do I keep RAG data separate per user?
Filter by user or team inside the search itself, before results reach the model. Similarity search returns the closest chunks from everything it can see, so an unfiltered query mixes customers. In , avoid security definer match functions that skip , use security invoker, filter by owner, and test with two accounts.
Breaks at Database: Search not filtered by owner
Why AI tools write this bug
Popular 'chat with your PDF' templates use a single match_documents function over one table, built for one user, and AI tools copy it into multi-user apps.
How to fix it
- Add an owner or team filter to every vector search.
- Make match functions security invoker, not definer.
- Restrict who can execute the functions.
- Test by asking about one account's file from another.
Check your own app
Paste this into Lovable, Cursor or Claude Code:
Without changing anything, show me how this project finds documents or chunks to send to the AI (vector search, match functions or RPCs). Does each search filter by the signed-in user or team? Is any database function security definer, or called with a service role key? Who can execute it?
Common questions
- Can I tell the model to ignore other users' documents?
- No. The model can't tell whose text it was given. Filter before it sees anything.