Skip to main content

PostgreSQL adapter for Astrocyte (vector + document + wiki stores backed by pgvector and tsvector)

Project description

astrocyte-postgres

PostgreSQL + pgvector implementation of the Astrocyte VectorStore and WikiStore SPIs (provider-spi.md).

Install

From the monorepo (with astrocyte available):

cd adapters-storage-py/astrocyte-postgres
uv sync
# or: pip install -e ../../astrocyte-py && pip install -e .

Entry point names:

  • postgres (group astrocyte.vector_stores) for raw/compiled memory vectors.
  • postgres (group astrocyte.document_stores) for BM25 keyword retrieval over the same table.
  • postgres (group astrocyte.wiki_stores) for durable wiki pages/revisions/provenance.

PostgreSQL with Docker

Use the combined Compose stack in ../../astrocyte-services-py/docker-compose.yml to run Postgres (pgvector) + the reference REST service together:

cd astrocyte-services-py
docker compose up -d

For Postgres only (no HTTP), start only postgres:

cd astrocyte-services-py
docker compose up -d postgres

Default DSN from your host (port 5433 maps to Postgres in the compose file):

postgresql://astrocyte:astrocyte@127.0.0.1:5433/astrocyte

Schema migrations (production)

DDL is shipped as plain SQL under migrations/ and applied with psql via scripts/migrate.sh (no Python migration framework).

export DATABASE_URL='postgresql://astrocyte:astrocyte@127.0.0.1:5433/astrocyte'
cd adapters-storage-py/astrocyte-postgres
./scripts/migrate.sh

Requirements: PostgreSQL 15+ (for CREATE INDEX CONCURRENTLY IF NOT EXISTS), psql on PATH.

After migrations are applied, set bootstrap_schema: false in vector_store_config so the app does not run CREATE TABLE / indexes at runtime (see configuration table below). For a single command that starts Postgres, runs migrations, then starts the stack with runbook config, use runbook-up.sh (see Runbook).

Embedding width: migrations/002_astrocyte_vectors.sql creates vector(${ASTROCYTE_EMBEDDING_DIMENSIONS:-128}). That must match embedding_dimensions in config. For OpenAI text-embedding-3-small, run migrations with ASTROCYTE_EMBEDDING_DIMENSIONS=1536.

Custom table_name: The shipped SQL targets astrocyte_vectors. If you use another table name, copy and adjust the migration files accordingly.

The later migrations add the Hindsight-comparable Postgres substrate around vectors: bank metadata and access grants, lifecycle columns (retained_at, forgotten_at), durable wiki pages/revisions/provenance, canonical entity/link tables, and normalized temporal facts.

Configuration

Constructor / YAML vector_store_config Meaning
dsn PostgreSQL connection URI (or set DATABASE_URL / ASTROCYTE_PG_DSN)
table_name Table name (default astrocyte_vectors; alphanumeric + underscore only)
embedding_dimensions Fixed vector(N) width; must match your embedding model and the vector(N) in SQL migrations (default 128)
bootstrap_schema If true (default), create extension / table / btree index on first use (dev-friendly; no HNSW). If false, assume migrate.sh already applied migrations/ (production).

How this fits astrocyte_gateway

  1. astrocyte-py defines the VectorStore protocol and discovers adapters by entry point (astrocyte.vector_stores).
  2. astrocyte-postgres registers postgresPostgresStore. Installing this package makes the name postgres available to resolve_provider().
  3. astrocyte_gateway/wiring.py calls resolve_vector_store(config), which loads the class from the entry point and passes vector_store_config from YAML (or env-only defaults).
  4. astrocyte_gateway/brain.py builds Astrocyte + PipelineOrchestrator with that store and your chosen llm_provider (still mock unless you configure a real LLM).

Example ASTROCYTE_CONFIG_PATH snippet:

provider_tier: storage
vector_store: postgres
llm_provider: mock
vector_store_config:
  dsn: postgresql://astrocyte:astrocyte@127.0.0.1:5433/astrocyte
  embedding_dimensions: 128
  bootstrap_schema: false
wiki_store: postgres
wiki_store_config:
  dsn: postgresql://astrocyte:astrocyte@127.0.0.1:5433/astrocyte
  bootstrap_schema: false

Then run the REST service (from repo layout):

export ASTROCYTE_CONFIG_PATH=/path/to/that.yaml
cd astrocyte-services-py/astrocyte-gateway-py && uv run astrocyte-gateway-py

Or set only env (no YAML file):

export ASTROCYTE_VECTOR_STORE=postgres
export DATABASE_URL=postgresql://astrocyte:astrocyte@127.0.0.1:5433/astrocyte
# embedding_dimensions default 128 — override via YAML if you add a file
cd astrocyte-services-py/astrocyte-gateway-py && uv sync --extra postgres

Note: vector_store_config for dimensions is only merged from YAML today; for env-only mode, add a small YAML or extend brain.py to pass ASTROCYTE_EMBEDDING_DIMENSIONS (future improvement).

Production notes

  • HNSW parameters (m, ef_construction) live in migrations/003_indexes.sql; tune with DBA guidance as load grows.
  • Embedding dimension must match the LLMProvider.embed() output used by the pipeline.
  • Use secrets for dsn, not committed YAML.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

astrocyte_postgres-0.12.3.tar.gz (52.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

astrocyte_postgres-0.12.3-py3-none-any.whl (16.8 kB view details)

Uploaded Python 3

File details

Details for the file astrocyte_postgres-0.12.3.tar.gz.

File metadata

  • Download URL: astrocyte_postgres-0.12.3.tar.gz
  • Upload date:
  • Size: 52.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for astrocyte_postgres-0.12.3.tar.gz
Algorithm Hash digest
SHA256 918d59ec9654aa2b67939771bfbef343870c6195f992cdbb1a958fe81552b3c8
MD5 509e40253bc1d8e0d56f852fae665f47
BLAKE2b-256 f1f53741d4a37cd6f0d3f3bc1896560cfbbc746ed3fd5cb48ba096c00d2ea22d

See more details on using hashes here.

File details

Details for the file astrocyte_postgres-0.12.3-py3-none-any.whl.

File metadata

File hashes

Hashes for astrocyte_postgres-0.12.3-py3-none-any.whl
Algorithm Hash digest
SHA256 762bc29945397de1198bd182a3e3be3a072002e5b4aef7511332c3aaca2e147e
MD5 493f5dbdb43f0ddc7c7282f642bfb71f
BLAKE2b-256 05974d15f72b74018d525a11ec6c70ee20cae27feb602826963381b7d1bcbf6b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page