npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

n8n-nodes-postgres-context

v1.0.13

Published

n8n nodes for AI context management with PostgreSQL

Readme

n8n-nodes-postgres-context

This is an n8n community node package that provides nodes for AI context management with PostgreSQL persistence.

Overview

This package contains two nodes for managing AI context in n8n workflows:

  1. Context Manager Node: Used within AI agent flows to retrieve contexts by type, with filtering and limits.
  2. External Context Node: Used to save or retrieve external contexts from any type and scope.

PostgreSQL Setup

Before using these nodes, you need to set up a PostgreSQL database with the following table:

CREATE TABLE IF NOT EXISTS ai_contexts (
  id SERIAL PRIMARY KEY,
  chat_id TEXT NOT NULL,
  user_id TEXT,
  agent_id TEXT,
  session_key TEXT NOT NULL,
  context_key TEXT NOT NULL,
  context_type TEXT DEFAULT 'session',
  context_value JSONB NOT NULL,
  created_at TIMESTAMPTZ DEFAULT NOW(),
  updated_at TIMESTAMPTZ DEFAULT NOW(),
  UNIQUE (chat_id, context_key, context_type)
);

CREATE INDEX IF NOT EXISTS idx_context_chat_type ON ai_contexts (chat_id, context_type, updated_at DESC);

The nodes will automatically create this table if it doesn't exist, but it's recommended to set it up manually for better control.

Node Usage

Context Manager Node

This node allows AI agents to retrieve contexts by type with filtering and limits.

Parameters

| Parameter | Type | Description | |-----------|------|-------------| | chatId | string | Unique identifier for the conversation | | alwaysInclude | multiOptions | Context types that should always be included | | limitsPerType | fixedCollection | List of types with maximum number of records | | connectionString | string | PostgreSQL connection string |

Example

{
  "chatId": "chat-123",
  "alwaysInclude": ["api"],
  "limitsPerType": [
    {"type": "user", "limit": 20},
    {"type": "agent", "limit": 10}
  ]
}

External Context Node

This node allows saving or retrieving external contexts of any type and scope.

Parameters

| Parameter | Type | Description | |-----------|------|-------------| | mode | options | 'save' or 'get' | | chatId | string | Unique identifier for the conversation | | contextKey | string | Name of the context key | | contextType | string | Type of the context (api, user, etc.) | | contextValue | json | (save mode) JSON object to be saved as context | | userId | string | (save mode) Optional user identifier | | agentId | string | (save mode) Optional agent identifier | | sessionKey | string | (save mode) Session identifier | | connectionString | string | PostgreSQL connection string |

Example: Saving Context

{
  "mode": "save",
  "chatId": "chat-123",
  "contextKey": "weather-forecast",
  "contextType": "api",
  "contextValue": {
    "city": "Arraial do Cabo",
    "temperature": "27°C",
    "status": "Ensolarado"
  }
}

Example: Getting Context

{
  "mode": "get",
  "chatId": "chat-123",
  "contextKey": "weather-forecast",
  "contextType": "api"
}

Context Types

The following context types are supported:

  • user
  • agent
  • api
  • memory
  • short_term
  • long_term
  • system
  • custom

Best Practices

  • Use context_type as a way to group logics: user, api, memory, etc.
  • Use ExternalContextNode for programmatic populations (via Webhook, Workers, etc).
  • Add TTL with periodic cleaning by updated_at.
  • Index by chat_id and context_type for performance.

Examples

This package includes example workflows in the examples directory that demonstrate how to use the nodes in n8n. See the examples README for more information.

License

MIT