rig/lib.rs
1//! Rig is a Rust library for building LLM-powered applications that focuses on ergonomics and modularity.
2//!
3//! # Table of contents
4//! - [High-level features](#high-level-features)
5//! - [Simple Example](#simple-example)
6//! - [Core Concepts](#core-concepts)
7//! - [Integrations](#integrations)
8//!
9//! # High-level features
10//! - Full support for LLM completion and embedding workflows
11//! - Simple but powerful common abstractions over LLM providers (e.g. OpenAI, Cohere) and vector stores (e.g. MongoDB, in-memory)
12//! - Integrate LLMs in your app with minimal boilerplate
13//!
14//! # Simple example:
15//! ```
16//! use rig::{completion::Prompt, providers::openai};
17//!
18//! #[tokio::main]
19//! async fn main() {
20//! // Create OpenAI client and agent.
21//! // This requires the `OPENAI_API_KEY` environment variable to be set.
22//! let openai_client = openai::Client::from_env();
23//!
24//! let gpt4 = openai_client.agent("gpt-4").build();
25//!
26//! // Prompt the model and print its response
27//! let response = gpt4
28//! .prompt("Who are you?")
29//! .await
30//! .expect("Failed to prompt GPT-4");
31//!
32//! println!("GPT-4: {response}");
33//! }
34//! ```
35//! Note: using `#[tokio::main]` requires you enable tokio's `macros` and `rt-multi-thread` features
36//! or just `full` to enable all features (`cargo add tokio --features macros,rt-multi-thread`).
37//!
38//! # Core concepts
39//! ## Completion and embedding models
40//! Rig provides a consistent API for working with LLMs and embeddings. Specifically,
41//! each provider (e.g. OpenAI, Cohere) has a `Client` struct that can be used to initialize completion
42//! and embedding models. These models implement the [CompletionModel](crate::completion::CompletionModel)
43//! and [EmbeddingModel](crate::embeddings::EmbeddingModel) traits respectively, which provide a common,
44//! low-level interface for creating completion and embedding requests and executing them.
45//!
46//! ## Agents
47//! Rig also provides high-level abstractions over LLMs in the form of the [Agent](crate::agent::Agent) type.
48//!
49//! The [Agent](crate::agent::Agent) type can be used to create anything from simple agents that use vanilla models to full blown
50//! RAG systems that can be used to answer questions using a knowledge base.
51//!
52//! ## Vector stores and indexes
53//! Rig provides a common interface for working with vector stores and indexes. Specifically, the library
54//! provides the [VectorStoreIndex](crate::vector_store::VectorStoreIndex)
55//! trait, which can be implemented to define vector stores and indices respectively.
56//! Those can then be used as the knowledge base for a RAG enabled [Agent](crate::agent::Agent), or
57//! as a source of context documents in a custom architecture that use multiple LLMs or agents.
58//!
59//! # Integrations
60//! ## Model Providers
61//! Rig natively supports the following completion and embedding model provider integrations:
62//! - OpenAI
63//! - Cohere
64//! - Anthropic
65//! - Perplexity
66//! - Google Gemini
67//! - xAI
68//! - DeepSeek
69//!
70//! You can also implement your own model provider integration by defining types that
71//! implement the [CompletionModel](crate::completion::CompletionModel) and [EmbeddingModel](crate::embeddings::EmbeddingModel) traits.
72//!
73//! ## Vector Stores
74//! Rig currently supports the following vector store integrations via companion crates:
75//! - `rig-mongodb`: Vector store implementation for MongoDB
76//! - `rig-lancedb`: Vector store implementation for LanceDB
77//! - `rig-neo4j`: Vector store implementation for Neo4j
78//! - `rig-qdrant`: Vector store implementation for Qdrant
79//!
80//! You can also implement your own vector store integration by defining types that
81//! implement the [VectorStoreIndex](crate::vector_store::VectorStoreIndex) trait.
82
83extern crate self as rig;
84
85pub mod agent;
86#[cfg(feature = "audio")]
87pub mod audio_generation;
88pub mod cli_chatbot;
89pub mod client;
90pub mod completion;
91pub mod embeddings;
92pub mod extractor;
93#[cfg(feature = "image")]
94pub mod image_generation;
95pub(crate) mod json_utils;
96pub mod loaders;
97pub mod one_or_many;
98pub mod pipeline;
99pub mod prelude;
100pub mod providers;
101pub mod streaming;
102pub mod tool;
103pub mod transcription;
104pub mod vector_store;
105
106// Re-export commonly used types and traits
107pub use completion::message;
108pub use embeddings::Embed;
109pub use one_or_many::{EmptyListError, OneOrMany};
110
111#[cfg(feature = "derive")]
112pub use rig_derive::Embed;