Skip to main content

postgresml-django

postgresml-django is a Python module that integrates PostgresML with Django ORM, enabling automatic in-database embedding of Django models. It simplifies the process of creating and searching vector embeddings for your text data.

Introduction

This module provides a seamless way to:

  • Automatically generate in-databse embeddings for specified fields in your Django models
  • Perform vector similarity searches in-database

Installation

  1. Ensure you have pgml installed and configured in your database. The easiest way to do that is to sign up for a free serverless database at postgresml.org. You can also host it your self.

  2. Install the package using pip:

    pip install postgresml-django
    

You are ready to go!

Usage Examples

Example 1: Using intfloat/e5-small-v2

This example demonstrates using the intfloat/e5-small-v2 transformer, which has an embedding size of 384.

from django.db import models
from postgresml_django import VectorField, Embed

class Document(Embed):
    text = models.TextField()
    text_embedding = VectorField(
        field_to_embed="text",
        dimensions=384,
        transformer="intfloat/e5-small-v2"
    )

# Searching
results = Document.vector_search("text_embedding", "some query to search against")

Example 2: Using mixedbread-ai/mxbai-embed-large-v1

This example shows how to use the mixedbread-ai/mxbai-embed-large-v1 transformer, which has an embedding size of 1024 and requires specific parameters for recall.

from django.db import models
from postgresml_django import VectorField, Embed

class Article(Embed):
    content = models.TextField()
    content_embedding = VectorField(
        field_to_embed="content",
        dimensions=1024,
        transformer="mixedbread-ai/mxbai-embed-large-v1",
        transformer_recall_parameters={
            "prompt": "Represent this sentence for searching relevant passages: "
        }
    )

# Searching
results = Article.vector_search("content_embedding", "some query to search against")

Note the differences between the two examples:

  1. The dimensions parameter is set to 384 for intfloat/e5-small-v2 and 1024 for mixedbread-ai/mxbai-embed-large-v1.
  2. The mixedbread-ai/mxbai-embed-large-v1 transformer requires additional parameters for recall, which are specified in the transformer_recall_parameters argument.

Both examples will automatically generate embeddings when instances are saved and allow for vector similarity searches using the vector_search method.

Contributing

We welcome contributions to postgresml-django! Whether it's bug reports, feature requests, documentation improvements, or code contributions, your input is valuable to us. Feel free to open issues or submit pull requests on our GitHub repository.

Metadata

Release files for postgresml-django 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for postgresml-django 0.1.0
File Size Uploaded Provenance Actions
postgresml_django-0.1.0.tar.gz 3.5 kB Without provenance Details for postgresml_django-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for postgresml-django 0.1.0
File Interpreter ABI Platform Actions
postgresml_django-0.1.0-py3-none-any.whl Python 3 none any Details for postgresml_django-0.1.0-py3-none-any.whl

Total release size: 7.9 kB

Release files / postgresml_django-0.1.0.tar.gz

Download URL postgresml_django-0.1.0.tar.gz
Size 3.5 kB
Tags Source
SHA-256 checksum
How to use checksums
1b262ca35156bcea0390df7f3772c7aff3ef65b217318ff52edc031edc6eaff4
BLAKE2b-256 checksum
How to use checksums
1f953784a47264cc189dca28bd979841436bfd1d9845fb73627cd6bfcfecbb80
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.11.9

Release files / postgresml_django-0.1.0-py3-none-any.whl

Download URL postgresml_django-0.1.0-py3-none-any.whl
Size 4.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cd1481f4bb0cba158c36874cdf2bea1937629a22f0c111412441926aa5dda22d
BLAKE2b-256 checksum
How to use checksums
e89d1f0393df33e86bf6adeafc1a6dc6cb7793a061485afce2076f89755c6f82
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.11.9

Security for postgresml-django 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page