Integrate Long-Term Memory Skills with Coding Agent
AnalyticDB for PostgreSQL long-term memory Skills is a set of development knowledge management tools that run in Claude Code. Each Skill can be triggered by slash commands (such as /adbpgmem-record) or natural language (such as "record this"). By connecting to the AnalyticDB for PostgreSQL long-term memory service API, AI assistants can capture, retrieve, and maintain implicit knowledge from development conversations, such as experiences, decisions, and lessons learned that are critical to a project but not captured in code.
Core value: Transform development experiences from ephemeral conversations into searchable, reusable knowledge assets.
How it works
AnalyticDB for PostgreSQL long-term memory Skills works in three stages:
Environment detection and configuration loading
When a user triggers a Skill, it detects the current IDE type through environment variables (CLAUDECODE identifies the Claude Code environment). It then reads the adbpgmem.conf configuration file from the .claude/ directory to obtain the API endpoint, authentication token, and user identifier.
Memory operation execution
Depending on the triggered Skill type, the corresponding operation runs through the AnalyticDB for PostgreSQL long-term memory service REST API:
-
Write knowledge (
POST /v3/memories/add/): Writes structured development knowledge to the remote memory store. -
Semantic retrieval (
POST /v3/memories/search/): Searches historical memories by semantic similarity. -
Memory list (
POST /v3/memories/?page=X&page_size=Y): Retrieves the user's memory list with pagination. -
Update memory (
PUT /v1/memories/{id}/): Modifies the content of an existing memory. -
Delete memory (
DELETE /v1/memories/{id}/): Removes expired or obsolete memories.
Result processing and presentation
The API results are processed by the AI and presented in a structured format, including write summaries, ranked retrieval results, health statistics, and cleanup recommendations.
Key design principles:
-
Automatic IDE detection: The Skill identifies the current IDE through environment variables and stores configuration files in the corresponding directory.
-
Project-level configuration: Each project has its own
adbpgmem.conf, so different projects can use different API endpoints and user identifiers. -
REST API communication: All memory operations are performed through HTTP APIs, supporting semantic search, intelligent deduplication, and paginated retrieval.
Skill overview
| Skill | Command | Function | Description |
|---|---|---|---|
| setup | /adbpgmem-setup |
Configuration | Configure the API endpoint, token, and user identifier. |
| record | /adbpgmem-record |
Knowledge capture | Write high-value knowledge from conversations to the memory store. |
| recall | /adbpgmem-recall |
Knowledge retrieval | Retrieve historical development experiences from the memory store. |
| review | /adbpgmem-review |
Memory maintenance | Review memory store health and clean up expired or duplicate entries. |
Scenarios
| Scenario | Recommended Skill | Description |
|---|---|---|
| First-time use, need to configure connection | /adbpgmem-setup |
Must be completed first. |
| Solved a tricky bug, want to record it | /adbpgmem-record |
Say "remember this" to trigger. |
| Encountered a similar issue, want to check history | /adbpgmem-recall |
Say "how did we solve this before" to trigger. |
| Memory store used for a while, want to clean up | /adbpgmem-review |
Say "clean up memories" to trigger. |
Prerequisites
-
AI IDE: Claude Code.
-
AnalyticDB for PostgreSQL long-term memory service: A running instance is required (for setup instructions, see AnalyticDB for PostgreSQL long-term memory service), including:
-
API URL (for example,
http://your-server:8000). -
API Token (for authentication).
-
User ID (username, used to identify memory ownership).
After activation, you must click Authorize Service in the API KEY Management section to authorize the API KEY for the long-term memory service.
-
-
Network connectivity: The machine running the IDE must be able to reach the AnalyticDB for PostgreSQL long-term memory service API endpoint (a public network address).
Install Skills
Skills are Markdown files stored in the AI IDE skills directory. You can install them globally or at the project level:
# Project-level skills (effective only for the current project, managed with the project repository)
{project-root}/.claude/skills/
├── adbpgmem-setup/SKILL.md # Configuration
├── adbpgmem-record/SKILL.md # Knowledge capture
├── adbpgmem-recall/SKILL.md # Knowledge retrieval
└── adbpgmem-review/SKILL.md # Memory maintenance
# Global skills (effective for all projects)
~/.claude/skills/
├── adbpgmem-setup/SKILL.md
├── adbpgmem-record/SKILL.md
└── ...
Installation steps:
-
Copy the 4
adbpgmem-*/SKILL.mdfiles to the skills directory of the corresponding IDE (project-level or global). -
Restart the IDE or reload the skills configuration.
-
Type
/adbpgmem-in a conversation to confirm the skills are recognized.
.agents/skills/ is the universal directory for the Agent Skills open standard, compatible with all three IDEs. Use this path if you want the same set of skills to work across different IDEs.
Configure Skills
Before first use, run /adbpgmem-setup to complete the configuration.
Step 1: Run the configuration command
Type the following in an AI IDE conversation:
/adbpgmem-setup
Or say "configure memory" or "set up adbpgmem".
Step 2: Enter configuration information
The AI prompts you for three configuration items:
| Item | Description | Example |
|---|---|---|
| API URL | The AnalyticDB for PostgreSQL long-term memory service endpoint. | http://192.168.1.100:8000 |
| API Token | The authentication token. | your-api-token-here |
| User ID | The user identifier (username). | zhangsan |
If a configuration already exists, you can select "keep unchanged" to retain the existing values, or enter new values to overwrite them.
Step 3: Connectivity test
After configuration, a connectivity test runs automatically (up to 2 retries):
-
HTTP 200: Connection successful, configuration saved.
-
HTTP 401/403: Token invalid, re-enter required.
-
Timeout/Connection failure: URL is incorrect or the service is unavailable.
Step 4: Confirm completion
After successful configuration, the configuration file is written to the project's IDE directory:
# Configuration file path example
Claude Code: .claude/adbpgmem.conf
Example configuration file content:
# ============================================================
# adbpgmem x AI IDE Integration Configuration
# File permissions: chmod 600 (contains API Token)
# ============================================================
# ── Connection ──
ADBPGMEM_API_URL="http://192.168.1.100:8000"
ADBPGMEM_API_TOKEN="your-api-token-here"
# ── User Identifier (user_id, username only, not project name) ──
# Priority: this value > whoami
ADBPGMEM_USER_ID="zhangsan"
Update and delete configuration
-
Reconfigure: Run
/adbpgmem-setupand select "reconfigure" to modify some or all parameters. -
Delete configuration: Run
/adbpgmem-setupand select "delete" to remove the configuration file.
Use Skills
Knowledge recording (record)
Trigger methods:
-
Slash command:
/adbpgmem-record -
Natural language: "remember this", "record this", "don't forget this pitfall", "this experience is important", "don't make this mistake again"
-
AI proactive suggestion: The AI suggests recording when high-value knowledge emerges during a conversation.
Workflow:
-
Identify knowledge: Extract high-value knowledge from the current conversation and structure it into three key elements.
-
Automatic deduplication: Check for similar existing memories through semantic search (score > 0.85). If a match is found, update the existing entry; otherwise, create a new one.
-
Write to memory store: Uses jq to safely construct JSON, preventing write failures from special characters.
-
Output summary: Displays the write results.
Knowledge categories:
| Type | Description | Example |
|---|---|---|
| architecture | Architectural decisions. | "Chose Redis over Memcached because persistence is required" |
| solution | Problem solutions. | "Kafka consumer lag resolved by increasing partitions" |
| pattern | Coding patterns or conventions. | "All APIs must return a unified Result wrapper class" |
| debug | Debugging experiences. | "Connection pool exhaustion caused by unclosed PreparedStatement" |
| context | Environment or business context. | "Production database primary-replica delay is approximately 200ms" |
Output example:
Wrote 2 memories to adbpgmem (user: zhangsan)
1. Kafka offset commit uses manual mode to avoid duplicate consumption
2. Reason for adjusting order service timeout threshold from 3s to 5s
Notes:
-
Up to 5 memories can be captured at a time. If more are available, the user is asked to select the most important ones.
-
If the conversation does not contain knowledge worth recording, the user is informed and the process ends.
-
Do not record passwords, API keys, tokens, personally identifiable information, or production environment IPs.
-
Content wrapped in
<private>tags is automatically discarded.
Knowledge retrieval (recall)
Trigger methods:
-
Slash command:
/adbpgmem-recall -
Natural language: "how did we solve this last time", "encountered a similar issue before", "any related experience", "we hit this pitfall before"
-
AI proactive suggestion: The AI triggers retrieval when it determines the current problem may have historical precedents.
Workflow:
-
Understand intent: Extracts the search topic, keywords, time range, and project scope from the user's question.
-
Semantic search: Retrieves related memories through the AnalyticDB for PostgreSQL semantic search API (default top_k=5).
-
Filter and rank: Filters out results with score < 0.5 and sorts by relevance in descending order.
-
Structured presentation: Displays results as type tag + content + relevance score.
Cross-project retrieval: To search across projects, remove the user_id filter to broaden the scope (top_k=10).
Output example:
Found 3 related historical memories:
1. [solution] Kafka offset commit uses manual mode to avoid duplicate consumption (relevance: 0.92)
Details: In auto-commit mode, when a consumer crashes and restarts, it starts from the last committed offset...
Recorded: 2025-05-15
2. [debug] Kafka consumer group rebalance causes message loss (relevance: 0.75)
Details: max.poll.interval.ms set too low, processing time exceeding this value triggers rebalance...
Recorded: 2025-04-20
3. [pattern] Message queue consumers uniformly use @KafkaListener annotation (relevance: 0.65)
Recorded: 2025-03-10
Notes:
-
Search queries are truncated to 500 characters to stay within API limits.
-
Each search returns a maximum of 10 results.
-
If no matches are found, try different keywords or use
/adbpgmem-recordto record the current experience.
Memory maintenance (review)
Trigger methods:
-
Slash command:
/adbpgmem-review -
Natural language: "clean up memories", "what have I recorded", "how many memories do I have", "review memories"
Recommended frequency: Once a month, or after every 50 new memories.
Workflow:
-
Fetch memories: Retrieves memories through the list API with pagination (200 entries maximum by default).
-
Statistics dashboard: Generates a health report by type and time dimensions.
-
Identify issues: Flags memories with four types of issues: expired, low-quality, duplicate, and orphaned.
-
Present recommendations: Displays the issue list and recommended actions, and waits for the user to confirm each item.
-
Execute cleanup: Performs updates or deletions based on the user's confirmed decisions.
-
Promotion suggestions: Identifies high-value memories (architecture/pattern types) and recommends syncing them to AGENTS.md.
-
Output summary: Displays operation statistics and the current total number of memories.
Issue identification criteria:
| Issue type | Identification criteria | Recommended action |
|---|---|---|
| Expired memory | Context type with content related to temporary configurations or environment issues. | Delete. |
| Low-quality memory | Content is too generic (fewer than 20 characters) or lacks specific details. | Update with more details or delete. |
| Duplicate memory | Two memories describe highly similar content (semantically similar). | Merge into one. |
| Orphaned memory | Memory not tagged with a type label. | Add a category tag. |
Output example:
=== Memory Store Health Report ===
Project: my-project
Total memories: 83 (83 analyzed)
Distribution by type:
architecture (architectural decisions): 8
solution (solutions): 15
pattern (coding patterns): 12
debug (debugging experiences): 9
context (project context): 3
uncategorized: 36
Issues requiring attention:
[expired] (2 entries)
1. "Test environment database address is 10.0.0.5" -> Recommend: delete
[duplicate] (1 group)
1. "Kafka offset manual commit" and "Kafka consumer offset management" -> Recommend: merge
Cleanup complete: 1 updated, 2 deleted, 1 group merged
Promotion suggestion: 2 architectural decisions recommended for syncing to AGENTS.md
Current total memories: 44
========================
Notes:
-
The list API supports pagination (50 entries per page) and retrieves up to 200 entries by default.
-
Update and delete operations require per-item user confirmation and are not executed in batch.
-
An updated memory must not exceed 2,000 tokens. If it does, the content is summarized and compressed first.
Typical scenarios
Scenario 1: Bug troubleshooting loop
Developer: The order API response time spiked from 200ms to 5s. Help me investigate.
AI: (Investigation... found N+1 query issue) Fixed by adding JOIN FETCH in OrderRepository.
Developer: Record this pitfall.
AI: -> Triggers /adbpgmem-record, writes [debug] type memory
Next time a similar issue occurs:
Developer: The user list API is slow again. Any similar experience from before?
AI: -> Triggers /adbpgmem-recall
AI: Based on historical memories, the last order API slowness was also an N+1 query issue,
resolved by adding JOIN FETCH in Repository. Recommend checking SQL logs first.
Scenario 2: Team knowledge sharing
New member joins the project:
Developer: Any development experience or tips for this project?
AI: -> Triggers /adbpgmem-recall (cross-project retrieval mode)
AI: Found 12 team historical memories:
1. [architecture] Chose PostgreSQL over MySQL because JSONB support is needed
2. [pattern] All REST APIs must return a unified ApiResponse wrapper class
3. [debug] KEYS command blocks in Redis cluster mode, must use SCAN
...
Scenario 3: Multi-IDE collaborative development
Configure in Qoder (auto-detects .qoder/ directory):
/adbpgmem-setup -> Config written to .qoder/adbpgmem.conf
Configure the same service in Cursor (auto-detects CURSOR_AGENT environment variable):
/adbpgmem-setup -> Config written to .cursor/adbpgmem.conf
Both IDEs share the same long-term memory service and User ID, with synchronized memories.
Knowledge recorded in Qoder can also be retrieved in Cursor.
Command quick reference
| Command | Natural language trigger | Function |
|---|---|---|
/adbpgmem-setup |
"configure memory", "set up adbpgmem" | Configure, reconfigure, or delete connection parameters. |
/adbpgmem-record |
"remember this", "record this", "don't forget this pitfall" | Capture knowledge from the current conversation. |
/adbpgmem-recall |
"how did we do this before", "any related experience" | Retrieve historical development experiences. |
/adbpgmem-review |
"clean up memories", "how many memories do I have" | Review and maintain memory store health. |