Skip to main content

Database and vector store persistence adapters for HACS

Project description

HACS Persistence

PostgreSQL + pgvector persistence for healthcare data storage

Database and vector storage adapters optimized for healthcare AI applications.

🗄️ Database Support

PostgreSQL with pgvector

Primary storage solution for healthcare data:

  • Relational Data - Patient records, observations, clinical data
  • Vector Storage - Clinical embeddings via pgvector extension
  • Schema Management - Automated migrations and versioning
  • Healthcare Compliance - HIPAA-aware design patterns

🏥 Healthcare Schema

Optimized database tables for clinical workflows:

-- Core healthcare tables
patients              -- Patient demographics and clinical context
observations         -- Clinical measurements and findings
actors              -- Healthcare providers with role-based permissions
memory_blocks       -- AI agent episodic/procedural memory
evidence_items     -- Clinical guidelines and research
knowledge_base     -- Structured clinical knowledge

-- Vector storage for AI operations
patient_vectors     -- Patient data embeddings
clinical_vectors    -- Clinical note embeddings
memory_vectors      -- Memory content embeddings

📦 Installation

pip install hacs-persistence

🚀 Quick Start

Setup via HACS

# Automatic setup with migrations
python setup.py --mode local

# Database runs on localhost:5432
# Automatic pgvector extension installation

Direct Usage

from hacs_persistence import Adapter
from hacs_core import Patient

# Connect to healthcare database
adapter = Adapter(
    database_url="postgresql://hacs:password@localhost:5432/hacs"
)

# Store patient record
patient = Patient(
    full_name="Maria Rodriguez",
    birth_date="1985-03-15",
    gender="female"
)

# Save with automatic validation
saved_patient = adapter.save_resource(patient)
print(f"Saved patient: {saved_patient.id}")

🔧 Configuration

Environment Variables

# Primary database connection
DATABASE_URL=postgresql://hacs:password@localhost:5432/hacs

# Vector store configuration (uses pgvector by default)
VECTOR_STORE=pgvector

# Optional: External PostgreSQL for production
DATABASE_URL=postgresql://hacs:secure_password@prod-db:5432/hacs_production

Migration Management

# Run database migrations
python -m hacs_persistence.migrations $DATABASE_URL

# Check migration status
python -c "from hacs_persistence import get_migration_status; print(get_migration_status())"

📊 Performance

  • Resource Operations: <50ms for standard CRUD
  • Vector Queries: <100ms for similarity search
  • Batch Operations: 1000+ records per second
  • Memory Footprint: Minimal overhead

🔐 Security Features

  • Connection Encryption - SSL/TLS support
  • Role-based Access - Healthcare provider permissions
  • Audit Trails - Complete operation logging
  • Data Isolation - Organization-specific schemas

🛠️ Advanced Usage

Vector Operations

# Store clinical embedding
adapter.store_vector(
    resource_id="patient_123",
    embedding=[0.1, 0.2, ...],  # Clinical text embedding
    metadata={"type": "patient", "department": "cardiology"}
)

# Similarity search
similar_patients = adapter.vector_search(
    query_embedding=[0.1, 0.2, ...],
    resource_type="patient",
    top_k=5
)

Batch Operations

# Bulk insert for large datasets
patients = [Patient(...) for _ in range(1000)]
results = adapter.bulk_save(patients)

📄 License

Apache-2.0 License - see LICENSE for details.

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

hacs_persistence-0.4.0.tar.gz (30.8 kB view details)

Uploaded Source

Built Distribution

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

hacs_persistence-0.4.0-py3-none-any.whl (35.8 kB view details)

Uploaded Python 3

File details

Details for the file hacs_persistence-0.4.0.tar.gz.

File metadata

  • Download URL: hacs_persistence-0.4.0.tar.gz
  • Upload date:
  • Size: 30.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.8

File hashes

Hashes for hacs_persistence-0.4.0.tar.gz
Algorithm Hash digest
SHA256 158b2ecb324ca5421be52a1dfb2312d7b7b405d15da357c7d2dc3dd9a7cc3507
MD5 f212d1bd728753c4340e24efe5b2150c
BLAKE2b-256 4e0ed0b38bea3e2ff3ccfd8301c47c036eb4329c6cc701dd2f9d161ab2bcf9f0

See more details on using hashes here.

File details

Details for the file hacs_persistence-0.4.0-py3-none-any.whl.

File metadata

File hashes

Hashes for hacs_persistence-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2328cd62ba598e4d3773bd5820a5fe1ef853dbcffa3d5eb60c73db38fd06ca9f
MD5 2b7d7ec61f5d99aa17abd25149ba93df
BLAKE2b-256 4058a79099e3611b4e4f9fef4bf2364c55bce0614827a66c8443c5ef9eb8c1eb

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