This skill helps teams configure PostgreSQL with pgvector for GrepAI, enabling scalable, concurrent, and persistent semantic code search across large codebases.
npx playbooks add skill yoanbernabeu/grepai-skills --skill grepai-storage-postgres
This skill covers using PostgreSQL with the pgvector extension as the storage backend for GrepAI.
| Benefit | Description |
|---------|-------------|
| 👥 Team sharing | Multiple users can access same index |
| 📏 Scalable | Handles large codebases |
| 🔄 Concurrent | Multiple simultaneous searches |
| 💾 Persistent | Data survives machine restarts |
| 🔧 Familiar | Standard database tooling |
# Run PostgreSQL with pgvector
docker run -d \
--name grepai-postgres \
-e POSTGRES_USER=grepai \
-e POSTGRES_PASSWORD=grepai \
-e POSTGRES_DB=grepai \
-p 5432:5432 \
pgvector/pgvector:pg16
# Install pgvector extension (Ubuntu/Debian)
sudo apt install postgresql-16-pgvector
# Or compile from source
git clone https://github.com/pgvector/pgvector.git
cd pgvector
make
sudo make install
Then enable the extension:
-- Connect to your database
CREATE EXTENSION IF NOT EXISTS vector;
# .grepai/config.yaml
store:
backend: postgres
postgres:
dsn: postgres://user:password@localhost:5432/grepai
grepai does not substitute ${VAR} in config.yaml: dsn: ${DATABASE_URL} is used literally and fails. The DSN is passed to the pgx driver, which reads the standard libpq variables for anything the DSN leaves out, so you can drop the password from the config:
store:
backend: postgres
postgres:
dsn: postgres://user@localhost:5432/grepai
export PGPASSWORD="password"
store:
backend: postgres
postgres:
dsn: postgres://user:password@host:5432/database?sslmode=require
DSN components:
user: Database usernamepassword: Database passwordhost: Server hostname or IP5432: Port (default: 5432)database: Database namesslmode: SSL mode (disable, require, verify-full)| Mode | Description | Use Case |
|------|-------------|----------|
| disable | No SSL | Local development |
| require | SSL required | Production |
| verify-full | SSL + verify certificate | High security |
# Production with SSL
store:
backend: postgres
postgres:
dsn: postgres://user:pass@prod.db.com:5432/grepai?sslmode=require
GrepAI automatically creates these tables:
-- Vector embeddings table
CREATE TABLE IF NOT EXISTS embeddings (
id SERIAL PRIMARY KEY,
file_path TEXT NOT NULL,
chunk_index INTEGER NOT NULL,
content TEXT NOT NULL,
start_line INTEGER,
end_line INTEGER,
embedding vector(768), -- Dimension matches your model
created_at TIMESTAMP DEFAULT NOW(),
UNIQUE(file_path, chunk_index)
);
-- Index for vector similarity search
CREATE INDEX ON embeddings USING ivfflat (embedding vector_cosine_ops);
-- Connect to database
psql -U grepai -d grepai
-- Check extension is installed
SELECT * FROM pg_extension WHERE extname = 'vector';
-- Check GrepAI tables exist (after first grepai watch)
\dt
# Check status
grepai status
# Should show PostgreSQL backend info
For better vector search performance:
-- Increase work memory for vector operations
SET work_mem = '256MB';
-- Adjust for your hardware
SET effective_cache_size = '4GB';
SET shared_buffers = '1GB';
For large indices, tune the IVFFlat index:
-- More lists = faster search, more memory
CREATE INDEX ON embeddings
USING ivfflat (embedding vector_cosine_ops)
WITH (lists = 100); -- Adjust based on row count
Rule of thumb: lists = sqrt(rows)
PostgreSQL handles concurrent access automatically:
grepai search commands work simultaneouslygrepai watch daemon per codebaseAll team members point to the same database:
# Each developer's .grepai/config.yaml
store:
backend: postgres
postgres:
dsn: postgres://team:secret@shared-db.company.com:5432/grepai
For isolated projects, use separate databases:
# Create databases
createdb -U postgres grepai_projecta
createdb -U postgres grepai_projectb
# Project A config
store:
backend: postgres
postgres:
dsn: postgres://user:pass@localhost:5432/grepai_projecta
pg_dump -U grepai -d grepai > grepai_backup.sql
psql -U grepai -d grepai < grepai_backup.sql
store:
backend: postgres
postgres:
dsn: postgres://user:pass@localhost:5432/grepai
rm .grepai/index.gob
grepai watch
❌ Problem: FATAL: password authentication failed
✅ Solution: Check DSN credentials and pg_hba.conf
❌ Problem: ERROR: extension "vector" is not available
✅ Solution: Install pgvector:
sudo apt install postgresql-16-pgvector
# Then: CREATE EXTENSION vector;
❌ Problem: ERROR: type "vector" does not exist
✅ Solution: Enable extension in the database:
CREATE EXTENSION IF NOT EXISTS vector;
❌ Problem: Connection refused
✅ Solution:
❌ Problem: Slow searches
✅ Solution:
work_memPostgreSQL storage status:
✅ PostgreSQL Storage Configured
Backend: PostgreSQL + pgvector
Host: localhost:5432
Database: grepai
SSL: disabled
Contents:
- Files: 2,450
- Chunks: 12,340
- Vector dimension: 768
Performance:
- Connection: OK
- IVFFlat index: Yes
- Search latency: ~50msWeekly roundup of top Claude Code skills, MCP servers, and AI coding tips.