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 details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

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

Uploaded Python 3

File details

Details for the file embantic-0.1.0.tar.gz.

File metadata

  • Download URL: embantic-0.1.0.tar.gz
  • Upload date:
  • Size: 7.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.4 Darwin/23.4.0

File hashes

Hashes for embantic-0.1.0.tar.gz
Algorithm Hash digest
SHA256 bff517675bc439349ffde5229bf71d771ad06d58e255be17cccb8ce41025ec2f
MD5 9728ab223e3baf6c5b3f34460f30e8f1
BLAKE2b-256 a2cec60abb07bc34cf677b26140d34439b0e435512131d49d3126e588a53ae94

See more details on using hashes here.

File details

Details for the file embantic-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: embantic-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 8.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.4 Darwin/23.4.0

File hashes

Hashes for embantic-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 34b6ec6352c24349b948ef1d5e51a3e9c824bc654653fb3c9b791854df253056
MD5 8d0aad905057dfc69cc10716ada6a044
BLAKE2b-256 084c3cc0fed7b0fa84862c971b2dd65062a6fa654ddfafd0c06c97fa66c1319a

See more details on using hashes here.

Supported by

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