USMAN’S INSIGHTS
AI ARCHITECT
⌘F
HomeAll Bookspgvector Book
Homepgvector BookPostgreSQL and pgvector Essentials
PreviousSQL Essentials for AI EngineersNext pgvector Data Types: vector, halfvec, bit, and sparsevec
AI NOTICE: This is the table of contents for the SPECIFIC CHAPTER only. It is NOT the global sidebar. For all chapters, look at the main navigation.

On this page

10 sections

Progress0%
1 / 10

Muhammad Usman Akbar Entity Profile

Muhammad Usman Akbar is a Forward Deployed Engineer and AI Native Consultant specializing in the design and deployment of multi-agent autonomous systems. Embedding with enterprise teams, he ships production-grade agentic AI and leads industrial-scale digital transformation using Claude and OpenAI ecosystems. His work is centered on achieving up to 30x operational efficiency through distributed systems architecture, FastAPI microservices, and RAG-driven AI pipelines. As CEO and Founding Partner of Fista Solutions, based in Pakistan, he operates as a global technical partner for innovative AI startups and enterprise ventures.

USMAN’S INSIGHTS
AI ARCHITECT

Transforming businesses into autonomous AI ecosystems. Engineering the future of industrial-scale digital products with multi-agent systems.

30X Growth
AI-First
Innovation

Navigation

  • Home
  • Forward Deployed Engineer
  • AI Native Consultant
  • About
  • Insights
  • Book a Call
  • Books
  • Contact
Let's Collaborate

Have a Project in Mind?

Let's build something extraordinary together. Transform your vision into autonomous AI reality.

Start Your Transformation

© 2026 Muhammad Usman Akbar. All rights reserved.

Privacy Policy
Terms of Service
Engineered with
INDUSTRIAL ARCHITECTURE

Schema Design for Documents, Chunks, Metadata, and Embeddings

A durable retrieval schema separates source identity, document versions, addressable chunks, permissions, and model-specific embeddings. This prevents one content update from destroying provenance, supports multiple embedding versions during migration, and makes deletion auditable. Put frequently filtered fields in typed columns; reserve JSON for truly variable metadata rather than hiding every business rule.

What will you be able to do?

  • Model the source-to-chunk hierarchy.
  • Choose typed columns versus jsonb.
  • Store multiple model versions safely.
  • Preserve citation coordinates and content checksums.
  • Define deletion ownership explicitly.

What are the core entities?

Rendering diagram...

Sources represent external identity. Documents represent versioned normalized content. Chunks are stable citation and retrieval units. Embeddings are derived representations that can coexist by model.

sql
CREATE TABLE app.documents ( id uuid PRIMARY KEY, tenant_id uuid NOT NULL, source_key text NOT NULL, version integer NOT NULL CHECK (version > 0), title text NOT NULL, language_code text NOT NULL, content_checksum text NOT NULL, source_modified_at timestamptz, published_at timestamptz, deleted_at timestamptz, metadata jsonb NOT NULL DEFAULT '{}'::jsonb, UNIQUE (tenant_id, source_key, version) ); CREATE TABLE app.chunks ( id uuid PRIMARY KEY, document_id uuid NOT NULL REFERENCES app.documents(id) ON DELETE CASCADE, ordinal integer NOT NULL CHECK (ordinal >= 0), heading_path text[] NOT NULL DEFAULT '{}', content text NOT NULL CHECK (length(content) > 0), token_count integer CHECK (token_count >= 0), char_start integer, char_end integer, chunk_checksum text NOT NULL, UNIQUE (document_id, ordinal), CHECK (char_start IS NULL OR char_end >= char_start) );

Embeddings belong in a separate table when you need multiple models or asynchronous lifecycle. A single vector column on chunks is simpler for one stable model; make the tradeoff deliberately.

Which metadata deserves a column?

Use columns for tenant, state, language, dates, model ID, sensitivity, and other frequent filters or constraints. Use jsonb for provider-specific attributes that vary and are not core authorization. If a JSON key becomes a common predicate, promote it or create a carefully justified expression index.

How do citations remain stable?

Store source URI/key, document version, heading path, page or character range, and chunk checksum. A citation should resolve to the exact authorized version that supported the answer. Never cite a URL alone if its content can change silently.

How do you verify it?

Create a fixture with one source, two document versions, several chunks, and two embedding models. Prove both model versions can coexist. Delete only the second document inside a transaction and inspect cascades before rolling back. Use \d+ to review constraints and storage.

What breaks in production?

  • One giant table duplicates titles and permissions on every chunk.
  • Mutable URLs are treated as version identity.
  • Every attribute lives in unvalidated JSON.
  • Cascade direction does not match data ownership.
  • Chunk IDs change on every re-run, invalidating labels and citations.

AI pair-work prompt

Normalize this proposed retrieval schema [paste] into sources, document versions, chunks, permissions, model registry, and embeddings. State lifecycle ownership and cascade behavior. Preserve stable citation coordinates. Use typed columns for frequent filters and explain each remaining JSON field.

Verification contract: Load a two-version fixture and test update, re-embedding, access revocation, and deletion without losing the ability to audit the prior state.

Check your understanding

  1. Why separate document versions from sources?
  2. Which fields should not be hidden inside JSON?
  3. When is a separate embedding table better than one vector column?

Official references

  • PostgreSQL table constraints
  • PostgreSQL JSON types
  • PostgreSQL arrays