https://github.com/brianferri/pymilvusmodel
MilvusVDB Model interaction layer
https://github.com/brianferri/pymilvusmodel
milvus pydantic python
Last synced: 3 months ago
JSON representation
MilvusVDB Model interaction layer
- Host: GitHub
- URL: https://github.com/brianferri/pymilvusmodel
- Owner: brianferri
- License: mit
- Created: 2025-02-28T15:33:47.000Z (7 months ago)
- Default Branch: main
- Last Pushed: 2025-05-02T13:20:33.000Z (5 months ago)
- Last Synced: 2025-06-04T23:43:25.908Z (4 months ago)
- Topics: milvus, pydantic, python
- Language: Python
- Homepage: https://pypi.org/project/milvusmodel.py/
- Size: 17.6 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# PyMilvusModel
Inspired by [SQLModel](https://sqlmodel.tiangolo.com/), PyMilvusModel:
> is a library for interacting with [Milvus](https://milvus.io/) databases from Python code, with Python objects.
and follows the same paradigm, using Python type annotations and powered by [Pydantic](https://docs.pydantic.dev/latest/)
## Installation
```sh
pip install milvusmodel.py
```## Example Usage
```py
from typing import List, Optional
from typing_extensions import Annotated
from pymilvus import MilvusClient, DataType
from pymilvusmodel import MilvusIndexParam, MilvusField, MilvusModelclass ExampleModel(MilvusModel):
indexes: list[MilvusIndexParam] = [
MilvusIndexParam("vector", "IVF_FLAT", "vector_index", metric_type="COSINE", params={
"nlist": 128
})
]
id: Annotated[
Optional[int],
MilvusField(name="id", dtype=DataType.INT64,
is_primary=True, auto_id=True)
] = None
vector: Annotated[
List[float],
MilvusField(name="vector", dtype=DataType.FLOAT_VECTOR, dim=2)
]MILVUS_CLIENT = MilvusClient("http://localhost:19530")
MilvusModel.metadata.create_all(MILVUS_CLIENT)
print(MILVUS_CLIENT.list_collections()) # ['ExampleModel']
ExampleModel.insert(ExampleModel(vector=[0, 1]))
print(ExampleModel.query(filter="id>=0")) # [ExampleModel(indexes=[], id=456328785400861845, vector=[0.0, 1.0])]
```