AI Memory & Storage
Relevant source files
The following files were used as context for generating this wiki page:
- packages/@n8n/workflow-sdk/src/prompts/best-practices/guides/knowledge-base.ts
- packages/@n8n/workflow-sdk/src/prompts/best-practices/guides/document-processing.ts
- packages/@n8n/ai-workflow-builder.ee/src/prompts/agents/discovery.prompt.ts
- packages/@n8n/ai-workflow-builder.ee/src/code-builder/prompts/index.ts
- packages/frontend/editor-ui/src/app/constants/workflowSuggestions.ts
- packages/frontend/editor-ui/src/experiments/readyToRunWorkflowsV2/workflows/ai-workflow-v6.ts
AI Memory and Storage in n8n encompasses the systems used to maintain conversation context, store document embeddings, and manage persistent data for AI agents. This module enables agents to "remember" previous interactions within a session and retrieve relevant factual information from external or internal data sources using semantic search.
The system distinguishes between short-term conversation memory, which persists for a defined number of message turns, and long-term knowledge storage, which utilizes vector databases to index and retrieve document chunks.
Sources: packages/@n8n/workflow-sdk/src/prompts/best-practices/guides/knowledge-base.ts, packages/@n8n/ai-workflow-builder.ee/src/prompts/agents/discovery.prompt.ts
Conversation Memory
Conversation memory allows AI Agents to maintain context across multiple user messages. Without memory, each request to an LLM is stateless. n8n provides specific sub-nodes that connect to the AI Agent node to handle this state.
Window Buffer Memory
The Window Buffer Memory node (@n8n/n8n-nodes-langchain.memoryBufferWindow) is the primary component for conversational context. It stores a rolling window of the last N messages.
- Capacity: Typically configured for 3-5 message turns to balance context preservation with token limits.
- Connection: Connects to the
ai_memoryinput of an AI Agent.
Sources: packages/@n8n/workflow-sdk/src/prompts/best-practices/guides/knowledge-base.ts:114-117, packages/frontend/editor-ui/src/experiments/readyToRunWorkflowsV2/workflows/ai-workflow-v6.ts:46-53
Memory Data Flow
The following diagram illustrates how memory integrates into a chatbot execution flow:
The AI Agent retrieves history from the memory node before processing and updates it after generating a response.
Sources: packages/@n8n/ai-workflow-builder.ee/src/prompts/agents/discovery.prompt.ts, packages/frontend/editor-ui/src/experiments/readyToRunWorkflowsV2/workflows/ai-workflow-v6.ts
Vector Storage and Knowledge Bases
Vector storage enables Retrieval-Augmented Generation (RAG). It allows workflows to index documents as high-dimensional vectors (embeddings) and retrieve them based on semantic similarity rather than keyword matching.
Architecture Patterns
n8n recommends a modular design for knowledge bases, separating the ingestion of data from the querying of data.
- Ingestion Workflow: Fetches documents, splits them into chunks (500-1000 characters), generates embeddings, and "upserts" them into a vector store with unique IDs.
- Query Workflow: Triggered by user queries, it searches the vector store for the top 3-5 relevant chunks to provide context to the LLM.
Sources: packages/@n8n/workflow-sdk/src/prompts/best-practices/guides/knowledge-base.ts:10-18
Vector Store Implementations
| Node Name | Purpose | Best Practices |
|---|---|---|
| In Memory | Testing/Development | Data is lost on restart; not for production. |
| Pinecone | Scalable Production | Use namespaces for organization. |
| Qdrant | High-performance/Self-hosted | Configure collections and use metadata filters. |
| Supabase | Integrated PGVector | Ensure pgvector extension is enabled. |
Sources: packages/@n8n/workflow-sdk/src/prompts/best-practices/guides/knowledge-base.ts:87-107
Retrieval Logic
When using a Vector Store as a tool for an AI Agent, the following configurations are critical:
- Top-K Limit: 3-5 results are typically optimal to avoid overwhelming the LLM.
- Similarity Threshold: Filters out matches that do not meet a minimum relevance score.
- Embedding Consistency: The same embedding model (e.g.,
text-embedding-ada-002) MUST be used for both indexing and querying.
Sources: packages/@n8n/workflow-sdk/src/prompts/best-practices/guides/knowledge-base.ts:32-35, 126-130
Data Tables and Persistent Storage
For structured data that does not require semantic search, n8n provides persistent storage options to track AI interactions or store extracted information.
n8n Data Tables
n8n Data Tables are the recommended default for internal storage as they require no external credentials or accounts. They are used to:
- Log chat interactions (query, matched files, timestamps).
- Store structured results from document extraction (e.g., invoice data).
- Maintain state for lead qualification or appointment booking.
Sources: packages/@n8n/ai-workflow-builder.ee/src/prompts/agents/discovery.prompt.ts:65-68, packages/frontend/editor-ui/src/app/constants/workflowSuggestions.ts:46-60
External Databases
Workflows often sync AI-processed data to external systems:
- Google Sheets / Airtable: Used for collaborative review and manual validation.
- Postgres / MySQL: Used for production-grade persistence of extraction results.
Sources: packages/@n8n/workflow-sdk/src/prompts/best-practices/guides/document-processing.ts:182-198
Document Processing Pipeline
AI Storage is often the final destination in document processing pipelines. Binary data must be converted into text and then into vectors or structured records.
The pipeline converts raw binary files into embeddings for retrieval and structured logs for auditing.
Sources: packages/@n8n/workflow-sdk/src/prompts/best-practices/guides/knowledge-base.ts, packages/@n8n/workflow-sdk/src/prompts/best-practices/guides/document-processing.ts
Binary Data Preservation
Nodes that process text (like AI Agents) often drop binary data from the output. To preserve the original file for storage (e.g., in a database or S3):
- Use parallel branches to process text on one side and keep binary on the other.
- Use the Merge node in "Pass Through" mode or a Set node with "Include Other Input Fields" enabled to rejoin the binary data with the AI's structured output.
Sources: packages/@n8n/workflow-sdk/src/prompts/best-practices/guides/document-processing.ts:46-55
Summary of Best Practices
- Chunking: Maintain chunk sizes between 500-1000 characters with 10-15% overlap to preserve context.
- Unique Identifiers: Use
Document ID + Chunk Numberas a unique ID in vector stores to enable targeted updates and prevent duplicates. - Temperature: Use a low temperature (0-0.3) for RAG tasks to ensure factual accuracy and reduce hallucinations.
- Metadata: Always include source, title, and page numbers in vector store metadata to help the LLM cite its sources.