Skip to main content

🔮 Super-power your database with AI 🔮

Project description

Bring AI to your favorite database!

Package version Downloads Supported Python versions Coverage License - Apache 2.0

English | 中文 | 日本語

What is aladindb? 🔮

aladindb is an open-source framework for integrating your database with AI models, APIs, and vector search engines, providing streaming inference and scalable training/fine-tuning.

aladindb is not a database. aladindb is an open platform unifying data infrastructure and AI. Think db = aladin(db): aladindb transforms your databases into an intelligent system that leverages the full power of the AI, open-source and Python ecosystem. It is a single scalable environment for all your AI that can be deployed anywhere, in the cloud, on-prem, on your machine.

aladindb allows you to build AI applications easily without needing to move your data to complex MLOps pipelines and specialized vector databases by integrating AI at the data’s source, directly on top of your existing data infrastructure:

  • Generative AI & LLM-Chat
  • Vector Search
  • Standard Machine Learning Use-Cases (Classification, Segmentation, Recommendation etc.)
  • Highly custom AI use-cases involving ultra specialized models

To get started: Check the use-cases we have already implemented here in the docs as well as the apps built by the community in the dedicated aladin-community-apps repo and try all of them with Jupyter right in your browser!

aladindb is open-source: Please leave a star to support the project! ⭐

For more information about aladindb and why we believe it is much needed, read this blog post.

Overview QuickStart

Key Features:

  • Integration of AI with your existing data infrastructure: Integrate any AI models and APIs with your databases in a single scalable deployment, without the need for additional pre-processing steps, ETL or boilerplate code.
  • Streaming Inference: Have your models compute outputs automatically and immediately as new data arrives, keeping your deployment always up-to-date.
  • Scalable Model Training: Train AI models on large, diverse datasets simply by querying your training data. Ensured optimal performance via in-build computational optimizations.
  • Model Chaining: Easily setup complex workflows by connecting models and APIs to work together in an interdependent and sequential manner.
  • Simple, but Extendable Interface: Add and leverage any function, program, script or algorithm from the Python ecosystem to enhance your workflows and applications. Drill down to any layer of implementation, including to the inner workings of your models while operating aladindb with simple Python commands.
  • Difficult Data-Types: Work directly with images, video, audio in your database, and any type which can be encoded as bytes in Python.
  • Feature Storing: Turn your database into a centralized repository for storing and managing inputs and outputs of AI models of arbitrary data-types, making them available in a structured format and known environment.
  • Vector Search: No need to duplicate and migrate your data to additional specialized vector databases - turn your existing battle-tested database into a fully-fledged multi-modal vector-search database, including easy generation of vector embeddings and vector indexes of your data with preferred models and APIs.

Why opt for aladindb?

With aladindb Without
Data Management & Security Data stays in the database, with AI outputs stored alongside inputs available to downstream applications. Data access and security to be externally controlled via database access management. Data duplication and migration to different environments, and specialized vector databases, imposing data management overhead.
Infrastructure A single environment to build, ship, and manage your AI applications, facilitating scalability and optimal compute efficiency. Complex fragmented infrastructure, with multiple pipelines, coming with high adoption and maintenance costs and increasing security risks.
Code Minimal learning curve due to a simple and declarative API, requiring simple Python commands. Hundreds of lines of codes and settings in different environments and tools.

Supported Datastores (more coming soon):

Transform your existing database into a Python-only AI development and deployment stack with one command:

db = aladin('mongodb|postgres|mysql|sqlite|duckdb|snowflake://<your-db-uri>')

Supported AI Frameworks and Models (more coming soon):

Integrate, train and manage any AI model (whether from open-source, commercial models or self-developed) directly with your datastore to automatically compute outputs with a single Python command:

  • Install and deploy model:
m = db.add(
    <sklearn_model>|<torch_module>|<transformers_pipeline>|<arbitrary_callable>,
    preprocess=<your_preprocess_callable>,
    postprocess=<your_postprocess_callable>,
    encoder=<your_datatype>
)
  • Predict:
m.predict(X='<input_column>', db=db, select=<mongodb_query>, listen=False|True, create_vector_index=False|True)
  • Train model:
m.fit(X='<input_column_or_key>', y='<target_column_or_key>', db=db, select=<mongodb_query>|<ibis_query>)

Pre-Integrated AI APIs (more coming soon):

Integrate externally hosted models accessible via API to work together with your other models with a simple Python command:

m = db.add(
    OpenAI<Task>|Cohere<Task>|Anthropic<Task>|JinaAI<Task>(*args, **kwargs),   # <Task> - Embedding,ChatCompletion,...
)

Infrastructure Diagram

Featured Examples

Try our ready-to-use notebooks live on your browser.

Also find use-cases and apps built by the community in the aladin-community-apps repository.

Text-To-Image Search Text-To-Video Search Question the Docs
Semantic Search Engine Classical Machine Learning Cross-Framework Transfer Learning

Installation

1. Install aladindb via pip (~1 minute):

Requirements:

  • Python 3.10 or 3.11
  • Working pip installation (e.g. via virtual environment)
pip install aladindb

2. Try aladindb via Docker (~2 minutes):

Requirements:

docker run -p 8888:8888 aladindb/demo:latest

Preview

Here are snippets which give you a sense of how aladindb works and how simple it is to use. You can visit the docs to learn more.

- Deploy ML/AI models to your database:

Automatically compute outputs (inference) with your database in a single environment.

import pymongo
from sklearn.svm import SVC

from aladindb import aladin

# Make your db aladin!
db = aladin(pymongo.MongoClient().my_db)

# Models client can be converted to aladindb objects with a simple wrapper.
model = aladin(SVC())

# Add the model into the database
db.add(model)

# Predict on the selected data.
model.predict(X='input_col', db=db, select=Collection(name='test_documents').find({'_fold': 'valid'}))

- Train models directly from your database.

Simply by querying your database, without additional ingestion and pre-processing:

import pymongo
from sklearn.svm import SVC

from aladindb import aladin

# Make your db aladin!
db = aladin(pymongo.MongoClient().my_db)

# Models client can be converted to aladindb objects with a simple wrapper.
model = aladin(SVC())

# Fit model on the training data.
model.fit(X='input_col', y='target_col', db=db, select=Collection(name='test_documents').find({}))

- Vector-Search your data:

Use your existing favorite database as a vector search database, including model management and serving.

# First a "Listener" makes sure vectors stay up-to-date
indexing_listener = Listener(model=OpenAIEmbedding(), key='text', select=collection.find())

# This "Listener" is linked with a "VectorIndex"
db.add(VectorIndex('my-index', indexing_listener=indexing_listener))

# The "VectorIndex" may be used to search data. Items to be searched against are passed
# to the registered model and vectorized. No additional app layer is required.
db.execute(collection.like({'text': 'clothing item'}, 'my-index').find({'brand': 'Nike'}))

- Integrate AI APIs to work together with other models.

Use OpenAI, Jina AI, PyTorch or Hugging face model as an embedding model for vector search.

# Create a ``VectorIndex`` instance with indexing listener as OpenAIEmbedding and add it to the database.
db.add(
    VectorIndex(
        identifier='my-index',
        indexing_listener=Listener(
            model=OpenAIEmbedding(identifier='text-embedding-ada-002'),
            key='abstract',
            select=Collection(name='wikipedia').find(),
        ),
    )
)
# The above also executes the embedding model (openai) with the select query on the key.

# Now we can use the vector-index to search via meaning through the wikipedia abstracts
cur = db.execute(
    Collection(name='wikipedia')
        .like({'abstract': 'philosophers'}, n=10, vector_index='my-index')
)

- Add a Llama 2 model to aladindb!:

model_id = "meta-llama/Llama-2-7b-chat-hf"
tokenizer = AutoTokenizer.from_pretrained(model_id)
pipeline = transformers.pipeline(
    "text-generation",
    model=model_id,
    torch_dtype=torch.float16,
    device_map="auto",
)

model = Pipeline(
    identifier='my-sentiment-analysis',
    task='text-generation',
    preprocess=tokenizer,
    object=pipeline,
    torch_dtype=torch.float16,
    device_map="auto",
)

# You can easily predict on your collection documents.
model.predict(
    X=Collection(name='test_documents').find(),
    db=db,
    do_sample=True,
    top_k=10,
    num_return_sequences=1,
    eos_token_id=tokenizer.eos_token_id,
    max_length=200
)

- Use models outputs as inputs to downstream models:

model.predict(
    X='input_col',
    db=db,
    select=coll.find().featurize({'X': '<upstream-model-id>'}),  # already registered upstream model-id
    listen=True,
)

Community & Getting Help

If you have any problems, questions, comments, or ideas:

Contributing

There are many ways to contribute, and they are not limited to writing code. We welcome all contributions such as:

Please see our Contributing Guide for details.

Contributors

Thanks goes to these wonderful people:

License

aladindb is open-source and intended to be a community effort, and it wouldn't be possible without your support and enthusiasm. It is distributed under the terms of the Apache 2.0 license. Any contribution made to this project will be subject to the same provisions.

Join Us

We are looking for nice people who are invested in the problem we are trying to solve to join us full-time. Find roles that we are trying to fill here!

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

aladindb-0.1.1.tar.gz (149.0 kB view hashes)

Uploaded Source

Built Distribution

aladindb-0.1.1-py3-none-any.whl (180.8 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