Architecture decision
ADR-004: PostgreSQL with pgvector
Keep portfolio metadata and future vector retrieval in one transactional database.
Context
Ask Habib stores its public source content in Git. Indexed retrieval needs a derived, queryable index with stable document identities, ordered chunks, and a record of which content revision produced that index. Phase 5 now provides lexical search; semantic retrieval and chat remain later stages.
Decision
Use PostgreSQL with the pgvector extension. Phase 4 introduces the database, document and chunk tables, and index state. It deliberately adds no embedding columns or vector index. The extension can be installed and its Go type adapter tested before choosing an embedding model or dimension.
The foundation is deployed in production, with migrations, restricted roles, database readiness, and an encrypted off-host restore verified. Phase 5 adds English/simple full-text search with its own restricted indexer role. API access remains read-only. Embeddings and generated answers remain later stages.
PostgreSQL constraints enforce canonical slug uniqueness, chunk order uniqueness, document foreign keys, and one index state. Migrations use explicit SQL. A separate migration role owns schema changes; the runtime API initially has only read access to the three content tables. The administrator role is reserved for initial database and extension setup.
Alternatives considered
A dedicated vector database would introduce another service, backup procedure, and consistency boundary before this portfolio has a vector workload. A separate search engine would have similar costs. Neither is necessary for the initial relational foundation.
Keeping everything in memory or reading Markdown on each request avoids a database but leaves future indexed retrieval, concurrency, and persistent index state to application code.
Consequences
One database can support relational filters and future vector retrieval together. That does not establish that a particular approximate vector index will meet a latency or recall target. Those choices need measurements with real content.
The database is a new operational dependency. It stays on an internal network without a host port, uses separate credentials, and needs encrypted off-VPS copies and restore drills. Static portfolio pages and liveness remain available during a database outage; readiness reports the unavailable dependency.
Application rollback preserves the database. Schema changes must remain compatible with the previous application, and destructive contraction needs its own plan. Revisit a separate retrieval service when measured scale or isolation needs justify the extra operational boundary.
References: pgvector, Go type registration.