DEV Community

rocky007cn
rocky007cn

Posted on

PVM:Give any LLM long-term memory.No API keys,no GPU,~800 lines Python.

PVM: Give any LLM long-term memory. No API keys, no GPU, ~800 lines Python.


Every LLM you've ever used is an amnesiac.

ChatGPT forgets your name between sessions. Cursor forgets your project conventions overnight. Claude forgets the decision your team made three conversations ago. This isn't a bug — it's architecture. LLMs are stateless. Every conversation starts from zero.

The industry's answer has been RAG — retrieve relevant context, stuff it into the prompt, hope the model figures it out. It mostly works for simple Q&A. It falls apart when information changes.


The problem with "just search for it"

RAG treats memory as a search problem: encode everything into vectors, find the most "similar" ones, return them.

This breaks in three ways that anyone who's used AI seriously has felt:

1. Information rots, but vectors don't know that.
Your company changed its API policy three months ago. The old policy document is still in the vector database, semantically similar to "API policy," and gets returned alongside the new one. Which one should the LLM trust? RAG shrugs.

2. You correct it, it forgets the correction.
You tell the AI "no, that's outdated." It apologizes. Next session, same query, same outdated result. There's no feedback loop. The vector database never learns.

3. When multiple things match, it guesses.
Three memories all look relevant. The system picks the highest cosine similarity score and presents it as fact. Wrong choice? Too bad. The user's trust erodes one guess at a time.


What PVM does differently

PVM (Persistent Vector Memory) replaces similarity with evolution.

Every memory carries a weight that changes over time. Every memory records when it was stored, when it was last accessed, and what it's connected to. The system doesn't just find things — it tracks how their importance changes.

Three mechanisms make this work:

Temporal weight decay.
A memory not accessed for 69 days has its weight halved. Not accessed for a year? It sinks to the bottom. You don't write expiration rules. Time handles it.

Delta Rule calibration.
User confirms a memory → weight moves up. User corrects it → weight moves down. This is the Widrow-Hoff Delta Rule from 1960 — one subtraction, one multiplication, one addition. O(1). No GPU. No batch training. Five confirmations moves a weight from 0.50 to 0.61. Five corrections drops it to 0.39.

Fuzzy attribution.
When multiple memories match and no single one is clearly right, PVM doesn't guess. It tells you: "I found a pattern across three memories spanning 180 days. Here's what they share." Then when you pick the right one, the weight updates. Next time it knows.


What this enables

AI that actually gets better the more you use it.

A writer who's been drafting a novel for six months — PVM remembers every character detail, every plot thread, every abandoned idea, and surfaces the relevant ones without flooding the context window. The AI stops contradicting itself in Chapter 12 about a detail from Chapter 3.

A development team using Cursor — their coding conventions, architectural decisions, and bug histories persist across sessions. New team members onboard by querying the team's memory, not by reading a wiki that's already stale.

A customer support agent — user preferences evolve. Someone who loved blue last year now only buys black. PVM's weights track the shift automatically. The AI recommends black, not blue.


Compared to what's out there

Mem0 Letta Pinecone/RAG PVM
Learns from feedback
Temporal weight decay
Fuzzy attribution
Needs API keys 2 keys 1 key 1+ keys 0
Needs GPU Yes Yes Cloud No
Data leaves your machine Yes Yes Yes No
Lines of code ~10K+ ~10K+ Varies ~800

How to use it

pip install pvm-memory
Enter fullscreen mode Exit fullscreen mode
from pvm import PVMEngine

engine = PVMEngine()

# Store a memory
fp = engine.store("User prefers dark mode in all editors", 
                   keywords=["preference", "dark mode", "editor"])

# Query later — weights have evolved
results = engine.query("What UI preferences does the user have?")

# User confirms — weight goes up
engine.calibrate(fp, signal=1.0)

# User corrects — weight goes down  
engine.calibrate(fp, signal=0.0)
Enter fullscreen mode Exit fullscreen mode

That's the entire API. Three methods.


The catch

I built this alone. It's not a company. There's no sales team, no funding, no enterprise support. The code is open source (BSL → MIT 2030). If it's useful to you, use it. If you find bugs, open an issue. If you want to build something on top of it, go ahead.

The paper explaining the architecture is on SSRN and in the GitHub repo.


Wenhui Tian is an independent researcher. He works on causal inference, memory systems, and the intersection of economics and AI. He can be reached at rocky007cn@outlook.com.


Top comments (0)