Back to Nodes

SQLite Memory

Last updated Aug 6, 2025

N8N node for AI Chat Memory with SQLite3 backend

2 Weekly Downloads
12 Monthly Downloads

Included Nodes

SQLite Memory

Description

n8n-nodes-sqlite-memory

npm version
License: MIT

A powerful N8N community node for AI Chat Memory with SQLite3 backend. Provides persistent local storage for chat conversations without external dependencies.

๐Ÿš€ Features

  • ๐Ÿ—„๏ธ Local SQLite Storage: No external database required – works out of the box
  • ๐Ÿ”‘ Session Management: Organize conversations by unique session keys
  • ๐Ÿ“Š Smart Context Window: Token-aware message retrieval with configurable limits
  • ๐Ÿค– AI Integration: Auto-detect and store user inputs and AI responses
  • ๐Ÿงน Auto-cleanup: Automatically maintains last 50 messages per session
  • โšก Zero Configuration: Works immediately after installation
  • ๐Ÿ”„ Legacy Support: Backward compatible with existing message formats

๐Ÿ“ฆ Installation

Option 1: Install via npm (Recommended)

npm install n8n-nodes-sqlite-memory

Option 2: Manual Installation

  1. Download the latest release
  2. Place in your N8N custom nodes directory
  3. Restart N8N

๐Ÿ› ๏ธ Operations

๐Ÿ“ฅ Get Messages

Retrieves recent messages from a chat session.

Parameters:

  • Session Key: Unique identifier for the chat session
  • Window Size: Number of recent messages to retrieve (default: 10)

Output:

{
  "messages": [
    { "id": "uuid", "role": "user", "content": "Hello", "timestamp": 1703123456789 },
    { "id": "uuid", "role": "assistant", "content": "Hi there!", "timestamp": 1703123456790 }
  ],
  "sessionKey": "chat-123",
  "count": 2
}

โž• Add Message

Manually stores a message in the chat session.

Parameters:

  • Session Key: Unique identifier for the chat session
  • Role: Message sender role (user/assistant/system)
  • Message Content: The message text to store

Output:

{
  "success": true,
  "sessionKey": "chat-123",
  "message": {
    "role": "user",
    "content": "Hello"
  }
}

๐Ÿ”„ Auto-Store User Input

Automatically detects and stores user input from the previous node.

Detects input from:

  • chatInput
  • message
  • content
  • text
  • query

Output:

{
  "success": true,
  "sessionKey": "chat-123",
  "message": { "role": "user", "content": "Hello" },
  "chatInput": "Hello"
}

๐Ÿค– Auto-Store AI Response

Automatically detects and stores AI responses with metadata.

Supports formats:

  • OpenAI API responses
  • LangChain outputs
  • Simple text responses

Output:

{
  "success": true,
  "sessionKey": "chat-123",
  "message": {
    "role": "assistant",
    "content": "Hi there!",
    "metadata": {
      "model": "gpt-3.5-turbo",
      "tokens": 150
    }
  }
}

๐ŸŽฏ Format for AI

Formats conversation history for AI consumption with token limits.

Parameters:

  • Session Key: Chat session identifier
  • Token Limit: Maximum tokens for context (default: 4000)
  • AI Model: Model for token counting (GPT-3.5/GPT-4)

Output:

{
  "messages": [
    { "role": "user", "content": "Hello" },
    { "role": "assistant", "content": "Hi there!" }
  ],
  "sessionKey": "chat-123",
  "tokenLimit": 4000,
  "model": "gpt-3.5-turbo"
}

๐Ÿง  Smart Context Window

Retrieves context-aware message window based on token limits.

Output:

{
  "messages": [...],
  "sessionKey": "chat-123",
  "count": 5,
  "tokenLimit": 4000
}

๐Ÿ—‘๏ธ Clear Memory

Removes all messages for a specific session.

Output:

{
  "success": true,
  "sessionKey": "chat-123",
  "cleared": true
}

๐Ÿ“‹ Usage Examples

Basic Chat Memory Flow

[Chat Trigger] โ†’ [SQLite Memory: Auto-Store User] โ†’ [OpenAI] โ†’ [SQLite Memory: Auto-Store AI]

Context-Aware AI Chat

[Webhook] โ†’ [SQLite Memory: Auto-Store User] โ†’ [SQLite Memory: Format for AI] โ†’ [OpenAI] โ†’ [SQLite Memory: Auto-Store AI]

Manual Message Management

[Manual Trigger] โ†’ [SQLite Memory: Add Message] โ†’ [SQLite Memory: Get Messages]

Smart Context Retrieval

[HTTP Request] โ†’ [SQLite Memory: Smart Context Window] โ†’ [Process Messages] โ†’ [Response]

๐Ÿ—ƒ๏ธ Database Schema

File Location: Database file created in N8N working directory

Table Structure:

CREATE TABLE memory (
  sessionKey TEXT PRIMARY KEY,
  messages TEXT,
  created INTEGER,
  lastAccessed INTEGER
)

Message Format:

{
  "id": "uuid-v4",
  "role": "user|assistant|system",
  "content": "message text",
  "timestamp": 1703123456789,
  "metadata": {
    "model": "gpt-3.5-turbo",
    "tokens": 150
  }
}

โš™๏ธ Configuration

Session Keys

  • Auto-generated: Leave empty for automatic UUID generation
  • Custom: Use consistent keys across workflow nodes
  • Best Practice: Use meaningful identifiers like user-${userId}-chat

Token Limits

  • GPT-3.5 Turbo: 4,096 tokens (recommended: 3,500)
  • GPT-4: 8,192 tokens (recommended: 7,500)
  • GPT-4 Turbo: 128,000 tokens (recommended: 120,000)

Window Sizes

  • Small conversations: 5-10 messages
  • Medium conversations: 20-30 messages
  • Large conversations: 50+ messages (auto-trimmed)

๐Ÿ”ง Advanced Usage

Custom Session Management

  • Use consistent session keys across workflow nodes
  • Generate meaningful identifiers for better organization
  • Implement user-specific session isolation

Conditional Memory Storage

  • Filter messages based on importance or content type
  • Implement selective storage logic
  • Skip memory operations when not needed

Message Preprocessing

  • Clean and validate message content before storage
  • Add custom metadata for tracking
  • Transform message format as needed

๐Ÿšจ Troubleshooting

Node Not Appearing

  • Verify package installation
  • Restart N8N service
  • Check custom extensions configuration

Database Issues

  • Permission errors: Ensure N8N has write access to working directory
  • File not found: Database auto-creates on first use
  • Corruption: Reset database if needed (data will be lost)

Memory Not Persisting

  • Check session keys: Must be consistent across operations
  • Verify operations: Ensure using correct operation types
  • Database location: Check N8N working directory

Performance Issues

  • Large sessions: Use Smart Context Window instead of Get Messages
  • Token limits: Reduce window size or token limits
  • Cleanup: Regularly clear old sessions

๐Ÿ“Š Performance Tips

  1. Use Smart Context Window for large conversations
  2. Set appropriate token limits based on your AI model
  3. Implement session cleanup for old conversations
  4. Use consistent session keys to avoid fragmentation
  5. Monitor database size and clean up periodically

๐Ÿค Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests
  5. Submit a pull request

๐Ÿ“„ License

MIT License – see LICENSE file for details.

๐Ÿ”— Links

๐Ÿ“ž Support


Made with โค๏ธ for the N8N community