Skip to main content

emdantic

Embed pydantic models

Embantic is an OVM (Object Vector Mapper) which embeds pydantic models to vectors allowing for semantic search and retrieval of arbitrary mutlimodal objects.

Installation

pip install embantic

Usage

Create a data model you would like to embed

from emdantic import EmbModel

class Foo(EmbModel):
    a: int
    b: str
    c: float
    d: bool
    e: list[int]
    f: dict[str, int]
    g: Image.Image
    h: Optional[EmbModel]

Embed the data model

foo = Foo(
    a=1, 
    b="hello", 
    c=3.14, 
    d=True, 
    e=[1, 2, 3], 
    f={"a": 1, "b": 2},
    g=Image.open("path/to/image.png")
)

vectors = foo.embed()

Or embed the data model and store the embeddings in a vector database

foo.store()

Search for objects by text

results: List[Foo] = Foo.search("hello")

Search for objects by image

results: List[Foo] = Foo.search(Image.open("path/to/image.png"))

Specify the embedding models to use

class Foo(EmbModel):
    __text_model__ = "text-embedding-ada-002"
    __image_model__ = "SigLIP-400M"

    ...

Backends

Vector Databases

Vector database backends are configured using EMDANTIC_VECTOR_BACKEND environment variable. Supported backeends are currently: faiss

Embedding Models

Embedding models are configured using the __text_model__ and __image_model__ parameters on the EmbModel class. Supported models are currently: text-embedding-ada-002 and SigLIP-400M.

Alternatively, you can set the EMDANTIC_TEXT_EMBEDDING_MODEL and EMDANTIC_IMAGE_EMBEDDING_MODEL environment variable as the model defaults.

Database

Embdantic also uses a database to store the raw objects in JSON format. The database is configured using the EMDANTIC_DATABASE_BACKEND environment variable. Supported databases are currently: sqlite.

Metadata

Release files for embantic 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 embantic 0.1.0
File Size Uploaded
embantic-0.1.0.tar.gz 7.1 kB Details

Built distribution (wheel)

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

Total release size: 15.2 kB

Release files / embantic-0.1.0.tar.gz

Download URL embantic-0.1.0.tar.gz
Size 7.1 kB
Tags Source
SHA-256 checksum
How to use checksums
bff517675bc439349ffde5229bf71d771ad06d58e255be17cccb8ce41025ec2f
BLAKE2b-256 checksum
How to use checksums
a2cec60abb07bc34cf677b26140d34439b0e435512131d49d3126e588a53ae94
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.3 CPython/3.12.4 Darwin/23.4.0

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

Download URL embantic-0.1.0-py3-none-any.whl
Size 8.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
34b6ec6352c24349b948ef1d5e51a3e9c824bc654653fb3c9b791854df253056
BLAKE2b-256 checksum
How to use checksums
084c3cc0fed7b0fa84862c971b2dd65062a6fa654ddfafd0c06c97fa66c1319a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.3 CPython/3.12.4 Darwin/23.4.0

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

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