Building AI agents is all fun and games until the context window slides.
You spend hours crafting the perfect system prompt, you feed it documentation, and you have a great conversation. Then, 10 minutes later, the agent forgets a crucial dependency you mentioned at the start.
It has the memory of a goldfish.
We try to fix this with RAG (Vector Databases). We tell ourselves "It has access to my entire codebase!" but deep down, we know the truth: Vector databases are just spicy Ctrl+F.
They find keywords. They don't understand relationships. If you ask about a concept that is scattered across five different files, standard RAG fails.
The Problem: Vectors are lonely
When you store a chunk of text in a vector database, it sits there alone. It has no idea that File A imports File B, or that the function processData modifies the schema in database.ts.
To an AI using standard RAG, these are just unconnected snippets. It lacks the "connective tissue" that makes up real memory.
The Solution: Give the AI a "Sleep Cycle"
I got tired of my agents hallucinating, so I built a new memory layer called MemVault.
Instead of just dumping text into a database and hoping for the best, I implemented an asynchronous processing pipeline. I call it "Sleep Cycles."
Here is how it works:
Ingestion: You push code or docs. It gets vectorized immediately for fast, "short-term" retrieval.
Consolidation: In the background, a worker process (Redis + BullMQ) wakes up. It reads the new data and extracts entities and relationships.
Graph Construction: It updates a Knowledge Graph (GraphRAG). It links "User Service" to "Database Config" because it sees they interact, even if they are in different folders.
When you query the agent later, it pulls data from both the Vector Index (similarity) and the Knowledge Graph (relationships).
Automating the input (The GitHub Action)
The biggest friction point was actually getting the data into the brain. I didn't want to manually upload markdown files every time I changed the documentation.
So, I built a GitHub Action.
Now, every time I push code to main, the action runs. It diffs the changes and syncs the new code/docs directly to the MemVault API. The "Sleep Cycle" kicks in automatically, and my agent is updated without me touching a thing.
Try it out
I just published the Action on the GitHub Marketplace. It connects to the managed API, but the core stack (Next.js, Postgres/pgvector) is open for inspection if you want to see how the graph logic works.
If you are tired of building goldfish, give it a try.
GitHub Action: https://github.com/marketplace/actions/memvault-sync
Repo / Source: https://github.com/jakops88-hub/Long-Term-Memory-API.git
Let me know what you think about the "Sleep Cycle" approach. Is it overkill, or is this where RAG needs to go?
Top comments (0)