Skip to main content
milvusql logo

milvusql-django

A Django database backend for Milvus, built on the milvusql DBAPI.

PyPI Python License CI

📚 Documentation · PyPI · milvusql


Model/Field CRUD and filtering go through Django's normal query compiler; vector search goes through an explicit helper instead of a queryset method, because Milvus needs an index built and the collection loaded before a vector column is searchable at all — see API below. Relation lookups (filter(related__field=...)), .values().annotate(...) grouping and Exists(... OuterRef(...)) (correlated EXISTS, decorrelated into a semi/anti join) all plan through the DBAPI's relational engine, and a TextField is Milvus's analyzer-enabled full-text input.

Installation

pip install milvusql-django

Quick start

# settings.py
DATABASES = {
    "default": {
        "ENGINE": "milvusql_django",
        "NAME": "/path/to/items.db",  # or HOST/PORT/USER/PASSWORD for a real server
    }
}
# models.py
from django.db import models
from milvusql_django.fields import VectorField

class Item(models.Model):
    embedding = VectorField(dim=768)
    category = models.CharField(max_length=64)
# after migrating: build the index and load the collection once
from django.db import connection
from milvusql_django.schema import create_index_and_load

create_index_and_load(
    connection, "myapp_item", "embedding",
    using="HNSW", metric_type="COSINE",
)
# CRUD/filtering: the normal ORM
Item.objects.filter(category="book").values("id")

# vector search: a raw SQL escape hatch, not a queryset method
with connection.cursor() as cursor:
    cursor.execute(
        'SELECT id FROM "myapp_item" ORDER BY embedding <=> %s LIMIT 5',
        [[0.1] * 768],
    )
    rows = cursor.fetchall()

API

VectorField

A standard Django Field, not a fake-column shim — round-trips list[float] <-> VECTOR(n):

from milvusql_django.fields import VectorField

class Item(models.Model):
    embedding = VectorField(dim=768)   # dim is optional; omit for an unconstrained VECTOR

milvusql_django.schema.create_index_and_load()

create_index_and_load(
    connection,          # a Django database connection
    table,                # collection/table name
    field_name,            # the VectorField's column
    *,
    using="HNSW",
    metric_type="COSINE",
    **index_params,        # e.g. M=16, ef_construction=200
)

The explicit follow-up step CreateModel deliberately doesn't do automatically — index method/metric is a query-shape decision (HNSW vs. IVF, COSINE vs. L2), not something a generic schema migration should guess. Call it once, after defining the model, before querying it.

Schema & migrations

This is a first cut, not full Django migration parity:

Operation Support
CreateModel (scalar fields + one or more VectorFields)
AddField ✅ against a real Milvus server — Milvus Lite's gRPC server doesn't implement AddCollectionField
RemoveField, AlterField ❌ raises loudly — Milvus can't alter or drop a field

See Schema & Migrations for the full picture.

Development

From the workspace root (requires Python 3.12+, uv, task):

task install
task django:lint
task django:test    # integration tests need Docker (testcontainers)

License

MIT

Release files for milvusql-django 1.0.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 milvusql-django 1.0.0
File Size Uploaded
milvusql_django-1.0.0.tar.gz 17.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for milvusql-django 1.0.0
File Interpreter ABI Platform
milvusql_django-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 39.9 kB

Release files / milvusql_django-1.0.0.tar.gz

Download URL milvusql_django-1.0.0.tar.gz
Size 17.5 kB
Tags Source
SHA-256 checksum
How to use checksums
98a2c6856a7637142a157f4c12036f641482c2f032a77aff66ada478e295a46e
BLAKE2b-256 checksum
How to use checksums
fa61a6d523d718ab0b1ada7bdc441f7f4f8fb188b778daff6f5c45038d804dec
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / milvusql_django-1.0.0-py3-none-any.whl

Download URL milvusql_django-1.0.0-py3-none-any.whl
Size 22.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
946b6f118885b7f9fb365975cf861b4cb24294da9d070dc125ea624decbb850b
BLAKE2b-256 checksum
How to use checksums
08d2206c8b4bdccf747e6428e1a99eceb5c883eaca27e00f9e7f9c70b257e0d4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

1 release file

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