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.

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 0.1.4

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 0.1.4
File Size Uploaded
milvusql_django-0.1.4.tar.gz 17.1 kB Details

Built distribution (wheel)

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

Total release size: 38.9 kB

Release files / milvusql_django-0.1.4.tar.gz

Download URL milvusql_django-0.1.4.tar.gz
Size 17.1 kB
Tags Source
SHA-256 checksum
How to use checksums
62a31d55d625e3d3e75820474849f46cbd7bfa0d0d63c2e31a25b78102d6000d
BLAKE2b-256 checksum
How to use checksums
69e03e00f7cb1504ea95cb558c239acb638c533ab5bbf5e439b25bd835d1c835
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-0.1.4-py3-none-any.whl

Download URL milvusql_django-0.1.4-py3-none-any.whl
Size 21.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a4d45c6db5d8b81ddf9c4feb5a19b9d0376d43245d8d29ad47a18d8ddf2df740
BLAKE2b-256 checksum
How to use checksums
83d261cf855f634ec097480437d531276b441bab80a4ae4fe26f67469bfa67fe
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

1.0.0

2 release files

This release

0.1.4 This release

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