A sophisticated persistent memory system for Open WebUI that extracts and maintains user information across conversations using LangGraph and PostgreSQL.
Beau D'Amore
www.damore.ai
- Persistent Memory: Remembers user preferences, relationships, goals, interests, and personal information
- PII Protection: 3-layer defense-in-depth filtering prevents storage of phone numbers, SSNs, addresses, credit cards, and other personally identifiable information — while still storing personality traits, preferences, and ownership types
- Preference Evolution Tracking: Tracks how user preferences change over time (e.g., "used to like coffee → now prefers tea")
- PostgreSQL Backend: Reliable, persistent storage with LangGraph checkpoint support
- Multi-Model Support: Works with GPT-4, Llama, Qwen, Gemini, and other extraction models
- Schema Versioning: Built-in migration system for data structure evolution
memory_langgraph/
├── README.md # This file
├── DEPENDENCY_RESOLUTION.md # Dependency troubleshooting guide
├── test_imports.py # Dependency verification script
├── filter/
│ ├── langgraph_memory_filter.py # Main filter code
│ └── requirements-langgraph.txt # Python dependencies
├── docker/
│ └── docker-compose.langgraph.yml # PostgreSQL container
├── docs/
│ ├── LANGGRAPH_SETUP.md # Full installation guide
│ ├── EXTRACTION_MODEL_SETUP.md # Extraction model configuration
│ ├── AI_DEVELOPMENT_GUIDE.md # Guide for AI assistants
│ └── ...
└── prompt/
└── EXTRACTION_PROMPT.md # Extraction model system prompt
cd docker
docker-compose -f docker-compose.langgraph.yml up -d# In your Open WebUI container
docker exec -it <open-webui-container> pip install \
"langgraph>=1.0.0" \
langgraph-checkpoint-postgres \
"psycopg[binary]" \
psycopg-pool- Go to Open WebUI Admin Panel → Functions
- Click "+ Add Function"
- Paste the contents of
filter/langgraph_memory_filter.py - Save and enable the filter
See docs/EXTRACTION_MODEL_SETUP.md for detailed instructions.
Quick version:
- Create a custom model in Open WebUI with the system prompt from
prompt/EXTRACTION_PROMPT.md - Set the filter's
extraction_model_idvalve to your model's ID
| Document | Description |
|---|---|
| LANGGRAPH_SETUP.md | Complete installation and setup guide |
| EXTRACTION_MODEL_SETUP.md | Extraction model configuration |
| AI_DEVELOPMENT_GUIDE.md | Guide for AI assistants modifying this code |
| DEPENDENCY_RESOLUTION.md | Dependency troubleshooting |
- Open WebUI: Latest version
- Python: 3.10+
- PostgreSQL: 16+ (provided via Docker)
- Dependencies:
langgraph>=1.0.0 langgraph-checkpoint-postgres psycopg[binary] psycopg-pool
cd docker
docker-compose -f docker-compose.langgraph.yml up -dDefault Connection:
- Host:
localhost(orlanggraph-postgresfrom other containers) - Port:
5432 - Database:
langgraph_memory - User:
langgraph - Password:
langgraph_password_change_me
The filter has configurable "valves" (settings):
| Valve | Default | Description |
|---|---|---|
enable_filter |
true |
Enable/disable the filter |
postgres_connection_string |
postgresql://... |
Database connection |
extraction_model_id |
"" |
Model ID for memory extraction |
debug_logging |
false |
Enable verbose logging |
enable_memory_injection |
true |
Inject memories into context |
pii_filter_enabled |
true |
Enable PII detection and filtering |
pii_filter_mode |
"remove" |
remove drops facts with PII; redact stores with [REDACTED] |
pii_scrub_input |
true |
Scrub PII from messages before sending to extraction model |
pii_patterns_enabled |
all 10 | Which PII types to detect (see PII Protection section) |
See PII Protection for details on privacy filtering.
python test_imports.pydocker exec -it langgraph-postgres psql -U langgraph -d langgraph_memory -c "SELECT 1;"docker exec -it langgraph-postgres psql -U langgraph -d langgraph_memory -c \
"SELECT thread_id, checkpoint FROM checkpoints ORDER BY thread_id LIMIT 5;"The filter includes a 3-layer defense-in-depth system to prevent storage of personally identifiable information:
The extraction model's system prompt explicitly instructs it to never extract PII. Examples are provided showing how to extract non-PII meaning from PII-containing messages (e.g., "I bought a house at 123 Oak Lane" → store ownership: house, recently purchased a house).
Before messages reach the extraction model, all PII is replaced with [REDACTED]. The LLM never sees raw PII data.
Every extracted fact is scanned for PII in both subject and value fields, plus a subject blocklist. Facts with PII are either dropped or redacted based on config.
| Pattern | Example |
|---|---|
| Social Security Number | 123-45-6789 |
| Credit Card | 4111-1111-1111-1111 |
| Phone Number | (555) 123-4567 |
| Email Address | user@example.com |
| Street Address | 123 Main Street Apt 4B |
| Passport Number | Passport: A12345678 |
| Driver's License | Driver's license: D1234567 |
| Bank Account | Account #: 123456789 |
| Date of Birth | DOB: 01/15/1990 |
| IP Address | 192.168.1.1 |
- Personality traits, preferences, opinions
- Ownership types ("owns a Tesla" — not the VIN)
- Relationships ("married to Sarah" — not her phone number)
- Goals, skills, interests, hobbies
- Professional info ("engineer at Acme" — not employee ID)
Current: Schema v4 (LLM-Powered Semantic Merge + PII Protection)
Schema v4 features:
- LLM-powered semantic merge replaces code-based deduplication
- Flexible fact-based storage (replaces rigid type system)
- 3-layer PII filtering (prompt guardrails, regex pre-scrub, post-extraction validation)
schema_migrationstable for version tracking
If you're an AI assistant modifying this codebase, please read:
📚 docs/AI_DEVELOPMENT_GUIDE.md
This document contains critical information about:
- Schema version requirements
- Pitfalls to avoid
- Code modification procedures
- Testing requirements
cannot import name 'RunnableSerializable'
pip install "langgraph>=1.0.0"ImportError: no pq wrapper available
pip install "psycopg[binary]"ModuleNotFoundError: No module named 'psycopg_pool'
pip install psycopg-poolSee DEPENDENCY_RESOLUTION.md for detailed troubleshooting.
MIT License
- Open WebUI - The amazing AI chat interface
- LangGraph - State machine for LLM applications
- LangChain - LLM application framework