Environment:24kchengYe MemoMind PostgreSQL pgvector
| Knowledge Sources | |
|---|---|
| Domains | Infrastructure, Database |
| Last Updated | 2026-10-28 14:45 GMT |
Overview
PostgreSQL 17 with the pgvector extension, pg_trgm, and HNSW vector indexes — the primary data store for all MemoMind memory operations.
Description
This environment provides a PostgreSQL database with the pgvector extension for vector similarity search (HNSW indexes), pg_trgm for trigram fuzzy matching used by entity resolution, and native full-text search for BM25 ranking. The production deployment uses the `pgvector/pgvector:pg17` Docker image which bundles the vector extension. MemoMind also supports alternative vector extensions (vchord, pgvectorscale) via `HINDSIGHT_API_VECTOR_EXTENSION`. An embedded PostgreSQL mode (`pg0`) is available for local/development use via the `pg0-embedded` package.
Usage
Use this environment for every MemoMind operation that persists or queries memory — retain (fact storage), recall (hybrid retrieval), reflect (agent retrieval), consolidation, entity resolution, and worker task claiming. It is the mandatory prerequisite for nearly all Implementation pages.
System Requirements
| Category | Requirement | Notes |
|---|---|---|
| OS | Linux (production) / WSL2 / macOS (dev) | Docker recommended for production |
| Hardware | 2+ CPU cores, 4GB+ RAM | HNSW index builds are CPU/memory intensive; 100GB+ disk for large memory banks |
| Disk | SSD recommended | HNSW vector search and BM25 ranking benefit from high IOPS |
| Database | PostgreSQL 17 (production) | pgvector/pgvector:pg17 Docker image; PostgreSQL 13+ minimum for pgvector |
| Vector Extension | pgvector (default) | Alternatives: vchord, pgvectorscale (DiskANN) |
| Text Search | native PostgreSQL (default) | Alternatives: vchord BM25, Timescale pg_textsearch |
Dependencies
System Packages
- `postgresql` = 17 (production) or 13+ (minimum)
- `pgvector` extension (`CREATE EXTENSION vector;`)
- `pg_trgm` extension (`CREATE EXTENSION IF NOT EXISTS pg_trgm;` — ships with contrib)
- `pg0-embedded` (optional, for embedded dev mode: `pip install 'hindsight-api-slim[embedded-db]'`)
Python Packages
- `asyncpg` — async PostgreSQL driver (connection pooling)
- `pgvector` >= 0.3 (Python bindings: `pgvector.sqlalchemy`)
- `sqlalchemy` — ORM models and Alembic migrations
- `alembic` — schema migration management
Credentials
The following environment variables must be set in `.env`:
- `HINDSIGHT_API_DATABASE_URL`: PostgreSQL connection URL (e.g., `postgresql://user:pass@host:5432/db`) or `pg0` for embedded mode
- `HINDSIGHT_API_DATABASE_SCHEMA`: Schema name (default: `public`)
- `PG_PASSWORD`: PostgreSQL password (Docker Compose production)
Optional connection pool tuning:
- `HINDSIGHT_API_DB_POOL_MIN_SIZE` (default: 5)
- `HINDSIGHT_API_DB_POOL_MAX_SIZE` (default: 100)
- `HINDSIGHT_API_DB_COMMAND_TIMEOUT` (default: 60s)
- `HINDSIGHT_API_DB_ACQUIRE_TIMEOUT` (default: 30s)
Quick Install
# Production (Docker) — uses pgvector/pgvector:pg17 image
docker compose up -d # see deploy/server/docker-compose.yml
# Development (embedded PostgreSQL)
pip install 'hindsight-api-slim[embedded-db]'
# External PostgreSQL — install pgvector extension
CREATE EXTENSION vector;
CREATE EXTENSION IF NOT EXISTS pg_trgm;
Code Evidence
Vector extension validation from `migrations.py:45-100`:
def _detect_vector_extension(conn, vector_extension: str = "pgvector") -> str:
"""Validate vector extension: 'pgvector', 'vchord', or 'pgvectorscale'."""
if vector_extension == "pgvector":
pgvector_check = conn.execute(text("SELECT 1 FROM pg_extension WHERE extname = 'vector'")).scalar()
if not pgvector_check:
raise RuntimeError(
"Configured vector extension 'pgvector' not found. "
"Install it with: CREATE EXTENSION vector;"
)
Embedded PostgreSQL import guard from `pg0.py:38-44`:
try:
from pg0 import Pg0
except ImportError:
raise ImportError(
"pg0-embedded is required for embedded PostgreSQL. "
"Install it with: pip install 'hindsight-api-slim[embedded-db]'"
)
Docker Compose PostgreSQL service from `deploy/server/docker-compose.yml:4-21`:
pg:
image: pgvector/pgvector:pg17 # 自带 vector 扩展(hindsight 必需)
environment:
POSTGRES_USER: hindsight
POSTGRES_PASSWORD: ${PG_PASSWORD:?PG_PASSWORD is required}
POSTGRES_DB: hindsight
pg_trgm migration from `alembic/versions/c1a2b3d4e5f6_enable_pg_trgm_and_entities_trgm_index.py:28-30`:
# pg_trgm ships with every standard PostgreSQL installation as a contrib module.
op.execute("CREATE EXTENSION IF NOT EXISTS pg_trgm")
Common Errors
| Error Message | Cause | Solution |
|---|---|---|
| `Configured vector extension 'pgvector' not found` | pgvector extension not installed | Run `CREATE EXTENSION vector;` on the database |
| `Failed to start embedded PostgreSQL after 5 attempts` | pg0-embedded not installed or port conflict | Install `hindsight-api-slim[embedded-db]`; check for port conflicts |
| `Configured vector extension 'pgvectorscale' not found` | pgvectorscale/DiskANN requires pgvector first | `CREATE EXTENSION vector;` then `CREATE EXTENSION vectorscale CASCADE;` |
| `too many connections` | DB pool exhausted | Increase `HINDSIGHT_API_DB_POOL_MAX_SIZE` or reduce `HINDSIGHT_API_RECALL_MAX_CONCURRENT` |
Compatibility Notes
- pgvector: Default and most widely supported. HNSW indexes with `max_neighbors = 50`.
- vchord: Alternative vector extension — `CREATE EXTENSION vchord CASCADE;`
- pgvectorscale (DiskANN): Requires pgvector installed first; available on Azure as `pg_diskann`.
- pg_textsearch: Alternative to native PostgreSQL full-text search for BM25.
- Embedded mode (pg0): Development only; auto-assigns a port. Not suitable for production.
Related Pages
- Implementation:24kchengYe_MemoMind_extract_facts_from_contents
- Implementation:24kchengYe_MemoMind_process_entities_batch
- Implementation:24kchengYe_MemoMind_create_links_batch
- Implementation:24kchengYe_MemoMind_insert_facts_batch
- Implementation:24kchengYe_MemoMind_retrieve_all_fact_types_parallel
- Implementation:24kchengYe_MemoMind_run_reflect_agent
- Implementation:24kchengYe_MemoMind_WorkerPoller_claim_batch
- Implementation:24kchengYe_MemoMind_run_consolidation_job
- Implementation:24kchengYe_MemoMind_register_mcp_tools
- Implementation:24kchengYe_MemoMind_create_mcp_server
- Implementation:24kchengYe_MemoMind_ApiKeyTenantExtension_authenticate
- Implementation:24kchengYe_MemoMind_SupabaseTenantExtension_authenticate
- Implementation:24kchengYe_MemoMind_MultiApiKeyTenantExtension_authenticate
- Implementation:24kchengYe_MemoMind_serve_py
- Implementation:24kchengYe_MemoMind_dashboard_server