Skip to main content

Python SDK for Apache AGE + pgvector — graph and vector queries on PostgreSQL

Project description

Piggie

PyPI version Python versions License

Python SDK for Apache AGE + pgvector on PostgreSQL.

Graph queries, vector search, and hybrid graph+vector operations — all in one PostgreSQL instance.

Quick Start

# Start the database (Docker, any platform, ARM + x86)
git clone https://github.com/gregfelice/piggie.git && cd piggie
docker compose up -d

# Install the SDK
pip install piggie
import piggie

db = piggie.connect("postgresql://piggie:piggie@localhost:5488/piggie", graph="my_graph")

# Cypher queries → DataFrames
df = db.cypher("MATCH (n:Person) RETURN n.name, n.age").to_df()

# Vector search
results = db.vector_search("documents", "embedding", query_vec, k=10).to_df()

# Hybrid: graph traversal + vector similarity
results = db.hybrid_search(
    cypher="MATCH (p:Paper)-[:CITES]->(cited) RETURN cited",
    vector_table="papers",
    vector_column="abstract_embedding",
    query_vector=query_vec,
    k=10,
).to_df()

Installation

pip install piggie

# With pandas support
pip install piggie[pandas]

# With all optional dependencies
pip install piggie[all]

Database Setup

Piggie requires PostgreSQL with Apache AGE (graph) and pgvector (vectors).

Docker (recommended) — multi-arch image (ARM + x86), hardened config, everything pre-configured:

docker compose up -d

Verify the stack:

python docker/smoke-test.py

Other platforms: See the Install Database guide for Ubuntu, macOS, Fedora, and from-source instructions.

Cloud deployment: Terraform modules for AWS, GCP, Azure, DigitalOcean, and Hetzner — one terraform apply and you're running.

Docker Image

The piggie/db image ships PostgreSQL 18 + Apache AGE 1.7.0 + pgvector 0.8.2 with:

  • Multi-arch: linux/amd64 + linux/arm64 (native on Apple M-series, AWS Graviton)
  • scram-sha-256 authentication (no trust or md5)
  • TLS enabled with self-signed cert (replace for production)
  • Audit logging for connections, disconnections, and DDL
  • Minimal attack surface — multi-stage build, no build tools in runtime

Benchmarks

We benchmarked AGE + pgvector against Neo4j, Kuzu, and NebulaGraph across 12 workloads at three scales (10K, 100K, 1M). AGE won all 12 workloads at every scale. At 1M nodes:

Workload AGE Neo4j Speedup
Point Lookup 0.29ms 0.97ms 3x
Pattern Match 0.14ms 1.8ms 13x
VLE Traversal 0.18ms 0.62ms 3x
Concurrent Queries 52ms 1,323ms 25x
Bulk Load 59ms 133ms 2x

The Piggie SDK also won 14/16 algorithm benchmarks against Neo4j GDS, using igraph (C) and networkit (C++) backends.

Read the full analysis: Can One PostgreSQL Replace Your Graph Database and Your Vector Database?

Graph Algorithms

19 algorithms across 7 categories with automatic backend selection:

# Auto-selects igraph C backend
df = db.centrality(measure="betweenness")

# Auto-selects networkit C++ backend
df = db.centrality(measure="closeness")

# Community detection
df = db.communities(method="louvain")

Backends: igraph (C), networkit (C++), NetworkX (Python). The SDK detects installed backends and routes each algorithm to the fastest available implementation.

Integrations

  • LangChainPiggieVectorStore and PiggieGraphStore for RAG pipelines
  • LlamaIndexPiggieGraphStore (triplets) and PiggiePropertyGraphStore (labeled property graph)
  • NetworkXto_networkx() conversion + built-in PageRank, community detection, shortest path, centrality
  • PyTorch GeometricFeatureStore and GraphStore for GNN training on AGE data

Notebooks

Notebook Description
Quickstart Getting started with Piggie
Hybrid Search Graph + vector search combined
Bulk Load Bulk load and export
Algorithms Graph algorithms with igraph/networkit backends
RAG Pipeline RAG with LlamaIndex and LangChain
GNN Training GNN training with PyTorch Geometric

Documentation

Security

See SECURITY.md for vulnerability disclosure policy and security model.

Community

Requirements

  • Python 3.10+
  • PostgreSQL 16–18 with Apache AGE and pgvector extensions (or use the Docker image)

License

Apache 2.0

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

piggie-0.8.0.tar.gz (774.3 kB view details)

Uploaded Source

Built Distribution

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

piggie-0.8.0-py3-none-any.whl (117.9 kB view details)

Uploaded Python 3

File details

Details for the file piggie-0.8.0.tar.gz.

File metadata

  • Download URL: piggie-0.8.0.tar.gz
  • Upload date:
  • Size: 774.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for piggie-0.8.0.tar.gz
Algorithm Hash digest
SHA256 321e8c690173ff3820704a677a422c3b8e26f2bf799992e02250ddef4dec07e7
MD5 28ba4460b943be45aa61ae618edbd115
BLAKE2b-256 39790cef650a33472c66ace1b18a5c2c09e7525cb24bbc97789e5c91a7c9a04a

See more details on using hashes here.

File details

Details for the file piggie-0.8.0-py3-none-any.whl.

File metadata

  • Download URL: piggie-0.8.0-py3-none-any.whl
  • Upload date:
  • Size: 117.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for piggie-0.8.0-py3-none-any.whl
Algorithm Hash digest
SHA256 848c3f5e104c72d80ac8af5966e1a3e2b28aeb363736ebaefab696d880ff8ca9
MD5 71038b32520ef0ab48eb46aadf40e975
BLAKE2b-256 e51ed998a1c6d2b6f5db300bb6057b3fe5e753a2b9da060611393402f77371be

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