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 ch
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
- Trigger on a new or updated file in a shared folder (Google Drive, or an upload form).
- Extract the text. PDFs and docs need different handling, so do that first.
- Split it into chunks of a few paragraphs, with a little overlap between them.
- Embed each chunk and upsert it with its source file name, page and updated date.
- 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
- A question comes in (internal chat, WhatsApp, or a small web page).
- Embed the question and pull the closest chunks.
- 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.
- 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.
Originally published by Dev.to AI. Aggregated on AIWithGhost for educational purposes โ full credit and traffic to the original publisher.