Skip to main content

LocalStack extension to enable pgvector automatically

Project description

pgvector-extension Logo

LocalStack pgvector Extension 🚀

Install LocalStack Extension License: MIT PyPI version

localstack-extension-pgvector is a professional extension for LocalStack designed to simplify the development of AI-driven applications and Vector Search. This extension automatically enables pgvector on every PostgreSQL instance running in LocalStack and provides a web interface via pgweb.


✨ Key Features

  • Auto-Enable pgvector: Automatically executes CREATE EXTENSION IF NOT EXISTS vector; when a PostgreSQL container starts.
  • pgweb Integration: Automatically launches a pgweb (Web UI) instance as a sidecar to visualize your vector data.
  • Seamless Integration: Supports standard RDS and PostgreSQL instances in LocalStack.
  • Health Check Endpoint: Verify extension status via a dedicated HTTP endpoint.

🛠️ Installation

Using LocalStack Dashboard (Recommended)

Click the badge above or open the LocalStack Extensions Dashboard and enter this repository URL: https://github.com/Nocturnailed-Community/localstack-extension-pgvector

Using CLI

Use the following command to install the extension locally:

localstack extensions install "https://github.com/Nocturnailed-Community/localstack-extension-pgvector"

Local Development (Editable Mode)

  1. Clone this repository.
  2. Run:
    pip install -e .
    
  3. Restart LocalStack.

🐳 Using Docker Compose

For easy local development, you can use the provided docker-compose.yml:

  1. Start LocalStack:
    docker compose up -d
    
  2. The extension will be installed automatically. Check status:
    curl http://localhost:4566/pgvector-status
    

🛠️ Usage

  1. Start LocalStack:
    localstack start
    
  2. Launch PostgreSQL/RDS: Use AWS CLI or SDK to create a database instance. Example:
    awslocal rds create-db-instance --db-instance-identifier mydb --engine postgres --allocated-storage 20
    
  3. Access pgweb: Open your browser and navigate to http://localhost:8081 to view your data.
  4. Check Status: Verify if the extension is active: http://localhost:4566/pgvector-status

📡 API Reference (v0.2.0)

All endpoints are accessible via http://localhost:4566/pgvector/...

Status

curl http://localhost:4566/pgvector/status

Table Management

List tables:

curl http://localhost:4566/pgvector/tables

Create a table (with vector column):

curl -X POST http://localhost:4566/pgvector/tables \
  -H "Content-Type: application/json" \
  -d '{
    "table_name": "documents",
    "columns": [
      {"name": "id", "type": "SERIAL PRIMARY KEY"},
      {"name": "content", "type": "TEXT"},
      {"name": "embedding", "type": "vector(3)"}
    ]
  }'

Get table schema:

curl http://localhost:4566/pgvector/tables/documents/schema

Drop a table:

curl -X DELETE http://localhost:4566/pgvector/tables/documents

Data Operations

Insert rows:

curl -X POST http://localhost:4566/pgvector/tables/documents/data \
  -H "Content-Type: application/json" \
  -d '{
    "rows": [
      {"content": "Hello AI", "embedding": "[1,2,3]"},
      {"content": "Vector DB", "embedding": "[4,5,6]"}
    ]
  }'

Get rows (with pagination):

curl "http://localhost:4566/pgvector/tables/documents/data?limit=10&offset=0"

Update rows:

curl -X PUT http://localhost:4566/pgvector/tables/documents/data \
  -H "Content-Type: application/json" \
  -d '{"set": {"content": "Updated"}, "where": "id = 1"}'

Delete rows:

curl -X DELETE http://localhost:4566/pgvector/tables/documents/data \
  -H "Content-Type: application/json" \
  -d '{"where": "id = 1"}'

Raw SQL Query

curl -X POST http://localhost:4566/pgvector/query \
  -H "Content-Type: application/json" \
  -d '{"sql": "SELECT * FROM pg_extension WHERE extname = '\''vector'\'';"}'

🔍 Vector Similarity Search

curl -X POST http://localhost:4566/pgvector/search \
  -H "Content-Type: application/json" \
  -d '{
    "table_name": "documents",
    "column": "embedding",
    "query_vector": [1, 2, 3],
    "distance": "cosine",
    "limit": 5
  }'

Supported distance metrics: cosine, l2, inner_product


👨‍💻 Contributors


📜 License

This project is licensed under the MIT License - see the LICENSE file for details.


Built with ❤️ by Noc Lab as part of the LocalStack ecosystem.

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

localstack_extension_pgvector-0.2.0.tar.gz (6.8 kB view details)

Uploaded Source

Built Distribution

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

localstack_extension_pgvector-0.2.0-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

Details for the file localstack_extension_pgvector-0.2.0.tar.gz.

File metadata

File hashes

Hashes for localstack_extension_pgvector-0.2.0.tar.gz
Algorithm Hash digest
SHA256 f6732826dc22db7ddc7c8077fe5edfe2baeff0309cb4c962c227280c2b42e528
MD5 958848980b7e9a31ad2fd77566cf20af
BLAKE2b-256 ae192861bdac141b52ff2e82bcaddcc41244f59a05da0bffff7bea433091c215

See more details on using hashes here.

File details

Details for the file localstack_extension_pgvector-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for localstack_extension_pgvector-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3ec130749c4a21b37179cd6c1a706f7ae5d884837b225e73e3e63d77d3665006
MD5 0e2a701e5f40895eacb3271a5257a870
BLAKE2b-256 3fb751c551da7197e544f39e729fbc1f4e1f20badc49588c593c907adaa1e042

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