Grepai Storage Postgres

yoanbernabeu/grepai-skills/skills/storage/grepai-storage-postgres

作者 yoanbernabeu382d40261c0d41109c6e11872574ba0be9b064d0無授權條款收錄於 2026年10月9日更新於 2026年10月9日

Configure PostgreSQL with pgvector for GrepAI. Use this skill for team environments and large codebases.

僅含說明DevOps & Cloud
AI 產生的概覽

設定 PostgreSQL 搭配 pgvector 作為 GrepAI 的儲存後端,涵蓋安裝、調校與疑難排解。

功能
引導代理將搭載 pgvector 擴充功能的 PostgreSQL 設定為 GrepAI 的儲存後端,涵蓋 Docker、既有安裝與託管服務三種方式。文件說明了 DSN 設定、SSL 模式、embeddings 資料表結構、IVFFlat 索引調校、並行存取、團隊共享設定、備份與還原,以及從 GOB 儲存遷移。此外也列出驗證步驟與常見錯誤的排除方法。
適用情境
適用於需要共用 GrepAI 索引的團隊環境、超過一萬個檔案的大型程式碼庫、需要並行搜尋的情境,或與現有 PostgreSQL 基礎架構整合。也適合將 GrepAI 索引從 GOB 儲存遷移至 PostgreSQL 時使用。
執行需求
需要 PostgreSQL 14 以上版本並安裝 pgvector 擴充功能、具備建表權限的資料庫使用者,以及對 PostgreSQL 伺服器的網路存取。本機架設可選用 Docker。此技能未附帶指令碼,僅為說明文件。

GrepAI Storage with PostgreSQL

This skill covers using PostgreSQL with the pgvector extension as the storage backend for GrepAI.

When to Use This Skill

  • Team environments with shared index
  • Large codebases (10K+ files)
  • Need concurrent access
  • Integration with existing PostgreSQL infrastructure

Prerequisites

  1. PostgreSQL 14+ with pgvector extension
  2. Database user with create table permissions
  3. Network access to PostgreSQL server

Advantages

BenefitDescription
👥 Team sharingMultiple users can access same index
📏 ScalableHandles large codebases
🔄 ConcurrentMultiple simultaneous searches
💾 PersistentData survives machine restarts
🔧 FamiliarStandard database tooling

Setting Up PostgreSQL with pgvector

Option 1: Docker (Recommended for Development)

bash
# Run PostgreSQL with pgvectordocker run -d \  --name grepai-postgres \  -e POSTGRES_USER=grepai \  -e POSTGRES_PASSWORD=grepai \  -e POSTGRES_DB=grepai \  -p 5432:5432 \  pgvector/pgvector:pg16

Option 2: Install on Existing PostgreSQL

bash
# Install pgvector extension (Ubuntu/Debian)sudo apt install postgresql-16-pgvector
# Or compile from sourcegit clone https://github.com/pgvector/pgvector.gitcd pgvectormakesudo make install

Then enable the extension:

sql
-- Connect to your databaseCREATE EXTENSION IF NOT EXISTS vector;

Option 3: Managed Services

  • Supabase: pgvector included by default
  • Neon: pgvector available
  • AWS RDS: Install pgvector extension
  • Azure Database: pgvector available

Configuration

Basic Configuration

yaml
# .grepai/config.yamlstore:  backend: postgres  postgres:    dsn: postgres://user:password@localhost:5432/grepai

With Environment Variable

yaml
store:  backend: postgres  postgres:    dsn: ${DATABASE_URL}

Set the environment variable:

bash
export DATABASE_URL="postgres://user:password@localhost:5432/grepai"

Full DSN Options

yaml
store:  backend: postgres  postgres:    dsn: postgres://user:password@host:5432/database?sslmode=require

DSN components:

  • user: Database username
  • password: Database password
  • host: Server hostname or IP
  • 5432: Port (default: 5432)
  • database: Database name
  • sslmode: SSL mode (disable, require, verify-full)

SSL Modes

ModeDescriptionUse Case
disableNo SSLLocal development
requireSSL requiredProduction
verify-fullSSL + verify certificateHigh security
yaml
# Production with SSLstore:  backend: postgres  postgres:    dsn: postgres://user:[email protected]:5432/grepai?sslmode=require

Database Schema

GrepAI automatically creates these tables:

sql
-- Vector embeddings tableCREATE 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 searchCREATE INDEX ON embeddings USING ivfflat (embedding vector_cosine_ops);

Verifying Setup

Check pgvector Extension

sql
-- Connect to databasepsql -U grepai -d grepai
-- Check extension is installedSELECT * FROM pg_extension WHERE extname = 'vector';
-- Check GrepAI tables exist (after first grepai watch)\dt

Test Connection from GrepAI

bash
# Check statusgrepai status
# Should show PostgreSQL backend info

Performance Tuning

PostgreSQL Configuration

For better vector search performance:

sql
-- Increase work memory for vector operationsSET work_mem = '256MB';
-- Adjust for your hardwareSET effective_cache_size = '4GB';SET shared_buffers = '1GB';

Index Tuning

For large indices, tune the IVFFlat index:

sql
-- More lists = faster search, more memoryCREATE INDEX ON embeddingsUSING ivfflat (embedding vector_cosine_ops)WITH (lists = 100);  -- Adjust based on row count

Rule of thumb: lists = sqrt(rows)

Concurrent Access

PostgreSQL handles concurrent access automatically:

  • Multiple grepai search commands work simultaneously
  • One grepai watch daemon per codebase
  • Many users can share the same index

Team Setup

Shared Database

All team members point to the same database:

yaml
# Each developer's .grepai/config.yamlstore:  backend: postgres  postgres:    dsn: postgres://team:[email protected]:5432/grepai

Per-Project Databases

For isolated projects, use separate databases:

bash
# Create databasescreatedb -U postgres grepai_projectacreatedb -U postgres grepai_projectb
yaml
# Project A configstore:  backend: postgres  postgres:    dsn: postgres://user:pass@localhost:5432/grepai_projecta

Backup and Restore

Backup

bash
pg_dump -U grepai -d grepai > grepai_backup.sql

Restore

bash
psql -U grepai -d grepai < grepai_backup.sql

Migrating from GOB

  1. Set up PostgreSQL with pgvector
  2. Update configuration:
yaml
store:  backend: postgres  postgres:    dsn: postgres://user:pass@localhost:5432/grepai
  1. Delete old index:
bash
rm .grepai/index.gob
  1. Re-index:
bash
grepai watch

Common Issues

❌ Problem: FATAL: password authentication failed ✅ Solution: Check DSN credentials and pg_hba.conf

❌ Problem: ERROR: extension "vector" is not available ✅ Solution: Install pgvector:

bash
sudo apt install postgresql-16-pgvector# Then: CREATE EXTENSION vector;

❌ Problem: ERROR: type "vector" does not exist ✅ Solution: Enable extension in the database:

sql
CREATE EXTENSION IF NOT EXISTS vector;

❌ Problem: Connection refused ✅ Solution:

  • Check PostgreSQL is running
  • Verify host and port
  • Check firewall rules

❌ Problem: Slow searches ✅ Solution:

  • Add IVFFlat index
  • Increase work_mem
  • Vacuum and analyze tables

Best Practices

  1. Use environment variables: Don't commit credentials
  2. Enable SSL: For remote databases
  3. Regular backups: pg_dump before major changes
  4. Monitor performance: Check query times
  5. Index maintenance: Regular VACUUM ANALYZE

Output Format

PostgreSQL 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: ~50ms

來源與署名

來源:yoanbernabeu/grepai-skills位於skills/storage/grepai-storage-postgres提交382d402

授權條款: 無授權條款

內容歸原作者所有。SourceWeft 從公開儲存庫中收錄這些內容。

檢舉或申請下架