Postgres Memory
The Postgres Memory component acts as a secure, long-term storage system for your automation workflows in Nappai. Think of it as a reliable filing cabinet for your AI assistant’s memories. It allows you to save specific pieces of information (like user preferences, chat history, or task states) into a PostgreSQL database and retrieve them later when needed. This ensures that your automation processes can remember past interactions and maintain context across different steps of a workflow.
How it Works
This component connects your workflow directly to a PostgreSQL database to manage “memories.” When you use this component, it performs the following actions:
- Connects: It links to your PostgreSQL database using the credentials you have set up.
- Stores: You can save a piece of information (a “Memory Value”) by giving it a unique name (a “Memory Key”). You can choose whether to overwrite existing data with the same name or keep the old data.
- Retrieves: You can ask for a specific memory by providing its name (Key), and the component will return the stored value.
- Lists: It can also show you a list of all available memories or count how many are stored.
It uses advanced features like Semantic Search, which allows the AI to find memories based on meaning rather than just exact keyword matches, making it smarter for retrieving relevant information.
Connection & Credentials
This component requires a valid connection to your PostgreSQL database. Before using this component, you must set up a credential in Nappai.
- Go to the Credentials section in your Nappai panel.
- Create a new credential of the type Postgres SQL.
- You will need to enter your PostgresSQL Server Connection URL. This typically looks like
postgresql://user:password@host:port/database?sslmode=require.
- You will need to enter your PostgresSQL Server Connection URL. This typically looks like
- In your workflow, select the saved credential in the Credential input field of this node.
Note: You do not need to enter username, password, or server details directly in the component fields. Just select the credential you created in step 3.
Operations
This component is designed for automatic memory management within the Nappai framework. It handles storage and retrieval seamlessly based on the inputs provided, so you do not need to manually select specific operations like “Save” or “Load” in the interface.
Inputs
Input Fields
The following fields are available to configure this component. These inputs allow you to define what data is saved, how it is saved, and how it is retrieved.
- Embedding: Connect a component (like OpenAI, HuggingFace, or a local model) that converts text into numerical vectors. This is required if you want to use Semantic Search to find memories by meaning.
- Enable Checkpointing: A toggle to enable or disable checkpointing, which helps in saving the state of your workflow at specific points.
- Enable Store: A toggle to enable or disable the storage functionality entirely.
- Embedding Dimension: An integer specifying the dimension of the embeddings used by your connected model. This ensures the database understands the format of the data being stored.
- Session ID: (Required) A unique identifier for the current session. This helps organize memories so that they are specific to a particular user interaction or process instance.
- Conversation ID: (Required) A specific identifier for the conversation or message thread. This allows the component to link memories to specific contexts.
- Enable Semantic Search: A toggle to enable semantic search using vectors. When enabled, the component can find memories that are conceptually similar to your query, not just exact matches.
Outputs
The component provides several outputs that allow you to verify the status of the memory operation and access the stored data.
- Memory: The actual data retrieved from the database. This will be a text string or a structured data object (JSON) representing the stored memory.
- Success Status: A boolean value (
trueorfalse) indicating whether the memory operation (saving or retrieving) was successful. - Error Message: If the operation fails, this output provides a human-readable explanation of the error (e.g., connection issues or missing data).
- Memory Keys: A list of all the unique identifiers (keys) currently stored in the database for the specified session.
- Memory Count: The total number of memory records stored in the database.
Output Data Example (JSON)
json { “memory”: “User prefers email notifications for weekly reports.”, “success”: true, “error”: "", “keys”: [ “user_preferences_weekly_report”, “user_contact_info” ], “count”: 2 }
Connectivity
This component typically connects to Memory Storage or Context Management components within your workflow.
- Input Connections:
- Embedding: Connect to the output of an Embedding component (e.g., OpenAI Embedding, Local Embedding) to enable semantic search capabilities.
- Session ID / Conversation ID: Connect to outputs from a Chatbot or Message component to ensure memories are tied to the correct user interaction.
- Output Connections:
- Memory: Connect to AI Prompt components or Text Processing components to feed the retrieved context into your AI model’s reasoning.
- Success Status: Connect to Conditional or Decision components to trigger alternative flows if memory retrieval fails.
Usage Example
Imagine you are building an AI Assistant for Customer Support.
- Store: When a customer provides their phone number, you use the Postgres Memory component to save it. You set the
Session IDto the customer’s ticket number and theMemory Keytophone_number. TheMemory Valuecontains the actual phone number. - Retrieve: Later in the workflow, when the assistant needs to call the customer, it uses the Postgres Memory component again with the same
Session IDandMemory Key(phone_number) to retrieve the number. - Search: If you enable Semantic Search, the assistant can also find memories based on meaning. For example, searching for “contact details” might return the phone number memory, even if the key isn’t an exact match for that phrase.
Tips and Best Practices
- Use Unique Keys: Always use distinct
Memory Keysfor different pieces of information to avoid overwriting important data. - Enable Semantic Search: If you need your AI to understand context deeply, connect an Embedding model and enable Semantic Search. This makes memory retrieval much smarter.
- Check Success Status: Always check the
Success Statusoutput. If it isfalse, check theError Messageto understand why the memory operation failed (e.g., database connection issue). - Manage Session IDs: Use unique
Session IDsfor different users or threads to ensure that memories from one conversation do not interfere with another.
Security Considerations
- Credential Security: Ensure your PostgreSQL credential is stored securely in Nappai. Never share your database connection URL or passwords publicly.
- Data Isolation: Use
Session IDandConversation IDto isolate data between different users or workflows, preventing unauthorized access to other users’ memories. - Development Mode: This component is marked in development mode. Ensure you test thoroughly in a non-production environment before relying on it for critical data storage.