Give AI Agents Long-Term Memory: Knowledge Bases, RAG & Vector Search
Give AI Agents Long-Term Memory: Knowledge Bases, RAG & Vector Search: Designed as a zero-dependency, open-source TypeScript architecture under the MIT License with native Model Context Protocol (MCP) support and deterministic phase state machines.
- Persist architectural decisions and codebase patterns across sessions
- RAG-powered semantic search over large codebases without full context load
- Agent can recall past debugging sessions and applied fixes
- Knowledge base grows as the agent learns from each session
Building a RAG Tool for Codebase Knowledge
Create a custom search_knowledge_base tool that queries a vector database. The agent calls this tool when it needs context about architectural decisions, design patterns, or historical changes:
import { ChromaClient } from 'chromadb';
const chromaClient = new ChromaClient();
const collection = await chromaClient.getCollection({ name: 'codebase-knowledge' });
const knowledgeBaseTool = {
name: 'search_knowledge_base',
description: 'Search the codebase knowledge base for architectural patterns, past decisions, and documented conventions.',
parameters: {
type: 'object',
properties: {
query: { type: 'string', description: 'Natural language search query' },
topK: { type: 'number', default: 5 },
},
required: ['query'],
},
execute: async ({ query, topK }) => {
const results = await collection.query({ queryTexts: [query], nResults: topK });
return results.documents[0].map((doc, i) => ({
content: doc,
metadata: results.metadatas[0][i],
relevance: 1 - results.distances[0][i],
}));
},
};Building the Indexing Pipeline
Index your codebase into the vector database with chunked embeddings:
- Chunk: Split source files into semantic chunks (functions, classes, modules) rather than fixed character counts.
- Embed: Use the same embedding model for both indexing and retrieval (e.g.,
text-embedding-3-small). - Metadata: Store file path, function name, last modified date, and author with each chunk.
- Update: Re-index changed files on every commit using a post-commit git hook or CI step.
Use AST chunking for better retrieval accuracy
Chunking by AST node boundaries (functions, classes) instead of character count produces semantically coherent chunks that retrieve more relevant context.
Frequently Asked Questions
Q:Which vector database works best with Smoke Monkey?
For local development, ChromaDB is zero-configuration and runs in-memory or as a local server. For production, Pinecone, Weaviate, or pgvector (on PostgreSQL) are popular choices.
Q:How do I keep the vector database in sync with codebase changes?
Set up a git post-commit hook or GitHub Actions workflow that runs an incremental indexer — re-embedding only files that changed in the commit.
Related Alternatives & Comparisons
Build with Smoke Monkey Harness
Zero dependencies. 24 built-in tools. Human-in-the-loop safety. 100% open source under the MIT License.