Skip to main content

Embedded local-first property graph with vector search

Project description

polypack (Python)

Python bindings for the polypack embedded property-graph and vector-search core. PolyGraph and GraphQuery are a native Python layer mirroring the TypeScript PolyGraph/GraphQuery API; vector indexing, query execution, and directory-backed persistence run in the Rust core (polypack._core, built from crates/polypack-python).

Install

pip install polypack-db

Requires Python 3.8+ and numpy. Prebuilt wheels are published from polypack-db on PyPI; the version tracks the TypeScript package and polypack-core crate in lockstep.

Quick start

import time
from polypack import PolyGraph

graph = PolyGraph()

graph.add_node({
    "id": "doc_1",
    "type": "document",
    "data": {"title": "Quantum Computing"},
    "vector": [0.95, 0.20, 0.10],
    "insertedAt": int(time.time() * 1000),
    "updatedAt": int(time.time() * 1000),
})

graph.add_edge("doc_1", "REFERENCES", "doc_2", ownership="owned")

# Search by similarity
graph.query() \
    .where_type("document") \
    .similar_to([0.90, 0.30, 0.10], 0.5, 5) \
    .to_list()

# Filter, traverse, aggregate
graph.query().where("title", "Quantum Computing").traverse("REFERENCES", 3).to_list()
graph.query().where_type("book").aggregate("price", "avg")

Persistence

PolyGraph.open(directory) attaches a directory-backed binary store (snapshot + write-ahead log, shared format with the TypeScript BinaryStoreAdapter) and loads any existing state. Use it as a context manager so the store is compacted and closed on exit:

with PolyGraph.open("./data") as graph:
    graph.add_node({...})
    graph.save()  # persists queued puts and deletions

save() writes the complete current graph and flushes any deletions recorded since the last save; close_store() compacts and closes explicitly.

Vector indexes

ExactIndex and HnswIndex wrap the Rust vector core directly and can be used standalone, independent of PolyGraph:

from polypack import ExactIndex, HnswIndex

index = ExactIndex(distance="cosine")
index.add("doc_1", [0.95, 0.20, 0.10])
index.query([0.90, 0.30, 0.10], top_k=5, threshold=0.5)

approx = HnswIndex(m=16, ef_search=200)
approx.add_many([("doc_1", [0.95, 0.20, 0.10]), ("doc_2", [0.10, 0.90, 0.05])])

Errors

Native errors surface as PolypackError subclasses: PolypackValueError, PolypackDimensionError, PolypackClosedError, PolypackVersionError, PolypackCorruptDataError, and PolypackStorageError.

Development

See the top-level CONTRIBUTING.md for building the native extension with maturin and running the Python test suite.

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

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

polypack_db-2.4.7-cp38-abi3-win_amd64.whl (472.1 kB view details)

Uploaded CPython 3.8+Windows x86-64

polypack_db-2.4.7-cp38-abi3-manylinux_2_34_x86_64.whl (623.1 kB view details)

Uploaded CPython 3.8+manylinux: glibc 2.34+ x86-64

polypack_db-2.4.7-cp38-abi3-macosx_11_0_arm64.whl (563.5 kB view details)

Uploaded CPython 3.8+macOS 11.0+ ARM64

File details

Details for the file polypack_db-2.4.7-cp38-abi3-win_amd64.whl.

File metadata

  • Download URL: polypack_db-2.4.7-cp38-abi3-win_amd64.whl
  • Upload date:
  • Size: 472.1 kB
  • Tags: CPython 3.8+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for polypack_db-2.4.7-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 9a7ce479d199893a7490361a5bbb4fabc1218ca6851572500189e9331e7a73a8
MD5 f2cf7302ece97d15b4ac7e3c117db1dc
BLAKE2b-256 6c8087e9aa59d71d3e71207c6addce37158c744f1f2281406d40f784328c2b7a

See more details on using hashes here.

Provenance

The following attestation bundles were made for polypack_db-2.4.7-cp38-abi3-win_amd64.whl:

Publisher: release.yml on imattau/polypack

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file polypack_db-2.4.7-cp38-abi3-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for polypack_db-2.4.7-cp38-abi3-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 222b16c157b10c557c62cdf80481273bae1cbb73fa4bd5bfe5921ae86dded666
MD5 77c91815ebd71ec85da45a12fbc99c65
BLAKE2b-256 b727f96960f7fda2a8937c1c102d317aa0ffd039aacf5494a75d5214871c75c7

See more details on using hashes here.

Provenance

The following attestation bundles were made for polypack_db-2.4.7-cp38-abi3-manylinux_2_34_x86_64.whl:

Publisher: release.yml on imattau/polypack

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file polypack_db-2.4.7-cp38-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for polypack_db-2.4.7-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a60dbbe0127a530087326ab99c2e721c9525feac3ea34fa818a3ddd1b4bc5f2f
MD5 10ee89bce03589114f9ed95119847961
BLAKE2b-256 6db64190931e5e8acdeabc86ffdb3962d3a91d80aa1620d99fcd430c9a48e480

See more details on using hashes here.

Provenance

The following attestation bundles were made for polypack_db-2.4.7-cp38-abi3-macosx_11_0_arm64.whl:

Publisher: release.yml on imattau/polypack

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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