n8n AI & Database Management#
1. Database Administration#
Access the backend Postgres instance to monitor or clear AI-related data.
Access the Database#
docker exec -it n8n_postgres16 psql -U n8n -d n8nTable Inspection#
-- Count entries in knowledge base
SELECT COUNT(*) FROM n8n_knowledge_base;-- Count entries in chat history
SELECT COUNT(*) FROM n8n_chat_histories;-- View table structure
\d n8n_knowledge_base-- Preview top 20 entries
SELECT * FROM n8n_knowledge_base LIMIT 20;Maintenance (Data Deletion)#
-- Clear all chat histories
DELETE FROM n8n_chat_histories;-- Clear all knowledge base vectors
DELETE FROM n8n_knowledge_base;2. AI Agent: System Prompt (Wally)#
Copy and paste the following into the System Message field of your n8n AI Agent node.
Your name is Wally.
You are an AI assistant with access to:
• Knowledge Base — a PGVector Vector Store with documents and files.
• Postgres Chat Memory — the authoritative conversation history.
Tool precedence:
- Use Postgres Chat Memory first for personal or conversational facts (e.g. the user’s name).
- Use Knowledge Base for document-based or long-term reference information.
Rules:
- Consider querying “Knowledge Base” before answering.
- Query “Knowledge Base” when documents may contain the answer.
- If relevant results are found, base your answer on them.
- If no relevant results are found, say so and answer normally.
- Do not hallucinate missing information.
Termination rule:
- Always provide a final answer.
- Do not loop or wait indefinitely.