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.6-cp38-abi3-win_amd64.whl (472.8 kB view details)

Uploaded CPython 3.8+Windows x86-64

polypack_db-2.4.6-cp38-abi3-manylinux_2_34_x86_64.whl (623.2 kB view details)

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

polypack_db-2.4.6-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.6-cp38-abi3-win_amd64.whl.

File metadata

  • Download URL: polypack_db-2.4.6-cp38-abi3-win_amd64.whl
  • Upload date:
  • Size: 472.8 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.6-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 fa653252e7bac93266c9d1e9a568155bf88c29231b718a32b6e4f6f2cb60e918
MD5 614c29a6e30c6807ba36b6b82d1eb138
BLAKE2b-256 7b8b243294cec2ee61261ca6be63fae0e9b288dd2f6edfe5bd8bc1a27c48f269

See more details on using hashes here.

Provenance

The following attestation bundles were made for polypack_db-2.4.6-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.6-cp38-abi3-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for polypack_db-2.4.6-cp38-abi3-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 1f33aee1949027b9581244d337de330087f4b9316fd1bc2eee2b3f10fae9461d
MD5 cbe914461c51d77de2a67eb17ebdadb8
BLAKE2b-256 91b3eaa85a94323098f9b8944a69b7a94bfffb2513bd8c9e284b26308c06da6e

See more details on using hashes here.

Provenance

The following attestation bundles were made for polypack_db-2.4.6-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.6-cp38-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for polypack_db-2.4.6-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 079283cb3d359b0dee6c70d307ebed13b420889aafbf83cdc3554e9293b9c658
MD5 4ccd626a0a9f5ee6f0a95bb4c28c9c9c
BLAKE2b-256 5fef94f976ac2f60f68b3c9f7f083ce77c9ba58e071b079d035fb8be9df47082

See more details on using hashes here.

Provenance

The following attestation bundles were made for polypack_db-2.4.6-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