Skip to main content

Embed pydantic models

Project description

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

embantic-0.1.0.tar.gz (7.1 kB view hashes)

Uploaded Source

Built Distribution

embantic-0.1.0-py3-none-any.whl (8.0 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page