Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

postgresml-django is a Python module that integrates PostgresML with Django ORM, enabling automatic in-database embedding of Django models.

License

NotificationsYou must be signed in to change notification settings

postgresml/postgresml-django

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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 havepgml installed and configured in your database. The easiest way to do that is to sign up for a free serverless database atpostgresml.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 theintfloat/e5-small-v2 transformer, which has an embedding size of 384.

fromdjango.dbimportmodelsfrompostgresml_djangoimportVectorField,EmbedclassDocument(Embed):text=models.TextField()text_embedding=VectorField(field_to_embed="text",dimensions=384,transformer="intfloat/e5-small-v2"    )# Searchingresults=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 themixedbread-ai/mxbai-embed-large-v1 transformer, which has an embedding size of 1024 and requires specific parameters for recall.

fromdjango.dbimportmodelsfrompostgresml_djangoimportVectorField,EmbedclassArticle(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: "        }    )# Searchingresults=Article.vector_search("content_embedding","some query to search against")

Note the differences between the two examples:

  1. Thedimensions parameter is set to 384 forintfloat/e5-small-v2 and 1024 formixedbread-ai/mxbai-embed-large-v1.
  2. Themixedbread-ai/mxbai-embed-large-v1 transformer requires additional parameters for recall, which are specified in thetransformer_recall_parameters argument.

Both examples will automatically generate embeddings when instances are saved and allow for vector similarity searches using thevector_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.

About

postgresml-django is a Python module that integrates PostgresML with Django ORM, enabling automatic in-database embedding of Django models.

Topics

Resources

License

Stars

Watchers

Forks

Languages


[8]ページ先頭

©2009-2025 Movatter.jp