Memory & RAG
10 min readUpdated: October 2026

Give AI Agents Long-Term Memory: Knowledge Bases, RAG & Vector Search

Technical Review: Smoke Monkey Core Architecture Team
Tested on Node.js 18+ & BunTypeScript 5.x
Quick Answer & Executive Definition

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.

Key Architectural Takeaways

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:

typescript
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:

  1. Chunk: Split source files into semantic chunks (functions, classes, modules) rather than fixed character counts.
  2. Embed: Use the same embedding model for both indexing and retrieval (e.g., text-embedding-3-small).
  3. Metadata: Store file path, function name, last modified date, and author with each chunk.
  4. 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.

Google Search Questions & Answers

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.

npm install smoke-monkey-harness