Urgent.News

What's breaking now, across thousands of outlets.

Tech

Build Multi-Tenant RAG in Next.js Without Leaking Customer Data

A practical pattern for tenant-scoped retrieval with PostgreSQL, pgvector, row-level security, and integration tests. I've spent about twenty years building software. A pattern worth watching for is a security check that exists in the first request path but gets missed when someone adds a second one. RAG makes that mistake particularly easy: vector search can return a highly relevant passage that…

A key pattern for multi-tenant RAG (retrieval augmented generation) systems is ensuring tenant-level isolation when retrieving relevant document chunks for a user. This prevents potential data leakage where a user might see chunks from other organizations. The critical steps are:

1. Obtain tenant identity from trusted authentication server, not from browser-provided data. The tenant ID should come from a secure server-side check.

2. Store ownership data with each document chunk and maintain a foreign key constraint linking chunks to documents and tenants. This prevents chunks from being assigned to the wrong tenant.

3. Perform tenant filtering in the database query itself, before the retrieved chunks are sent to the LLM model. This enforcement point is critical - it must happen before the model receives any text, otherwise authorization is ineffective.

The article provides example SQL schema and code snippets in Next.js to implement these tenant isolation checks during document indexing and retrieval. The key takeaway is that proper tenant context must be established in the initial request, and enforced before any data is used in LLM prompts to avoid accidental data disclosure.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

Halving the KV Cache Doubles Capacity and Buys 1% of Speed

A reader ran the script from my last piece against the table, found a bug in my code, and asked a better question than the one I answered. The bug first.

  • Halving KV cache doubles capacity
  • Speed does not double at any length
  • Speed gain up to 21% for Qwen3-32B

JavaScript (ES6+) for React Developers: The Definitive Guide

React is fundamentally plain JavaScript. If you ever struggle with state updates, unintended re-renders, or props drilling, the issue is rarely React itself—it is usually a missing piece of modern…

  • ES6 (ES2015) crucial for React developers
  • Block scoping with let, const improves code safety
  • Arrow functions simplify React event handling

I made my coding agent explain its own pull requests

The problem: the agent knows why, the reviewer doesn't More and more of the pull requests I review were written by a coding agent. The code is usually fine.

  • DiffNotes tool explains coding agent's pull requests
  • Concise notes attached to changed code blocks
  • Setup involves server, agent skill, and Chrome extension

More from Sunday 1 November →