Skip to main content

MidrasAI

MidrasAI provides a simple API for using the Colpali model, which is a multi-modal model for text and image retrieval. It allows for local access to the model, and integrates a vector database for efficient storage and sematic search.

Setting up the model as a server for remote access is a WIP.

Getting started

Note: This is an alpha version of MidrasAI. All feedack and suggestions are welcome!

Local Dependencies

  • ColPali access: ColPali is based on PaliGemma, you will need to request access to the model here. Then you must authenticate through the huggingface-cli to download the model.
  • Poppler: Midras uses pdf2image to convert pdfs to images. This library requires poppler to be installed on your system. Check out the installation instructions here.
  • Hardware: ColPali is a 3B parmeter model, so I recommend using a GPU with at least 8GB of VRAM.

Installation

If running locally, you can install MidrasAI and its dependencies with pip, poetry, or uv:

# pip
pip install 'midrasai[local]'

# poetry
poetry install 'midrasai[local]'

# uv
uv install 'midrasai[local]'

Usage

Starting the ColPali model

To load the ColPali model locally, you just need to use the LocalMidras class:

from midrasai.local import LocalMidras

midras = LocalMidras() # Make sure you're logged in to HuggingFace so you can download the model

Creating an index

To create an index, you can use the create_index method with the name of the index you want to create:

midras.create_index("my_index")

Using the model to embed data

The Midras class provides a couple of convenience methods for embeding data. You can use the embed_pdf method to embed a single pdf, or the embed_pil_images method to embed a list of images. Here's how to use them:

# Embed a single pdf
path_to_pdf = "path/to/pdf.pdf"

pdf_response = midras.embed_pdf(path_to_pdf, include_images=True)
# Embed a list of images
images = [Image.open("path/to/image.png"), Image.open("path/to/another_image.png")]

image_response = midras.embed_pil_images(images)

Inserting data into an index

Once you have your data embeddings, you can insert a data point into your index with the add_point method:

midras.add_point(
    index="my_index", # name of the index you want to add to
    id=1, # id of this data point, can be any integer or string
    embedding=response.embeddings[0], # the embedding you created in the previous step
    data={ # any additional data you want to store with this point, can be any dictionary
        "something": "hi"
        "something_else": 123
    }
)

Searching an index

After you've added data to your index, you can start searching for relevant data. You can use the query method to do this:

query = "What is the meaing of life?"

results = midras.query(index_name, query=query)

# Top 3 relevant data points
for result in results[:3]:
    # Each result will have a score, which is a measure of how relevant the data is to the query
    print(f"score: {result.score}")
    # Each result will also have any additional data you stored with it
    print(f"data: {result.data}")

If you want a more detailed example including RAG, check out the example vector search notebook.

Metadata

Release files for midrasai 0.1.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for midrasai 0.1.5
File Size Uploaded Provenance Actions
midrasai-0.1.5.tar.gz 8.8 kB Without provenance Details for midrasai-0.1.5.tar.gz

Built distribution (wheel)

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

Total release size: 19.4 kB

Release files / midrasai-0.1.5.tar.gz

Download URL midrasai-0.1.5.tar.gz
Size 8.8 kB
Tags Source
SHA-256 checksum
How to use checksums
321928e0ba3ae66a7ce279fb6b0965cb4eb4eca7674acf5f7e07e6c5d0787218
BLAKE2b-256 checksum
How to use checksums
e97b5069fee0858fea644cdfe3ccc8bb75b7661c2af82fc0419d01794c0a94dd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.3 CPython/3.12.3 Linux/6.8.0-48-generic

Release files / midrasai-0.1.5-py3-none-any.whl

Download URL midrasai-0.1.5-py3-none-any.whl
Size 10.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a576024b1ff3495384276cf1ea69f9d84e7c97cb4d3786d831c7ada91ec565eb
BLAKE2b-256 checksum
How to use checksums
4ca065a344ad24871aa86e095b490af5b75163d056d80e95ff3002449c59b12a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.3 CPython/3.12.3 Linux/6.8.0-48-generic

Security for midrasai 0.1.5

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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