Skip to content

Database Persistence, Vector Engine & Quantum-Resistant Foundation

Context

After establishing the CI/CD pipeline, the focus shifted to building the data foundation. The goal was to implement a schema capable of handling both traditional relational data (votes, documents) and high-dimensional vectors for AI-powered semantic analysis, while ensuring decadal-scale cryptographic integrity.

Actions Taken

  1. Infrastructure as Code (IaC):

    • Deployed a Docker Compose environment featuring PostgreSQL 17 with the pgvector extension and Redis 7 for caching.
    • Implemented a health check mechanism to ensure database availability before application startup.
  2. Persistence Layer (Drizzle ORM):

    • Integrated Drizzle ORM as a lightweight, type-safe alternative to Prisma, optimized for the NestJS/Fastify engine.
    • Configured drizzle-kit for automated schema synchronization and migrations.
  3. Core Schema Materialization & Refactor:

    • legislative_docs: Central storage for law proposals.
    • doc_chunks_embeddings: Dedicated table for RAG (Retrieval-Augmented Generation), featuring a 1536-dimension vector column.
    • votes: High-integrity table. Successfully refactored the hash columns from 64 to 128 characters to support SHA3-512.
  4. Security Implementation (Post-Quantum Readiness):

    • Developed a global SecurityService utilizing Node's native crypto module.
    • Implemented SHA3-512 hashing to mitigate risks from Grover's Algorithm.
    • Implemented a recursive Merkle Tree generator (generateMerkleRoot) to enable efficient, high-integrity auditing of voting blocks.

Technical Resolution: The "Vector" Type Error

During the initial schema push, an error occurred because PostgreSQL did not recognize the vector type.

  • Root Cause: The pgvector extension was present in the Docker image but not activated in the specific database instance.
  • Fix: Manually executed CREATE EXTENSION IF NOT EXISTS vector; and added a persistent initialization script to the Docker configuration.

Status

  • Database Engine: Operational (Docker).
  • Schema: Synced and verified via drizzle-kit push (128-char hash support).
  • Security Logic: SecurityService verified and ready for production-grade hashing.
  • Persistence: Global DbModule fully integrated into the NestJS core.