Skip to main content

Python binding for pgvecto.rs

Project description

Python bindings for pgvecto.rs

pdm-managed

Usage

Install from PyPI:

pip install pgvecto_rs

See the usage of SDK

Or use it as an extension of postgres clients:

SDK

Our SDK is designed to use the pgvecto.rs out-of-box. You can exploit the power of pgvecto.rs to do similarity search or retrieve with filters, without writing any SQL code.

Install dependencies:

pip install "pgvecto_rs[sdk]"

A minimal example:

from pgvecto_rs.sdk import PGVectoRs, Record

# Create a client
client = PGVectoRs(
    db_url="postgresql+psycopg://postgres:mysecretpassword@localhost:5432/postgres",
    table_name="example",
    dimension=3,
)

try:
    # Add some records
    client.add_records(
        [
            Record.from_text("hello 1", [1, 2, 3]),
            Record.from_text("hello 2", [1, 2, 4]),
        ]
    )

    # Search with default operator (sqrt_euclid).
    # The results is sorted by distance
    for rec, dis in client.search([1, 2, 5]):
        print(rec.text)
        print(dis)
finally:
    # Clean up (i.e. drop the table)
    client.drop()

Output:

hello 2
1.0
hello 1
4.0

See examples/sdk_example.py and tests/test_sdk.py for more examples.

SQLAlchemy

Install dependencies:

pip install "pgvecto_rs[sqlalchemy]"

Then write your code. See examples/sqlalchemy_example.py and tests/test_sqlalchemy.py for example.

All the operators include:

  • squared_euclidean_distance
  • negative_dot_product_distance
  • negative_cosine_distance

psycopg3

Install dependencies:

pip install "pgvecto_rs[psycopg3]"

Then write your code. See examples/psycopg_example.py and tests/test_psycopg.py for example.

Known issue:

  • Can not check the length of an vector when inserting it into a table. See: #96.

Development

This package is managed by PDM.

Set up things:

pdm venv create
pdm use # select the venv inside the project path
pdm sync

Run lint:

pdm run format
pdm run check

Run test in current environment:

pdm run test

Test

Tox is used to test the package locally.

Run test in all environment:

tox run

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

pgvecto_rs-0.1.3.tar.gz (13.5 kB view details)

Uploaded Source

Built Distribution

pgvecto_rs-0.1.3-py3-none-any.whl (11.8 kB view details)

Uploaded Python 3

File details

Details for the file pgvecto_rs-0.1.3.tar.gz.

File metadata

  • Download URL: pgvecto_rs-0.1.3.tar.gz
  • Upload date:
  • Size: 13.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: pdm/2.10.3 CPython/3.10.12

File hashes

Hashes for pgvecto_rs-0.1.3.tar.gz
Algorithm Hash digest
SHA256 0d0b7a158224f078b8dda5f5a65e3a6fe0c24c8ef2e457f62d5c76c0af19680a
MD5 83577b6446600c186c2f3b94668e6f67
BLAKE2b-256 21014194a217408aeec56023dea87afb559937a4605a115e80060c1ec8a746d4

See more details on using hashes here.

File details

Details for the file pgvecto_rs-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: pgvecto_rs-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 11.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: pdm/2.10.3 CPython/3.10.12

File hashes

Hashes for pgvecto_rs-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 8d839d8a74a08b48420507ebc37966c5ed0d702f59ce9d5ede9ab21378769847
MD5 512c14a0ea213578c33f20de0c77fead
BLAKE2b-256 b7451d8298f481abd02524e5d43e1a15d863f156e108fc56d6e75419f443a219

See more details on using hashes here.

Supported by

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