Skip to content
mainri

mainri

Helps you achieve transformational innovation at scale and speed!

  • Home
  • What we do
  • Why us
  • Show cases
  • Knowledge hub
    • Infrastructure and Architecture
    • Azure Data Factory and Synapse Analytics
    • Azure Databricks
    • Fabric
    • Azure Purview
    • Lakehouse
    • Power BI
    • SQL & KQL
    • AI / LLM
    • Azure Sentinel
    • Technical Interview Questions and Answers
  • Search

Tag: User Profile

Posted on

Long-term Memory: User Profile

Also called User Profile; User Preference Storage; User Preference Modeling, Personalization Layer; Contextual Memory; Persistent Memory

Imagine you have a personal assistant who remembers your coffee order, your preferred meeting times, and your communication style—not just for one conversation, but forever, across every interaction. That’s what “User Preference Storage in PostgreSQL” does for an AI agent. It’s a durable, relational database that stores everything the AI learns about a user, so the AI doesn’t forget you between sessions.

CN: 想象你有一个私人助理,他记得你的咖啡口味、你偏好的会议时间、你的沟通风格——不是只在一场对话中记住,而是永远记住,跨越每一次交互。这就是 PostgreSQL 中的”用户偏好存储”为 AI Agent 做的事情。它是一个持久的、关系型数据库,存储 AI 了解到的关于用户的一切,让 AI 不会在会话之间忘记你。

PostgreSQL has become the overwhelming first choice for AI agent memory in production systems. PostgreSQL is not just “a database” anymore. In the AI world, it has evolved into what many call the “memory layer” for enterprise AI systems

What does it include?

3.1 核心架构 (Core Architecture)

EN: User preference storage in PostgreSQL typically involves:

CN: PostgreSQL 中的用户偏好存储通常包括:

组件 (Component)EN DescriptionCN Description
Users TableStores basic user identity (user_id, created_at, etc.)存储用户基本身份信息
Preferences TableStores key-value pairs of user preferences存储键值对的用户偏好
Memory/History TableStores interaction history with timestamps存储带时间戳的交互历史
Vector Embeddings (pgvector)Stores semantic embeddings for similarity search存储用于相似性搜索的语义向量

3.2 偏好数据类型 (Types of Preferences)

EN: What kinds of preferences do we store?

CN: 我们存储哪些类型的偏好?

TypeEN ExamplesCN Examples
Explicit“I prefer Python over R”, “I like detailed answers”“我偏好 Python 而不是 R”,”我喜欢详细的回答”
ImplicitInferred from behavior (e.g., always asks for code examples)从行为推断(例如,总是要求代码示例)
Temporal“I’m usually available after 2 PM”“我通常在下午 2 点后有空”
Contextual“For data questions, give SQL; for strategy, give summaries”“数据问题给 SQL;战略问题给摘要”

Key Takeaways

要点 (Key Point)ENCN
PostgreSQL作为长期记忆存储PostgreSQL provides durable, ACID-compliant storage for user preferences across sessionsPostgreSQL 为跨会话的用户偏好提供持久的、ACID 合规的存储
JSONB vs EAVUse JSONB for flexible, schema-less preferences with GIN indexes使用 JSONB 实现灵活的、无 Schema 的偏好存储,配合 GIN 索引
pgvector for语义记忆pgvector enables semantic similarity search on memory embeddingspgvector 支持对记忆嵌入进行语义相似性搜索
异步连接池Use asyncpg connection pool for scalable, non-blocking operations使用 asyncpg 连接池实现可扩展的非阻塞操作
UPSERT模式Use INSERT … ON CONFLICT DO UPDATE for atomic upsert使用 INSERT … ON CONFLICT DO UPDATE 实现原子性 upsert
部分更新Use jsonb_set() to update individual preference keys without full document replacement使用 jsonb_set() 更新单个偏好键,无需完整替换文档
三层记忆架构Preferences (JSONB) + Semantic (pgvector) + Episodic (interactions)偏好 (JSONB) + 语义 (pgvector) + 情景 (交互)
生产就绪Connection pooling, transaction management, error handling are essential连接池、事务管理、错误处理是生产环境必需的

Search

  • Infrastructure and Architecture
    • What is Service Principal ID, Application ID, Client ID, Tenant ID
    • Comprehensive migration engineering strategy
    • Create Service Principle, Register an application on Azure Entra ID (former Active Directory)
    • Using Key Vault services in Azure Ecosystem
    • Configuring Azure Entra ID Authentication in Azure SQL Database
    • Introduce Medallion Architecture
    • Data Lake implementation – Data Lake Zones and Containers Planning
    • Create External Data Sources in Synapse Serverless SQL
    • Data lake vs delta lake vs data lakehouse, and data warehouses comparison
    • SharePoint Online grants ADF or ASA access to extract data
    • Unity Catalog: Create Metastore and Enabling Unity Catalog in Azure
  • Azure Data Factory and Synapse Analytics
    • Create External Data Sources in Synapse Serverless SQL
    • ADF activities failure vs pipeline failure and pipeline error handling logical mechanism
    • Comparing the use of wildcards in the Copy Activity of Azure Data Factory with the Get Metadata activity for managing multiple file copies
    • Azure Data Factory or Synapse Analytic Lookup Activity Filter Modified date query for SharePoint Online List
    • Metadata driven full solution to incrementally copy data from SharePoint Online sink to ADSL Gen2 by using Azure Data Factory or Synapse
    • Azure Data Factory or Synapse lookup Delta table in Databricks Unity Catalog
    • Comparative Analysis of Linked Services in Azure Data Factory and Azure Synapse Analytics
    • Azure Data Factory or Synapse Copy Activity with File System
    • Get Metadata activity in ADF or ASA
    • Building Slowly Changing Dimensions Type 2 in Azure Data Factory and Synapse
    • Dynamic ETL Mapping in Azure Data Factory/Synapse Analytics: Source-to-Target Case Study Implementation (1)
    • Change Data Capture with Azure Data Factory and Synapse Analytics
    • Using Exists Transformation for Data Comparison in Azure Data Factory/Synapse
    • Data Flow: Aggregate Transformation
  • Azure Databricks
    • Data Quality Framework (DQX)
    • A few Important Terminology of Databricks
    • Unity Catalog
      • Unity Catalog in Databricks
      • Comparison of Unity Catalog, External Data Source, External Table, Mounting Data and Metastore
      • Unity Catalog: Create Metastore and Enabling Unity Catalog in Azure
      • Unity Catalog: Create Storage Credentials and External Locations
      • Comparison of the Hive Metastore, Unity Catalog Metastore, and a general Metastore
      • Unity Catalog: Catalogs and Schemas
      • Unity Catalog – Table Type Comparison
      • Unity Catalog: Creating Tables
      • Unity Catalog: Data Access Control with Databricks Unity Catalog
    • Read table from Unity Catalog and write table to Unity Catalog
    • DBFS
      • DBFS: Databricks File System (DBFS)
      • DBFS: Access database read/write database using JDBC
      • DBFS: Access ADLS or Blob using Service Principle with Oauth2
    • dbutils
      • dbutils: Databricks File System, dbutils
      • dbutils: Secrets and Secret Scopes
      • dbutils: mount, using Account Key or SAS to access adls or blob
      • dbutils: widgets
      • dbutls: notebook run(), exit() and pass parameters
    • ADB
      • Comparison between All-Purpose Cluster, Job Cluster, SQL Warehouse and Instance Pools
      • Partition in databricks
      • Comparison Partitioning Strategies and Methods
    • delta
      • Delta Table, Delta Lake
      • Delta: Time Travel of Delta Table
      • delta: Schema Evolution
    • deltaTable vs DataFrames
    • Implementing Slowly Changing Dimension Type 2 Using Delta Lake on Databricks
    • Overview of Commonly Used Unity Catalog and Spark SQL Management Commands
    • Read a delta table from Blob/ADLS and write a delta table to Blob/ADLS
    • Spark
      • spark: RDD, Dataframe, Dataset, Transformation and Action
    • Add a new user to workspace
    • PySpark
      • Summary of Dataframe Methods
      • Pyspark: read and write a csv file
      • Pyspark: read, write and flattening complex nested json
      • Pyspark: read and write a parquet file
      • DBFS: Access database read/write database using JDBC
      • withColumn, select
      • StructType(), StructField()
      • arrayType, mapType column and functions
      • from_json(), to_json()
      • condition: when (), otherwise (), expr()
      • withColumnRenamed(), drop(), show()
      • alias(), asc(), desc(), cast(), filter(), where(), like() functions
      • distinct(), dropDuplicates(), orderBy(), sort(), groupBy(), agg()
      • Join(), union(), unionAll(), unionByName(), fill(), fillna()
      • contains(), collect(), transform(), udf(), udf for sql
      • Comparison of transform() and udf() in PySpark
    • PySpark Data sources
    • PySpark DataFrame
    • PySpark Built-in Functions
  • Fabric
    • Introducing Fabric
    • Fabric terminology
    • Comparation of V-order, Z-order, liquid clustering
  • Lakehouse
    • Data Lake implementation – Data Lake Zones and Containers Planning
    • Data lake vs delta lake vs data lakehouse, and data warehouses comparison
    • Unity Catalog: Create Metastore and Enabling Unity Catalog in Azure
    • Comparing the use of wildcards in the Copy Activity of Azure Data Factory with the Get Metadata activity for managing multiple file copies
    • Unity Catalog in Databricks
    • Azure Data Factory or Synapse lookup Delta table in Databricks Unity Catalog
    • Delta Table, Delta Lake
    • Delta: Time Travel of Delta Table
    • delta: Schema Evolution
    • Comprehensive migration engineering strategy
  • Azure Purview
    • Azure Purview Introduction
    • Day 2: Quick start, what is inside
    • Day 3: How Microsoft Purview works – Data Source, Rule Sets, and Classification
    • Day 4: Registering ADLS Gen2 and Scan in Purview
    • Day 5: Registering Azure SQL Database and Scan in Purview
    • Day 6: Registering Azure Synapse Analytics workspaces and scan in Microsoft Purview
    • Day 7: Permission and Roles, Business Glossary and Collections Access Control in Purview
    • Day 8 – Data Lineage, Extract SQL, ADF, Synapse Pipeline Lineage
    • Day 9: Managed attributes in Data Map
    • Day 10: Workflows in Azure Purview
  • SQL & KQL
    • SQL
      • Comparison of Azure SQL Managed Instance, Azure SQL Database, Azure SQL Server
      • Configuring Azure Entra ID Authentication in Azure SQL Database
      • Create External Data Sources in Synapse Serverless SQL
      • Create External Data Sources in Synapse Serverless SQL
      • Using SQL Server Change Data Capture (CDC) in pipeline to implement incrementally UPSERT
      • Using sp_MSforeachdb to Search for Objects Across All Databases
      • Summary of Commonly used T-SQL queries
      • Summary of SQL built-in functions
      • Locking Mechanisms in Relational Database Management Systems (RDBMS)
    • KQL
      • Kusto Query Language (KQL) – quick reference
      • KQL query map SQL query
  • Power BI
  • AI / LLM
    • Summary of AI, ML, LLM
    • Frequently Used GenAI & LLM Concepts (Simple Explanations)
    • Agent Harness and its 12 Core Modules
    • LLM Fundamentals
    • Enterprise AI / LLM System
    • LLM Reasoning vs Retrieval (RAG)
    • Phase II – Azure AI Foundry service
    • Sign up OpenAI
    • Prompt / Prompt Engineering
    • Temperature
    • Token Fundamentals
    • LangChain – LLM Wrapper
    • PromptTemplate
    • Chain
  • Azure Sentinel
    • Kusto Query Language (KQL) – quick reference
    • KQL query map SQL query
  • Technical Interview Questions and Answers

At Mainri, we provide Consulting as a Service (CaaS) that helps you manage your growth while keeping your team focused on their core activities.

70 Forest Manor Road
Toronto Ontario Canada M2J 0A9
Tel. 437-800-8805
Email: info@mainri.ca

Search

Proudly powered by WordPress