AbsoluteJS

@absolutejs/rag-postgres

@absolutejs/rag-postgresv0.1.0betaAI

PostgreSQL (pgvector) vector-store adapter for @absolutejs/rag

#Installation

BASH
bun add @absolutejs/rag-postgres

#Capabilities

Overview

PostgreSQL storage for AbsoluteJS RAG with pgvector similarity, native full-text retrieval, metadata filtering and reusable plugin integration.

The driver is Bun.SQL; no separate PostgreSQL client package is required. Use your model provider to generate embeddings with the configured dimensions.

Lexical retrieval

Native mode is the default. First use creates a GIN expression index over title, text, source and JSON metadata string values. Existing tables are indexed too; index creation can take time and block writes on a populated table, so initialize it during a planned migration window. Updates and deletions maintain the index through PostgreSQL.

Queries use PostgreSQL's simple configuration, match any query lexeme, rank with weighted ts_rank_cd, and break ties by chunk ID. They are parameterized; query punctuation is treated as text. Title, body, source and metadata receive successively lower weights. Only the requested top K rows cross into the app. Tenant and other supported metadata predicates run before ranking/limiting. Unsupported filters are rejected rather than partially applied. Native top K must be an integer between 0 and 10,000.

lexicalMode: 'portable' retains the existing RAG lexical scorer and its richer field-specific ranking. It loads filtered candidates into application memory. The engines have different tokenization and scores; native mode is not a claim of identical relevance ordering. Compare your corpus before relying on score thresholds. Vector retrieval remains unchanged.

Measured retrieval

The reproducible benchmark uses a deterministic local PostgreSQL 15 corpus at 1K, 10K and 100K rows, one selective query with tenant filtering, one warmup and ten trials. It verifies expected matches and retains EXPLAIN ANALYZE plans in the results. At 100K rows, native median/p95 were 2.08/2.79 ms versus 683.03/752.49 ms for portable scoring. Native transferred 10 rows; portable transferred 50,000. These are local warm-query measurements, excluding ingestion/index construction, provider calls and network deployment effects. The 1K fixture has no matching row in the selected tenant. This is not an Exa comparison or a web-scale benchmark.

Run these from the repository root against an isolated test database. Fixture schemas are removed after execution. CI runs real PostgreSQL integration tests.

Outcomes

What you can build

Build on the supported package contract

Use @absolutejs/rag-postgres through its supported public entry points.

Hardening checklist

Production guidance

Make every external boundary explicitPin the deployed @absolutejs/rag-postgres version, replace example or memory-backed dependencies with durable implementations, bound external calls, protect credentials, and emit enough evidence to retry or recover safely.

Follow in order

Troubleshooting path

1
Trace from the first failed boundary
Reproduce the smallest canonical @absolutejs/rag-postgres example, confirm the supported entry point and version in the API explorer, then inspect the first boundary that did not produce its documented result.

#@absolutejs/rag-postgres quick start

Partial snippet

# @absolutejs/rag-postgres

BASH
bun add @absolutejs/rag @absolutejs/rag-postgres

#@absolutejs/rag-postgres quick start 2

Partial snippet

# @absolutejs/rag-postgres

TS
import { Elysia } from 'elysia';
import { createPostgresRAG } from '@absolutejs/rag-postgres';
import { ragPlugin } from '@absolutejs/rag';

const rag = createPostgresRAG({
  storeOptions: {
    connectionString: process.env.DATABASE_URL,
    dimensions: 1536,
    indexType: 'hnsw',
    lexicalMode: 'native',
  },
});
const app = new Elysia().use(ragPlugin({ path: '/rag', collection: rag.collection }));

#Measured retrieval

Partial snippet

The reproducible benchmark uses a deterministic local PostgreSQL 15 corpus at 1K, 10K and 100K rows, one selective query with tenant filtering, one warmup and ten trials. It verifies expected matches and retains EXPLAIN ANALYZE plans in the results. At 100K rows, native median/p95 were 2.08/2.79 ms versus 683.03/752.49 ms for portable scoring. Native transferred 10 rows; portable transferred 50,000. These are local warm-query measurements, excluding ingestion/index construction, provider calls and network deployment effects. The 1K fixture has no matching row in the selected tenant. This is not an Exa comparison or a web-scale benchmark.

BASH
RAG_LEXICAL_TEST_URL=postgres://... bun postgres/benchmarks/lexical.ts
RAG_LEXICAL_TEST_URL=postgres://... bun test postgres/tests

#Public entry points

Supported entry points declared by this package manifest.

Package entry point declared in package.json.

@absolutejs/rag-postgres@absolutejs/rag-postgres/manifest@absolutejs/rag-postgres/manifest.json

#Package commands

Scripts declared by this package manifest.

bun run buildrm -rf dist && bun build src/index.ts src/manifest.ts --outdir dist --sourcemap --target=bun --external @absolutejs/rag --external @absolutejs/rag/adapter-kit --external @absolutejs/ai && tsc --project tsconfig.build.json && absolute-manifest emit
bun run formatprettier --write "./**/*.{ts,json,md}"
bun run testbun test
bun run typechecktsc --noEmit

#API reference

Search the declarations exported by the current package type files. Expand a symbol to inspect its source-backed signature.

15 symbols
ABSOLUTE_POSTGRESQL_RAG_PACKAGE_NAMEvaluePermalink
TS
const ABSOLUTE_POSTGRESQL_RAG_PACKAGE_NAME = "@absolutejs/rag-postgres";
Exported from @absolutejs/rag-postgres