Giving AI Persistent Memory: Building a Code Reviewer that Actually Learns
If you’ve used an AI coding assistant, you already know the most frustrating part: the amnesia.
AI models are incredibly smart, but they start with a blank slate every single session. If your company requires snake_case variables, specific logging frameworks, or strict SQL procedures, you have to paste those rules into the prompt every single time.
For the Vectorize Hindsight Hackathon, I set out to fix this. I built the MNC Code Review Agent—an AI reviewer that learns your team's internal coding rules once and remembers them forever.
Here is a breakdown of how I built it, and how you can use persistent AI memory in your own apps.
🛠️ The Tech Stack
To make this work in real-time with zero lag, I used three core technologies:
Vectorize Hindsight API: The brain of the operation. This provides seamless, long-term persistent memory for the AI.
Groq (gpt-oss-120b): The reasoning engine. Groq provides lightning-fast inference, which is crucial when doing live code analysis.
Streamlit: For a rapid, interactive, and beautiful frontend UI.
🧠 How it Works: The Magic of Hindsight
The core concept of the app is split into two phases: Teaching and Reviewing.
- Teaching the Agent (Writing to Memory) At the bottom of the dashboard, there is a "Teach the Agent" box. If your Tech Lead decides that all database calls must use a specific safe wrapper, you simply type that rule in and hit save.
Behind the scenes, we use the Hindsight Python SDK to permanently retain this knowledge:
python
from hindsight_client import Hindsight
Initialize the client
h_client = Hindsight(
base_url="https://api.hindsight.vectorize.io",
api_key="YOUR_HINDSIGHT_API_KEY"
)
BANK_ID = "company-coding-rules"
def save_to_hindsight(new_rule):
# Retain this new rule in Hindsight permanently
h_client.retain(bank_id=BANK_ID, content=new_rule)
With just one line of code (h_client.retain), that rule is vectorized and securely stored in the cloud.
- The Code Review (Recalling from Memory) When a developer submits code for review, the app doesn't just blindly send it to the LLM. First, it asks Hindsight to recall any company rules that are semantically relevant to the code being evaluated.
python
def fetch_hindsight_memory(code_context):
# Search the memory bank for relevant rules
response = h_client.recall(bank_id=BANK_ID, query=code_context)
# Format the rules to feed to our LLM
rules = "\n".join([f"- {res.text}" for res in response.results])
return rules
We take those recalled rules and inject them directly into the system prompt for Groq. The AI now evaluates the code specifically against your company's unique guidelines.
✨ Features That Make It Pop
To make the app feel like a real enterprise tool (and a bit of fun), I added a few extra features to the UI:
🎭 AI Personas: You can choose the "vibe" of your reviewer. Pick "Strict Senior Engineer" for professional feedback, or "Roast Master" if you want the AI to brutally roast your camelCase variables.
📊 Quality Metrics: The LLM returns a structured JSON object, allowing us to display live scores out of 100 for Security, Performance, and Readability.
🔍 Diff Comparison: When the AI catches a mistake, it doesn't just complain—it writes the fixed code. Using Streamlit tabs, you can view a Git-style Diff to see exactly which lines were changed to comply with the Hindsight memory rules.
🚀 Try it yourself!
Building with Vectorize Hindsight completely changed how I think about LLM context windows. We no longer have to stuff massive prompt templates with company rules; we can just query the exact rules we need, exactly when we need them.
You can check out the full source code for the MNC Code Review Agent on my GitHub here:https://github.com/kolipakaabhichandra991-png/mnc-code-review-agent


Top comments (0)