PostgreSQL + pgvector

Configure PostgreSQL with pgvector extension for vector storage and semantic search.

Requirements

  • PostgreSQL 14+
  • pgvector extension

Installation

Install pgvector

bash
# Ubuntu/Debian
sudo apt install postgresql-16-pgvector

# macOS with Homebrew
brew install pgvector

Enable Extension

sql
CREATE EXTENSION vector;

Configuration

.envbash
DATABASE_URL=postgresql://user:password@localhost:5432/cognitivex

Schema

sql
CREATE TABLE memories (
  id UUID PRIMARY KEY,
  content TEXT NOT NULL,
  embedding vector(1536),
  tags TEXT[],
  metadata JSONB,
  created_at TIMESTAMP DEFAULT NOW()
);

CREATE INDEX ON memories USING ivfflat (embedding vector_cosine_ops);

Performance Tips

  • • Use IVFFlat index for large datasets (>100K vectors)
  • • Set appropriate lists parameter (rows/1000)
  • • Increase shared_buffers for better performance
  • • Regular VACUUM ANALYZE for index health