rig/
lib.rs

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