DEV Community

Om Ghorpade
Om Ghorpade

Posted on

How We Used Hindsight Memory to Build an AI That Knows Your Weaknesses

How We Used Hindsight Memory to Build an AI That Knows Your Weaknesses

Most AI tools have a goldfish memory.
You interact with them, get a response, close the tab — and they forget everything. The next time you come back, you are a complete stranger. This is fine for a chatbot. It is a disaster for a learning tool.
When our team decided to build TraceX — an AI coding mentor — the first question we asked was not "which LLM should we use?" It was "how do we make this thing remember?"
The answer was Hindsight.

Why Memory Changes Everything for Learning Tools
Think about how human mentors work. A great tutor does not just answer your question. They remember that last week you struggled with recursion. They notice that you keep forgetting null checks. They connect the dots across multiple sessions and give you feedback that actually helps you grow.
AI tools cannot do this — not because the LLMs are not smart enough, but because they have no persistent memory layer between sessions.
Hindsight solves this. It is a purpose-built memory system for AI agents that supports semantic search, temporal reasoning, and automatic knowledge consolidation.

Building the Memory Layer
My job on the team was the backend — specifically the Hindsight integration and API routes.
The first thing I built was a simple wrapper around the two core Hindsight calls:
javascriptimport { HindsightClient } from '@vectorize-io/hindsight-client';

const client = new HindsightClient({
baseUrl: process.env.HINDSIGHT_URL,
apiKey: process.env.HINDSIGHT_API_KEY,
});

export async function storeMemory(content) {
await client.retain('TraceX', content);
}

export async function fetchMemory(query) {
const response = await client.recall('TraceX', query);
return response.results.map(r => r.text);
}
Simple. Clean. Two functions. But these two functions are what make the entire product work.

The API Route That Powers Everything
The /api/analyze route is the heart of TraceX. Here is exactly what happens when a student submits code:
Step 1 — Recall past mistakes
javascriptconst pastMistakes = await fetchMemory(
What mistakes has this student made in ${topic}?
);
Step 2 — Send to Groq with memory context
javascriptconst memoryContext = pastMistakes?.length
? HINDSIGHT MEMORY:\n${pastMistakes.join('\n')}\n\n
: '';
// Groq now knows the student's full history
Step 3 — Store the new mistake
javascriptawait storeMemory(
Student submitted ${language} code for ${topic}. Error: ${errorType}.
);
Step 4 — Return structured response
javascriptreturn NextResponse.json({
analysis,
betterApproach,
correctedCode,
hindsightWarning,
pastMistakes,
memoryStored,
});
The order matters. Recall first, then analyze, then store. This ensures every response is informed by history before the new memory is added.

What Hindsight Does Behind the Scenes
What impressed me most about Hindsight is how it handles retrieval. It does not just do simple keyword matching. It uses four parallel search strategies — semantic search, keyword matching, graph traversal, and temporal reasoning.
This means when TraceX asks "What mistakes has this student made in binary search?" — Hindsight does not just look for the exact phrase. It understands the semantic meaning, connects related concepts, and returns the most relevant memories even if the wording is different.
For a learning tool, this is exactly what you need.

The Result
The difference between a first session and a fifth session on TraceX is dramatic.
First session: "Your binary search has an off-by-one error. Fix the boundary condition."
Fifth session: "You have made this exact boundary error in binary search 4 times. Your loop condition keeps using left < right instead of left <= right. This specific pattern needs your focused attention."
Same code. Completely different feedback. Because now TraceX knows you.

Try the Memory Layer Yourself
The entire backend is open source. You can see exactly how retain() and recall() are implemented in the codebase.

GitHub: https://github.com/Anupam-codes7/TraceX
Hindsight SDK: https://github.com/vectorize-io/hindsight
Hindsight Docs: https://hindsight.vectorize.io/
Agent Memory: https://vectorize.io/features/agent-memory

If you are building any AI product that needs to remember users across sessions — Hindsight is the cleanest solution I have found.

Top comments (0)