DEV Community

Shoeb Reza | Arwahyn AI
Shoeb Reza | Arwahyn AI

Posted on AI-assisted

A "company brain" over your own documents (RAG in n8n) that keeps the data in your own database

A common request from clients: "our staff keep asking the same questions about policies, products and old decisions, can AI answer from our own documents?" Yes, and you don't need to upload everything to a third-party chatbot builder to do it. Here's the setup we use, with the documents and the search index in the client's own Postgres.

Think of it as a new employee who has read every file in the cabinet, and who always points to the page they got the answer from.

The pieces

  • Postgres with pgvector (we use Supabase) to store document chunks and their embeddings
  • n8n for the two workflows below
  • An embeddings model and a chat model from whichever AI provider the client already trusts

Workflow 1: ingest

  1. Trigger on a new or updated file in a shared folder (Google Drive, or an upload form).
  2. Extract the text. PDFs and docs need different handling, so do that first.
  3. Split it into chunks of a few paragraphs, with a little overlap between them.
  4. Embed each chunk and upsert it with its source file name, page and updated date.
  5. When a file is deleted, delete its chunks. People forget this step, and the bot keeps quoting a policy that no longer exists.

Workflow 2: answer

  1. A question comes in (internal chat, WhatsApp, or a small web page).
  2. Embed the question and pull the closest chunks.
  3. Ask the model to answer only from those chunks, quote the source file, and say "I don't know" when the chunks don't cover it.
  4. Log every question and answer, so you can see what the documents are missing.

Rules that made it trustworthy

  • No source, no answer.
  • Restrict what each person can search. HR documents shouldn't answer questions for everyone.
  • Read the "I don't know" log every week. It's the best list of documents your company still needs to write.

I run Arwahyn AI, an AI automation agency in Dhaka.

Top comments (0)