How to Configure PGVector as the Vector Store Backend in Dat

Set vectorStore.type to pgvector and supply the required PostgreSQL connection parameters (host, port, user, password, database, and dimension) in your Dat project configuration to activate PostgreSQL with PGVector as the embedding store.

Dat uses a factory-based plug-in system to load vector-store implementations, and the PGVector backend is provided by ai.dat.storer.pgvector.PGVectorEmbeddingStoreFactory. This guide walks through the configuration options defined in the source code and provides ready-to-use YAML examples for your Dat projects.

Identify the PGVector Factory

Every vector store in Dat is referenced by a factory identifier. For PGVector, this identifier is defined as a constant in PGVectorEmbeddingStoreFactory.java (source):

public static final String IDENTIFIER = "pgvector";

When creating or editing a Dat project, set vectorStore.type to pgvector in your configuration file. The factory is automatically discovered at runtime via the Java Service Loader file located at dat-storers/dat-storer-pgvector/src/main/resources/META-INF/services/ai.dat.core.factories.EmbeddingStoreFactory, which registers the fully-qualified class name. No additional code changes are required to activate the backend.

Required Configuration Parameters

The requiredOptions() method (line 99) in PGVectorEmbeddingStoreFactory.java declares six mandatory fields that must be provided in your configuration:

  • host (String): PostgreSQL server hostname. Defaults to localhost if not specified.
  • port (int): PostgreSQL port. Defaults to 5432.
  • user (String): Database username for authentication.
  • password (String): Database password for authentication.
  • database (String): Name of the PostgreSQL database to connect to.
  • dimension (int): Dimensionality of the embedding vectors. This must match the output dimension of your chosen embedding model.

These parameters are validated at initialization via FactoryUtil.validateFactoryOptions(this, config) (line 116) before the store is instantiated.

Optional Performance Tuning

The optionalOptions() method (line 104) exposes three additional fields for optimizing table naming and search performance:

  • table-prefix (String): Prefix for the embedding table name. Default is dat_embeddings. The final table name is computed as {prefix}_{storeId}_{contentType}.
  • use-index (boolean): Enables an IVFFlat index for faster approximate nearest neighbor (ANN) search. Default is false.
  • index-list-size (int): Number of list partitions for the IVFFlat index. Required only when use-index is set to true.

Complete Configuration Examples

Minimal Configuration

Provide only the required fields to connect to a standard PostgreSQL instance:

vectorStore:
  type: pgvector
  host: pg.example.com
  port: 5432
  user: dat_user
  password: ${DAT_DB_PASSWORD}
  database: dat
  dimension: 384

Production Setup with Indexing

Enable IVFFlat indexing for faster vector lookups on large datasets:

vectorStore:
  type: pgvector
  host: pg.example.com
  user: dat_user
  password: ${DAT_DB_PASSWORD}
  database: dat
  dimension: 384
  use-index: true
  index-list-size: 20

Custom Table Naming

Override the default table prefix to organize embeddings by project:

vectorStore:
  type: pgvector
  host: localhost
  user: dat_user
  password: secret
  database: dat
  dimension: 768
  table-prefix: custom_prefix

How the Factory Builds the Store

During runtime, PGVectorEmbeddingStoreFactory constructs the store using the LangChain4j PgVectorEmbeddingStore builder (lines 32-50). The factory maps your configuration to the following builder calls:

PgVectorEmbeddingStore.builder()
    .host(host)
    .port(port)
    .database(database)
    .user(user)
    .password(password)
    .table(tableName)      // Computed from prefix, storeId, and content type
    .dimension(dimension)
    .createTable(true)     // Auto-create table if missing
    .useIndex(useIndex)
    .indexListSize(indexListSize)  // Only if use-index is true
    .build();

The createTable(true) setting ensures that the embedding table is automatically created on startup if it does not exist, simplifying deployment workflows.

Summary

  • Set vectorStore.type to pgvector to activate the PGVector backend in Dat projects.
  • Provide six required parameters: host, port, user, password, database, and dimension.
  • Optionally enable use-index and index-list-size for faster ANN search on large vector collections.
  • The factory auto-registers via Java Service Loader and validates configuration through FactoryUtil.validateFactoryOptions().
  • Tables are auto-created with configurable prefixes using the PgVectorEmbeddingStore builder pattern.

Frequently Asked Questions

What is the correct value for the vectorStore type field?

Set vectorStore.type to the string literal pgvector. This identifier is defined as the constant IDENTIFIER in PGVectorEmbeddingStoreFactory.java and is used by Dat's factory loader to instantiate the correct backend implementation.

Does the PGVector backend support automatic table creation?

Yes. The factory invokes createTable(true) on the PgVectorEmbeddingStore builder during initialization, which automatically creates the necessary database table if it does not already exist. You can customize the table name using the table-prefix option.

Which embedding models work with the PGVector configuration?

Any embedding model is compatible as long as the dimension parameter matches the model's output vector size. For example, use dimension: 384 for all-MiniLM-L6-v2 or dimension: 768 for many BERT-based models. Mismatched dimensions will cause runtime errors during vector insertion.

Set use-index: true and provide an index-list-size value (typically 10-100 depending on dataset size) in your configuration. This creates an IVFFlat index on the vector column, significantly speeding up approximate nearest neighbor queries at the cost of slight recall reduction and additional build time.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →