Skip to main content

lotus

Project description

LOTUS: Fast, Easy and Accurate LLM-Powered Data Processing

Colab Demo Arxiv Discord Blog Documentation Status PyPI - Python Version PyPI

LOTUS is the framework that allows you to easily process your datasets, including unstructured and structured data, with LLMs. It provides an intuitive Pandas-like API, offers algorithms for optimizing your programs for up to 1000x speedups, and makes LLM-based data processing robust with accuracy guarantees with respect to high-quality reference algorithms.

LOTUS stands for LLMs Over Text, Unstructured and Structured Data, and it introduces semantic operators. Semantic operators extend the core philosophy of relational operators—designed for declarative and robust structured-data processing—to unstructured-data processing with AI. Semantic operators are expressive, allowing you to easily capture all of your data-intensive AI programs, from simple RAG, to document extraction, image classification, LLM-judge evals, unstructured data analysis, complex research-based synthesis and more.

📰 New: Read about LOTUSPlan, our new API for optimized LLM-based data processing via lazy execution—delivering up to 2.4× cost reduction and up to 4.6× higher accuracy across diverse tasks (e.g., LLM-judge evals, agent trace analysis, RAG, deep research and document extraction)

For trouble-shooting or feature requests, please raise an issue and we'll get to it promptly. To share feedback and applications you're working on, you can send us a message on our community discord, or send an email (lianapat@stanford.edu).

Installation

Using uv (Recommended)

For the latest stable release:

# Install uv if you haven't already
curl -LsSf https://astral.sh/uv/install.sh | sh

# Create a new project or navigate to your existing project
uv add lotus-ai

For the latest features:

uv add git+https://github.com/lotus-data/lotus.git@main

Using pip

For the latest stable release:

conda create -n lotus python=3.10 -y
conda activate lotus
pip install lotus-ai

For the latest features, you can alternatively install as follows:

conda create -n lotus python=3.10 -y
conda activate lotus
pip install git+https://github.com/lotus-data/lotus.git@main

Running on Mac

If you are running on mac and using pip, please install Faiss via conda:

CPU-only version

conda install -c pytorch faiss-cpu=1.8.0

GPU(+CPU) version

conda install -c pytorch -c nvidia faiss-gpu=1.8.0

If you're using uv, the faiss-cpu dependency will be handled automatically.

For more details, see Installing FAISS via Conda.

Quickstart

If you're already familiar with Pandas, getting started will be a breeze! Below we provide a simple example using sem_filter. Like all semantic operators, it is specified by a langex (natural language expression) parameterized by one or more column names in brackets — here {title}. The langex for a sem_filter is a NL predicate, which is a natural language expression that can be evaluated to a True/False value.

import pandas as pd
import lotus
from lotus.models import LM

# Configure the LM — export your API key before running (e.g. OPENAI_API_KEY)
lm = LM(model="gpt-4.1-nano")
lotus.settings.configure(lm=lm)

# A sample of GitHub-style issue titles from an open source project
issues = pd.DataFrame({
    "title": [
        "Fix typo in README",
        "Add dark mode support to dashboard",
        "Refactor entire auth system to use OAuth2",
        "Update copyright year in LICENSE",
        "Implement distributed transaction support across microservices",
        "Change button color on settings page",
        "Migrate database from Postgres 13 to 16 with zero downtime",
        "Add missing comma in error message",
        "Build custom query planner to replace third-party dependency",
        "Bump lodash to fix known CVE",
        "Support multi-region active-active replication",
        "Remove unused import in utils.py",
    ]
})

# Use sem_filter to find issues approachable for a first-time contributor
good_first_issues = issues.sem_filter(
    "The {title} describes a small, self-contained task that a new open source contributor could tackle without deep knowledge of the codebase"
)

print("Good first issues for new contributors:\n")
print(good_first_issues.to_string(index=False))

# Uncomment to print the total LM usage
# lm.print_total_usage()

Tutorials

Below are some short tutorials in Google Colab, to help you get started. We recommend starting with [1] Introduction to Semantic Operators and LOTUS, which will provide a broad overview of useful functionality to help you get started.

Tutorial Difficulty Colab Link
1. Introduction to Semantic Operators and LOTUS Open In Colab
2. Failure Analysis Over Agent Traces Open In Colab
3. System Prompt Analysis with LOTUS Open In Colab
4. Processing Multimodal Datasets Open In Colab

Key Concept: The Semantic Operator Model

LOTUS introduces the semantic operator programming model. Semantic operators are declarative transformations over one or more datasets, parameterized by a natural language expression, that can be implemented by a variety of AI-based algorithms. Semantic operators seamlessly extend the relational model, operating over tables that may contain traditional structured data as well as unstructured fields, such as free-form text. These modular language-based operators allow you to write AI-based pipelines with high-level logic, leaving optimizations to the query engine. Each operator can be implemented and optimized in multiple ways, opening a rich space for execution plans, similar to relational operators. To learn more about the semantic operator model, read the full research paper.

LOTUS offers a number of semantic operators in a Pandas-like API, some of which are described below. To learn more about semantic operators provided in LOTUS, check out the full documentation, run the colab tutorial, or you can also refer to these examples.

Semantic operators provide a unified API for both LLM-based primitives...

Operator Description
sem_map Map each record using a natural language projection
sem_filter Keep records that match the natural language predicate
sem_extract Extract one or more attributes from each row
sem_agg Aggregate across all records (e.g. for summarization)
sem_topk Order the records by some natural langauge sorting criteria
sem_join Join two datasets based on a natural language predicate

... and embedding-based primitives:

Operator Description
sem_sim_join Join two DataFrames based on semantic similarity
sem_search Perform semantic search the over a text column

Supported Models

There are 3 main model classes in LOTUS:

  • LM: The language model class.
    • The LM class is built on top of the LiteLLM library, and supports any model that is supported by LiteLLM. See this page for examples of using models on OpenAI, Ollama, and vLLM. Any provider supported by LiteLLM should work. Check out litellm's documentation for more information.
  • RM: The retrieval model class.
    • Any model from SentenceTransformers can be used with the SentenceTransformersRM class, by passing the model name to the model parameter (see an example here). Additionally, LiteLLMRM can be used with any model supported by LiteLLM (see an example here).
  • Reranker: The reranker model class.
    • Any CrossEncoder from SentenceTransformers can be used with the CrossEncoderReranker class, by passing the model name to the model parameter (see an example here).

Contributing

We welcome contributions from the community! Whether you're reporting bugs, suggesting features, or contributing code, we have comprehensive templates and guidelines to help you get started.

Getting Started

Before contributing, please:

  1. Read our Contributing Guide - Comprehensive guidelines for contributors
  2. Check existing issues - Avoid duplicates by searching existing issues and pull requests
  3. Join our community - Connect with us on Discord

Community

We're excited to see what you build with LOTUS! 🚀 If you would like to be listed as a user and have your project featured, please reach out to lianapat@stanford.edu.

References

For recent updates related to LOTUS, follow @lianapatel_ on X.

If you find LOTUS or semantic operators useful, we'd appreciate if you can please cite this work as follows:

@article{patel2025semanticoptimization,
    title = {Semantic Operators and Their Optimization: Enabling LLM-Based Data Processing with Accuracy Guarantees in LOTUS},
    author = {Patel, Liana and Jha, Siddharth and Pan, Melissa and Gupta, Harshit and Asawa, Parth and Guestrin, Carlos and Zaharia, Matei},
    year = {2025},
    journal = {Proc. VLDB Endow.},
    url = {https://doi.org/10.14778/3749646.3749685},
}
@article{patel2024semanticoperators,
      title={Semantic Operators: A Declarative Model for Rich, AI-based Analytics Over Text Data},
      author={Liana Patel and Siddharth Jha and Parth Asawa and Melissa Pan and Carlos Guestrin and Matei Zaharia},
      year={2024},
      eprint={2407.11418},
      url={https://arxiv.org/abs/2407.11418},
}

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

lotus_ai-1.2.1.tar.gz (1.0 MB view details)

Uploaded Source

Built Distribution

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

lotus_ai-1.2.1-py3-none-any.whl (163.9 kB view details)

Uploaded Python 3

File details

Details for the file lotus_ai-1.2.1.tar.gz.

File metadata

  • Download URL: lotus_ai-1.2.1.tar.gz
  • Upload date:
  • Size: 1.0 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.21 {"installer":{"name":"uv","version":"0.11.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for lotus_ai-1.2.1.tar.gz
Algorithm Hash digest
SHA256 60a4096790e7891fb006d2e4fa57a2a1f7835686d81a69e5a5279d43a340bc69
MD5 de0c180ebb1a97d5458b4a08d472e15d
BLAKE2b-256 bd13ff5d5b7a1e0ca9f0cd1be61517d65ccaa5d6324501bff5d84b668746c2ef

See more details on using hashes here.

File details

Details for the file lotus_ai-1.2.1-py3-none-any.whl.

File metadata

  • Download URL: lotus_ai-1.2.1-py3-none-any.whl
  • Upload date:
  • Size: 163.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.21 {"installer":{"name":"uv","version":"0.11.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for lotus_ai-1.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 64cf2cd704620f8472e1c9388a1f514c81e6890342aa32af3f6c4609aa058d90
MD5 4f6f02e688a54094145c7a7c13f6330e
BLAKE2b-256 88691166216d67bd23dcc8da7f08aedd76db46af88addd9a4caa0b8d4a1ebb09

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