From c1293dac4e3f790fef1bd173b52695ddd60eb76d Mon Sep 17 00:00:00 2001 From: Joshua Mo Date: Mon, 19 Jan 2026 10:39:06 +0000 Subject: [PATCH 1/2] docs: update code snippets --- pages/docs/quickstart/embeddings.mdx | 1 + pages/docs/quickstart/getting_started.mdx | 28 +++++++++++++---------- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/pages/docs/quickstart/embeddings.mdx b/pages/docs/quickstart/embeddings.mdx index c411963..4c3ac43 100644 --- a/pages/docs/quickstart/embeddings.mdx +++ b/pages/docs/quickstart/embeddings.mdx @@ -25,6 +25,7 @@ Below is an example of how you can use `rig` to embed some simple documents. ```rust use rig::{embeddings::EmbeddingsBuilder, providers::openai}; +use rig::client::{EmbeddingsClient, ProviderClient}; // Create OpenAI client and model // This requires the `OPENAI_API_KEY` environment variable to be set. diff --git a/pages/docs/quickstart/getting_started.mdx b/pages/docs/quickstart/getting_started.mdx index d4863f9..d73df0b 100644 --- a/pages/docs/quickstart/getting_started.mdx +++ b/pages/docs/quickstart/getting_started.mdx @@ -22,23 +22,27 @@ This will add the `rig-core` dependency in your Rust project, as well as Tokio w Below is a simple example of how you can use `rig` to prompt OpenAI's GPT-4 model: ```rust -use rig::{completion::Prompt, providers::openai}; +use rig::client::{CompletionClient, ProviderClient}; +use rig::completion::Prompt; +use rig::providers::openai; #[tokio::main] -async fn main() { - // Create OpenAI client and model - // This requires the `OPENAI_API_KEY` environment variable to be set. - let openai_client = openai::Client::from_env(); +async fn main() -> Result<(), anyhow::Error> { + // Create OpenAI client + let client = openai::Client::from_env(); - let gpt4 = openai_client.agent("gpt-4").build(); + // Create agent with a single context prompt + let comedian_agent = client + .agent("gpt-5.2") + .preamble("You are a comedian here to entertain the user using humour and jokes.") + .build(); - // Prompt the model and print its response - let response = gpt4 - .prompt("Who are you?") - .await - .expect("Failed to prompt GPT-4"); + // Prompt the agent and print the response + let response = comedian_agent.prompt("Entertain me!").await?; - println!("GPT-4: {response}"); + println!("{response}"); + + Ok(()) } ``` From de7ea5f1b2e9a5ff0f592e11da7bc781fa274621 Mon Sep 17 00:00:00 2001 From: Joshua Mo Date: Mon, 19 Jan 2026 10:53:52 +0000 Subject: [PATCH 2/2] chore: CI --- pages/docs/concepts/agent.mdx | 4 ++++ pages/docs/concepts/completion.mdx | 4 ++++ pages/docs/concepts/embeddings.mdx | 2 ++ pages/docs/concepts/extractors.mdx | 2 ++ pages/docs/concepts/loaders.mdx | 2 ++ pages/docs/integrations/model_providers/openai.mdx | 1 + pages/docs/integrations/vector_stores/in_memory.mdx | 4 ++++ pages/docs/integrations/vector_stores/lancedb.mdx | 4 ++++ pages/docs/integrations/vector_stores/mongodb.mdx | 1 + pages/guides/advanced/discord_bot.mdx | 5 +++++ 10 files changed, 29 insertions(+) diff --git a/pages/docs/concepts/agent.mdx b/pages/docs/concepts/agent.mdx index 0383518..87779b1 100644 --- a/pages/docs/concepts/agent.mdx +++ b/pages/docs/concepts/agent.mdx @@ -16,11 +16,13 @@ Agents in Rig provide a high-level abstraction for working with LLMs, combining An Agent consists of: 1. **Base Components** + - Completion Model (e.g., GPT-4, Claude) - System Prompt (preamble) - Configuration (temperature, max tokens) 2. **Context Management** + - Static Context: Always available documents - Dynamic Context: RAG-based contextual documents - Vector Store Integration @@ -140,11 +142,13 @@ Bear in mind that while prompt hooks are not blocking, it's generally advisable ## Best Practices 1. **Context Management** + - Keep static context minimal and focused - Use dynamic context for large knowledge bases - Consider context window limitations 2. **Tool Integration** + - Prefer static tools for core functionality - Use dynamic tools for context-specific operations - Implement proper error handling in tools diff --git a/pages/docs/concepts/completion.mdx b/pages/docs/concepts/completion.mdx index 91519cc..8e346e3 100644 --- a/pages/docs/concepts/completion.mdx +++ b/pages/docs/concepts/completion.mdx @@ -135,6 +135,7 @@ let request = model.completion_request("prompt") ### Request Components 1. **Core Elements** + - Prompt text - System preamble - Chat history @@ -142,6 +143,7 @@ let request = model.completion_request("prompt") - Max tokens 2. **Context Management** + - Document attachments - Metadata handling - Formatting controls @@ -240,11 +242,13 @@ impl CompletionModel for CustomProvider { ## Best Practices 1. **Interface Selection** + - Use `Prompt` for simple interactions - Use `Chat` for conversational flows - Use `Completion` for fine-grained control 2. **Error Handling** + - Handle provider-specific errors - Implement graceful fallbacks - Log raw responses for debugging diff --git a/pages/docs/concepts/embeddings.mdx b/pages/docs/concepts/embeddings.mdx index 28f8990..390f058 100644 --- a/pages/docs/concepts/embeddings.mdx +++ b/pages/docs/concepts/embeddings.mdx @@ -92,11 +92,13 @@ qdrant.insert_documents(embeddings).await?; ## Best Practices 1. **Document Preparation** + - Clean and normalize text before embedding - Consider chunking large documents - Remove irrelevant embedding content 2. **Error Handling** + - Handle provider API errors gracefully - Validate vector dimensions - Check for empty or invalid input diff --git a/pages/docs/concepts/extractors.mdx b/pages/docs/concepts/extractors.mdx index 58f636f..02d4208 100644 --- a/pages/docs/concepts/extractors.mdx +++ b/pages/docs/concepts/extractors.mdx @@ -130,11 +130,13 @@ impl Deserialize<'a> + Serialize + Send + Sync> Tool for ## Best Practices 1. **Structure Design** + - Use `Option` for optional fields - Keep structures focused and minimal - Document field requirements 2. **Error Handling** + - Handle both extraction and deserialization errors - Provide fallback values where appropriate - Log extraction failures for debugging diff --git a/pages/docs/concepts/loaders.mdx b/pages/docs/concepts/loaders.mdx index e014d68..7e0e4c4 100644 --- a/pages/docs/concepts/loaders.mdx +++ b/pages/docs/concepts/loaders.mdx @@ -130,11 +130,13 @@ impl Loadable for Result { ## Best Practices 1. **Error Handling** + - Use `ignore_errors()` for fault-tolerant processing - Handle specific error types when needed - Log errors appropriately 2. **Resource Management** + - Process files in batches - Consider memory usage with large files - Clean up temporary resources diff --git a/pages/docs/integrations/model_providers/openai.mdx b/pages/docs/integrations/model_providers/openai.mdx index dbd0c54..e02e066 100644 --- a/pages/docs/integrations/model_providers/openai.mdx +++ b/pages/docs/integrations/model_providers/openai.mdx @@ -54,6 +54,7 @@ let embedder = client.embedding_model(openai::TEXT_EMBEDDING_3_LARGE); 1. **Tool Calling**: OpenAI models support function calling through a specialized JSON format. The provider automatically handles conversion between Rig's tool definitions and OpenAI's expected format. 2. **Response Processing**: The provider implements special handling for: + - Tool/function call responses - System messages - Token usage tracking diff --git a/pages/docs/integrations/vector_stores/in_memory.mdx b/pages/docs/integrations/vector_stores/in_memory.mdx index 495d944..49b0c08 100644 --- a/pages/docs/integrations/vector_stores/in_memory.mdx +++ b/pages/docs/integrations/vector_stores/in_memory.mdx @@ -220,11 +220,13 @@ match store.get_document::("doc1") { ## Best Practices 1. **Memory Management**: + - Monitor memory usage with large datasets - Consider chunking large document additions - Use cloud-based vector stores for production deployments 2. **Document Structure**: + - Keep documents serializable - Avoid extremely large arrays - Consider using custom ID generation for meaningful identifiers @@ -237,11 +239,13 @@ match store.get_document::("doc1") { ## Limitations 1. **Scalability**: + - Limited by available RAM - No persistence between program runs - Single-machine only 2. **Features**: + - No built-in indexing optimizations - No metadata filtering - No automatic persistence diff --git a/pages/docs/integrations/vector_stores/lancedb.mdx b/pages/docs/integrations/vector_stores/lancedb.mdx index 9d1321b..1b02ed0 100644 --- a/pages/docs/integrations/vector_stores/lancedb.mdx +++ b/pages/docs/integrations/vector_stores/lancedb.mdx @@ -206,10 +206,12 @@ impl RecordBatchDeserializer for Vec { ## Best Practices 1. **Index Creation**: + - Minimum of 256 rows required for IVF-PQ indexing - Choose appropriate distance metrics based on your use case 2. **Schema Design**: + - Use appropriate data types for columns - Consider embedding dimension requirements @@ -220,10 +222,12 @@ impl RecordBatchDeserializer for Vec { ## Limitations and Considerations 1. **Data Size**: + - Local storage is suitable for smaller datasets - Use cloud storage for large-scale deployments 2. **Index Requirements**: + - IVF-PQ index requires minimum dataset size - Consider memory requirements for large indices diff --git a/pages/docs/integrations/vector_stores/mongodb.mdx b/pages/docs/integrations/vector_stores/mongodb.mdx index 1575e29..45b28c8 100644 --- a/pages/docs/integrations/vector_stores/mongodb.mdx +++ b/pages/docs/integrations/vector_stores/mongodb.mdx @@ -136,6 +136,7 @@ The collection must have a vector search index configured: ## Special Considerations 1. **Index Validation**: The implementation automatically validates: + - Index existence - Vector dimensions - Similarity metric diff --git a/pages/guides/advanced/discord_bot.mdx b/pages/guides/advanced/discord_bot.mdx index fda13c2..9f90caf 100644 --- a/pages/guides/advanced/discord_bot.mdx +++ b/pages/guides/advanced/discord_bot.mdx @@ -443,11 +443,13 @@ Let's break down the process: 1. When an interaction is received, we first check if it's a slash command using the `Interaction::ApplicationCommand` enum variant. 2. If it's a slash command, we match on the command name to determine the appropriate action. + - For the `"hello"` command, we respond with a simple greeting message. - For the `"ask"` command, we extract the user's query from the command options. If no query is provided, we use a default message. 3. If the command is `"ask"`, we pass the user's query to the Rig agent's `process_message` method to generate a response. + - If the Rig agent successfully generates a response, we send it back to the user. - If an error occurs during processing, we log the error and send an error message to the user. @@ -511,6 +513,7 @@ Here's how the message handling works: 3. If the bot's user ID is found, we remove the mention from the message content to extract the actual query. 4. We pass the processed message content to the Rig agent's `process_message` method to generate a response. + - If the Rig agent successfully generates a response, we send it back to the channel where the message was received using `msg.channel_id.say`. - If an error occurs during processing, we log the error and send an error message to the channel. @@ -567,6 +570,7 @@ Here's what happens in the `ready` event handler: 3. We store the bot's user ID in the `TypeMap` using the `BotUserId` key. This allows us to access the bot's user ID in other event handlers. 4. We create global slash commands using the `Command::set_global_application_commands` method. + - We define two commands: `"hello"` and `"ask"`. - The `"hello"` command is a simple command that greets the user. @@ -674,6 +678,7 @@ To invite the bot to your Discord server, follow these steps: Once the bot is running and invited to your server, you can test its functionality: - **Slash Commands**: + - Type `/hello` to receive a greeting. - Use `/ask` followed by a question to interact with the bot and receive a response generated by the Rig agent.