AgentForge

PgVector Memory Store

Production memory store using PostgreSQL with pgvector for semantic search.

Setup

# Start PostgreSQL with pgvector
docker run -d -p 5432:5432 -e POSTGRES_PASSWORD=postgres pgvector/pgvector:pg16

Usage

import { createPgVectorStore } from '@ahzan-agentforge/core';

const store = await createPgVectorStore({
  connectionString: 'postgresql://postgres:postgres@localhost:5432/agentforge',
});

The store automatically creates the required tables and pgvector extension.

With an Agent

const agent = defineAgent({
  name: 'agent-with-memory',
  description: 'Agent with persistent memory',
  tools: [myTool],
  llm,
  systemPrompt: '...',
  memory: {
    store,
    config: {
      autoCapture: true,
      retrieveBeforeStep: true,
      maxRetrieved: 5,
    },
  },
});

PgVector enables semantic similarity search. When the agent recalls memories, it finds conceptually related content — not just keyword matches:

// Stored: "Customer John prefers phone calls over email"
// Query: "How does John like to be contacted?"
// → Retrieves the stored memory (semantic match)

Embedding Model

Configure the embedding model used for vectorization:

import { createEmbeddingModel } from '@ahzan-agentforge/core';

const embedding = createEmbeddingModel({
  provider: 'openai',
  model: 'text-embedding-3-small',
  dimensions: 1536,
});

Next Steps