Skip to main content

rig_core/
lib.rs

1#![cfg_attr(docsrs, feature(doc_cfg))]
2#![cfg_attr(
3    test,
4    allow(
5        clippy::expect_used,
6        clippy::indexing_slicing,
7        clippy::panic,
8        clippy::unwrap_used,
9        clippy::unreachable
10    )
11)]
12//! Rig is a Rust library for building LLM-powered applications that focuses on ergonomics and modularity.
13//!
14//! # Table of contents
15//! - [High-level features](#high-level-features)
16//! - [Simple Example](#simple-example)
17//! - [Core Concepts](#core-concepts)
18//! - [Integrations](#integrations)
19//!
20//! # High-level features
21//! - Full support for LLM completion and embedding workflows
22//! - Simple but powerful common abstractions over LLM providers (e.g. OpenAI, Cohere) and vector stores (e.g. MongoDB, in-memory)
23//! - Integrate LLMs in your app with minimal boilerplate
24//!
25//! # Simple example
26//! ```ignore
27//! use rig_core::{
28//!     client::{CompletionClient, ProviderClient},
29//!     completion::Prompt,
30//!     providers::openai,
31//! };
32//!
33//! #[tokio::main]
34//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
35//!     // Create OpenAI client and agent.
36//!     // This requires the `OPENAI_API_KEY` environment variable to be set.
37//!     let openai_client = openai::Client::from_env()?;
38//!
39//!     let agent = openai_client.agent(openai::GPT_5_2).build();
40//!
41//!     // Prompt the model and print its response
42//!     let response = agent
43//!         .prompt("Who are you?")
44//!         .await?;
45//!
46//!     println!("{response}");
47//!
48//!     Ok(())
49//! }
50//! ```
51//! Note: using `#[tokio::main]` requires you enable tokio's `macros` and `rt-multi-thread` features
52//! or just `full` to enable all features (`cargo add tokio --features macros,rt-multi-thread`).
53//!
54//! # Core concepts
55//! ## Completion and embedding models
56//! Rig provides a consistent API for working with LLMs and embeddings. Specifically,
57//! each provider (e.g. OpenAI, Cohere) has a `Client` struct that can be used to initialize completion
58//! and embedding models. These models implement the [CompletionModel](crate::completion::CompletionModel)
59//! and [EmbeddingModel](crate::embeddings::EmbeddingModel) traits respectively, which provide a common,
60//! low-level interface for creating completion and embedding requests and executing them.
61//!
62//! ## Agents
63//! Rig also provides high-level abstractions over LLMs in the form of the [Agent](crate::agent::Agent) type.
64//!
65//! The [Agent](crate::agent::Agent) type can be used to create anything from simple agents that use vanilla models to full blown
66//! RAG systems that can be used to answer questions using a knowledge base.
67//!
68//! ## Vector stores and indexes
69//! Rig provides a common interface for working with vector stores and indexes. Specifically, the library
70//! provides the [VectorStoreIndex](crate::vector_store::VectorStoreIndex)
71//! trait, which can be implemented to define vector stores and indices respectively.
72//! Those can then be used as the knowledge base for a RAG enabled [Agent](crate::agent::Agent), or
73//! as a source of context documents in a custom architecture that use multiple LLMs or agents.
74//!
75//! ## Conversation memory
76//! Rig can transparently load and persist per-conversation history through the
77//! [ConversationMemory](crate::memory::ConversationMemory) trait. Attach a backend
78//! with [`AgentBuilder::memory`](crate::agent::AgentBuilder::memory) and identify the
79//! conversation per-request via
80//! [`PromptRequest::conversation`](crate::agent::prompt_request::PromptRequest::conversation).
81//! The default in-process backend
82//! [InMemoryConversationMemory](crate::memory::InMemoryConversationMemory) is suitable
83//! for tests and single-process agents; reusable history-shaping policies (sliding
84//! window, token budget) live in the [`rig-memory`](https://crates.io/crates/rig-memory)
85//! companion crate. See [`examples/agent_with_memory.rs`](https://github.com/0xPlaygrounds/rig/blob/main/examples/agent_with_memory.rs)
86//! for a runnable end-to-end example.
87//!
88//! # Integrations
89//! ## Model Providers
90//! Rig natively supports the following completion and embedding model provider integrations:
91//! - Anthropic
92//! - Azure OpenAI
93//! - ChatGPT and GitHub Copilot auth-backed clients
94//! - Cohere
95//! - DeepSeek
96//! - Gemini
97//! - Groq
98//! - Hugging Face
99//! - Hyperbolic
100//! - Llamafile
101//! - MiniMax
102//! - Mira
103//! - Mistral
104//! - Moonshot
105//! - Ollama
106//! - OpenAI
107//! - OpenRouter
108//! - Perplexity
109//! - Together
110//! - Voyage AI
111//! - xAI
112//! - Xiaomi MiMo
113//! - Z.ai
114//!
115//! You can also implement your own model provider integration by defining types that
116//! implement the [CompletionModel](crate::completion::CompletionModel) and [EmbeddingModel](crate::embeddings::EmbeddingModel) traits.
117//!
118//! Vector stores are available as separate companion-crates:
119//!
120//! - MongoDB: [`rig-mongodb`](https://github.com/0xPlaygrounds/rig/tree/main/crates/rig-mongodb)
121//! - LanceDB: [`rig-lancedb`](https://github.com/0xPlaygrounds/rig/tree/main/crates/rig-lancedb)
122//! - Neo4j: [`rig-neo4j`](https://github.com/0xPlaygrounds/rig/tree/main/crates/rig-neo4j)
123//! - Qdrant: [`rig-qdrant`](https://github.com/0xPlaygrounds/rig/tree/main/crates/rig-qdrant)
124//! - SQLite: [`rig-sqlite`](https://github.com/0xPlaygrounds/rig/tree/main/crates/rig-sqlite)
125//! - SurrealDB: [`rig-surrealdb`](https://github.com/0xPlaygrounds/rig/tree/main/crates/rig-surrealdb)
126//! - Milvus: [`rig-milvus`](https://github.com/0xPlaygrounds/rig/tree/main/crates/rig-milvus)
127//! - ScyllaDB: [`rig-scylladb`](https://github.com/0xPlaygrounds/rig/tree/main/crates/rig-scylladb)
128//! - AWS S3Vectors: [`rig-s3vectors`](https://github.com/0xPlaygrounds/rig/tree/main/crates/rig-s3vectors)
129//! - HelixDB: [`rig-helixdb`](https://github.com/0xPlaygrounds/rig/tree/main/crates/rig-helixdb)
130//! - Cloudflare Vectorize: [`rig-vectorize`](https://github.com/0xPlaygrounds/rig/tree/main/crates/rig-vectorize)
131//!
132//! You can also implement your own vector store integration by defining types that
133//! implement the [VectorStoreIndex](crate::vector_store::VectorStoreIndex) trait.
134//!
135//! The following providers are available as separate companion-crates:
136//!
137//! - AWS Bedrock: [`rig-bedrock`](https://github.com/0xPlaygrounds/rig/tree/main/crates/rig-bedrock)
138//! - Fastembed: [`rig-fastembed`](https://github.com/0xPlaygrounds/rig/tree/main/crates/rig-fastembed)
139//! - Google Gemini gRPC: [`rig-gemini-grpc`](https://github.com/0xPlaygrounds/rig/tree/main/crates/rig-gemini-grpc)
140//! - Google Vertex AI: [`rig-vertexai`](https://github.com/0xPlaygrounds/rig/tree/main/crates/rig-vertexai)
141//!
142
143extern crate self as rig;
144
145pub mod agent;
146#[cfg(feature = "audio")]
147#[cfg_attr(docsrs, doc(cfg(feature = "audio")))]
148pub mod audio_generation;
149pub mod client;
150pub mod completion;
151pub mod embeddings;
152pub mod extractor;
153pub mod http_client;
154pub mod id;
155#[cfg(feature = "image")]
156#[cfg_attr(docsrs, doc(cfg(feature = "image")))]
157pub mod image_generation;
158pub mod integrations;
159pub(crate) mod json_utils;
160pub mod loaders;
161pub mod markers;
162pub mod memory;
163pub mod model;
164pub mod one_or_many;
165pub mod prelude;
166pub(crate) mod provider_response;
167pub mod providers;
168pub mod rerank;
169
170pub mod streaming;
171#[cfg(any(test, feature = "test-utils"))]
172#[cfg_attr(docsrs, doc(cfg(feature = "test-utils")))]
173pub mod test_utils;
174pub mod tool;
175pub mod transcription;
176pub mod vector_store;
177pub mod wasm_compat;
178
179// Re-export commonly used types and traits
180pub use completion::message;
181pub use embeddings::Embed;
182pub use extractor::ExtractionResponse;
183pub use one_or_many::{EmptyListError, OneOrMany};
184pub use provider_response::ProviderResponseError;
185pub use schemars;
186
187#[cfg(feature = "derive")]
188#[cfg_attr(docsrs, doc(cfg(feature = "derive")))]
189pub use rig_derive::{Embed, rig_tool as tool_macro};
190
191pub mod telemetry;