Daleel: RAG document assistant
An AI assistant that answers questions from your own documents and names the file behind every answer, built on two n8n workflows, Supabase pgvector, and OpenAI embeddings.
Answers you can trace back to a file.
Daleel (دليل, "guide") is a retrieval-augmented generation (RAG) assistant for your own documents. You upload PDF, text, or Markdown files, ask questions in plain language, and every answer comes with the file it was taken from, so it can be checked rather than trusted blindly.
It runs on two n8n workflows: one validates, hashes, chunks, and embeds documents into Supabase pgvector; the other is a chat agent that searches them, keeps conversation memory in Postgres, and reaches for web search or a calculator when the documents can't answer.
A confident wrong answer is worse than none.
A general-purpose chatbot knows nothing about a team's own policies, projects, or vendor notes, yet it will still answer questions about them, and sound sure while doing it. RAG fixes that by grounding answers in the documents themselves, but a naive pipeline brings its own failure modes.
When a document is updated, old and new chunks can both stay searchable, so answers mix outdated and current facts. Re-uploading the same file bloats the index with duplicates. And a document can carry hidden instructions aimed at the model. The goal was an assistant that only answers from the current version of each file, says where every answer came from, and treats document text as data.
Designed and built it end to end.
This was an individual project, so I owned every layer:
Ingestion workflow
Built the n8n flow that validates uploads, extracts text, hashes files, chunks, and embeds them.
Database
Designed the Supabase schema: the documents table, a version registry, grants, RLS, and the activation function.
Chat agent
Built the agent workflow with session validation, Postgres chat memory, vector search, and web and calculator tools.
Testing & evaluation
Wrote 16 offline checks, a retrieval-scoring script, and a scripted end-to-end demo run.
What it's built with.
Orchestration
Retrieval & storage
Models & tools
Testing
Two workflows, one source of truth.
The ingestion workflow writes new document versions into pgvector and only then marks them active. The chat workflow searches that same store, reading active versions only, and builds an answer that names its sources.
What it does.
- Cited answers: every response names the documents it was drawn from, even when it combines several.
- Safe document updates: a changed file replaces the old version only after its new chunks are indexed and counted, in a single transaction.
- Duplicate detection: unchanged re-uploads are recognised by SHA-256 hash and skipped.
- Conversation memory: follow-up questions use chat history stored in Postgres.
- Fallback tools: web search and a calculator for questions the documents can't answer.
- Injection-resistant: text inside documents is treated as data, so hidden instructions are ignored.
The hard parts, and how I solved them.
Old and new facts in the same answer
If an updated file is indexed while the old one is still searchable, answers blend both. I added a document registry and an activation step that counts the new chunks and switches the active version in one transaction; search filters to active versions only. In the demo, questions asked after the update returned the new project manager and remaining budget.
The same file, uploaded again
Re-uploading an unchanged document would re-embed it and fill the index with duplicate chunks. Each file is hashed with SHA-256 on arrival; a known hash stops before any embedding call and is reported as a duplicate.
Documents that try to give orders
Retrieved text lands in the model's context, so a file can smuggle in instructions. The agent is set up to treat document content strictly as data. Tested with a vendor file containing a hidden instruction, Daleel reported only the real points and ignored the instruction.
Grounded, current, and checkable.
Daleel answered single- and multi-document questions with the right sources, replaced an updated file, skipped a duplicate, and ignored a hidden instruction. The 16 offline checks cover workflow wiring, upload validation, the SQL schema, and that no credentials are committed.
The demo is a single run, not an accuracy benchmark; the repository includes a script that scores labelled questions for Hit@5 and MRR. Scanned-image PDFs aren't supported yet, only PDFs with selectable text.