dejan-stankovic / radient

Radient turns many data types - not just text - into vectors for similarity search.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Radient

Radient is a developer-friendly, lightweight library for vectorization, i.e. turning data into embeddings. Radient supports many data types, not just text.

$ pip install radient

Why Radient?

In applications that leverage RAG, vector databases are commonly used as a way to retrieve relevant content that is relevant to the query. It's become so popular that "traditional" database vendors are rushing to support vector search. (Anybody see those funky Singlestore ads on US-101?)

Although still predominantly used for text today, vectors will be used extensively across a variety of different modalities in the upcoming months. This evolution is being powered by two independent occurrences: 1) the shift from large language models to large multimodal models (such as Reka and Fuyu), and 2) the rise in adoption for "traditional" tasks such as recommendation and semantic search. In short, vectors are going mainstream, and we need a way to vectorize everything, not just text.

Getting started

Vectorization can be performed as follows:

>>> from radient import text_vectorizer
>>> vectorizer = text_vectorizer()
>>> vectorizer.vectorize("Hello, world!")
Vector([-3.21440510e-02, -5.10351397e-02,  3.69579718e-02, ...

The above snippet vectorizes the string "Hello, world!" using a default model, namely bge-small-en-v1.5 from sentence-transformers. We can specify a different model using:

>>> vectorizer_mbai = text_vectorizer(method="sbert", model_name_or_path="mixedbread-ai/mxbai-embed-large-v1")
>>> vectorizer_mbai.vectorize("Hello, world!")
Vector([ 0.01729078,  0.04468533,  0.00055427, ...

This will use Mixbread AI's mxbai-embed-large-v1 model to perform vectorization.

More than just text

You're not limited to text modalities. Audio, graphs, images, and molecules can be vectorized as well:

>>> from pathlib import Path
>>> from radient import audio_vectorizer, molecule_vectorizer
>>> audio_vectorizer().vectorize(str(Path.home() / "audio.wav"))
Vector([-5.26519306e-03, -4.55586426e-03,  1.79212391e-02, ...
>>> molecule_vectorizer().vectorize("O=C=O")  # O=C=O == SMILES string for CO2
Vector([False, False, False, ...

You can attach metadata to the resulting embeddings and store them in sinks. Radient currently supports Milvus:

>>> vector = vectorizer.vectorize("My name is Slim Shady")
>>> vector.add_key_value("artist", "Eminem")  # {"artist": "Eminem"}
>>> vector.store(collection_name="_radient", field_name="vector")
{'insert_count': 1, 'ids': [449662764050547785]}

This will store the vector in a Milvus instance at http://localhost:19530 by default; if the specified collection does not exist at this URI, it will create it (with dynamic schema turned on for flexibility). You can change the desired Milvus instance by specifying the milvus_uri parameter. This works with Zilliz Cloud instances too, e.g. vector.store(milvus_uri="https://in01-dd7f98cd6b900f6.aws-us-west-2.vectordb.zillizcloud.com:19530").

For production use cases with large quantities of data, performance is key. Radient provides an accelerate function to optimize some vectorizers on-the-fly:

>>> vectorizer.vectorize("Hello, world!")  # runtime: ~32ms
Vector([-3.21440510e-02, -5.10351397e-02,  3.69579718e-02, ...
>>> vectorizer.accelerate()
>>> vectorizer.vectorize("Hello, world!")  # runtime: ~17ms
Vector([-3.21440622e-02, -5.10351285e-02,  3.69579904e-02, ...

Full write-up on Radient will come later, along with some sample applications, so stay tuned.

Supported libraries

Radient builds atop work from the broader ML community. Most vectorizers come from other libraries:

A massive thank you to all the creators and maintainers of these libraries.

Coming soon™

A couple of features slated for the near-term (hopefully):

  • Sparse, binary, and multi-vector support
  • Support all relevant embedding models on Huggingface, e.g. non-seq2seq models
  • Data sources from object storage, Google Drive, Box, etc
  • Vector sinks to Zilliz, Databricks, Confluent, etc

About

Radient turns many data types - not just text - into vectors for similarity search.

License:BSD 2-Clause "Simplified" License


Languages

Language:Python 94.2%Language:Jupyter Notebook 5.8%