pub struct QdrantRAGTool { /* private fields */ }Expand description
RAG (Retrieval-Augmented Generation) Tool with Qdrant Vector Database
Provides document embedding, storage, retrieval, and reranking capabilities. Supports operations: add_document, search, delete, list, clear
Implementations§
Source§impl QdrantRAGTool
impl QdrantRAGTool
Sourcepub fn new(
qdrant_url: impl Into<String>,
collection_name: impl Into<String>,
embedding_api_url: impl Into<String>,
embedding_api_key: impl Into<String>,
) -> Self
pub fn new( qdrant_url: impl Into<String>, collection_name: impl Into<String>, embedding_api_url: impl Into<String>, embedding_api_key: impl Into<String>, ) -> Self
Create a new RAG tool with Qdrant backend
Examples found in repository?
examples/agent_with_rag.rs (lines 33-38)
15async fn main() -> helios_engine::Result<()> {
16 println!("🚀 Helios Engine - Agent with RAG Example");
17 println!("==========================================\n");
18
19 // Check for required environment variables
20 let embedding_api_key = std::env::var("OPENAI_API_KEY")
21 .unwrap_or_else(|_| {
22 println!("⚠ Warning: OPENAI_API_KEY not set. Using placeholder.");
23 "your-api-key-here".to_string()
24 });
25
26 // Load configuration
27 let config = Config::from_file("config.toml").unwrap_or_else(|_| {
28 println!("⚠ No config.toml found, using default configuration");
29 Config::new_default()
30 });
31
32 // Create RAG tool with Qdrant backend
33 let rag_tool = QdrantRAGTool::new(
34 "http://localhost:6333", // Qdrant URL
35 "helios_knowledge", // Collection name
36 "https://api.openai.com/v1/embeddings", // Embedding API
37 embedding_api_key, // API key
38 );
39
40 // Create agent with RAG tool
41 let mut agent = Agent::builder("KnowledgeAgent")
42 .config(config)
43 .system_prompt(
44 "You are a helpful assistant with access to a RAG (Retrieval-Augmented Generation) system. \
45 You can store documents and retrieve relevant information to answer questions. \
46 When answering questions, first search for relevant documents, then provide informed answers based on the retrieved context."
47 )
48 .tool(Box::new(rag_tool))
49 .max_iterations(10)
50 .build()
51 .await?;
52
53 println!("✓ Agent created with RAG capabilities\n");
54
55 // Example 1: Add knowledge to the database
56 println!("Example 1: Adding Documents to Knowledge Base");
57 println!("==============================================\n");
58
59 let response = agent
60 .chat(
61 "Store this information: Rust is a systems programming language that runs blazingly fast, \
62 prevents segfaults, and guarantees thread safety. It was created by Mozilla Research."
63 )
64 .await?;
65 println!("Agent: {}\n", response);
66
67 let response = agent
68 .chat(
69 "Store this: Python is a high-level, interpreted programming language known for its \
70 clear syntax and readability. It was created by Guido van Rossum in 1991."
71 )
72 .await?;
73 println!("Agent: {}\n", response);
74
75 let response = agent
76 .chat(
77 "Store this: JavaScript is a programming language commonly used for web development. \
78 It allows developers to create interactive web pages and runs in web browsers."
79 )
80 .await?;
81 println!("Agent: {}\n", response);
82
83 // Example 2: Semantic search - ask questions
84 println!("\nExample 2: Semantic Search and Q&A");
85 println!("===================================\n");
86
87 let response = agent
88 .chat("What programming language is known for preventing segfaults?")
89 .await?;
90 println!("Agent: {}\n", response);
91
92 let response = agent
93 .chat("Tell me about the programming language created in 1991")
94 .await?;
95 println!("Agent: {}\n", response);
96
97 // Example 3: Multi-document retrieval
98 println!("\nExample 3: Multi-Document Retrieval");
99 println!("====================================\n");
100
101 let response = agent
102 .chat("Search for information about programming languages and summarize what you find")
103 .await?;
104 println!("Agent: {}\n", response);
105
106 // Example 4: Adding documents with metadata
107 println!("\nExample 4: Documents with Metadata");
108 println!("===================================\n");
109
110 let response = agent
111 .chat(
112 "Store this with metadata: \
113 The Helios Engine is a Rust framework for building LLM agents. \
114 Metadata: category=framework, language=rust, year=2024"
115 )
116 .await?;
117 println!("Agent: {}\n", response);
118
119 println!("\n✅ Example completed successfully!");
120 println!("\n💡 Key Features Demonstrated:");
121 println!(" • Document embedding with OpenAI embeddings");
122 println!(" • Vector storage in Qdrant database");
123 println!(" • Semantic search with cosine similarity");
124 println!(" • RAG workflow for context-aware answers");
125 println!(" • Metadata support for document organization");
126
127 println!("\n📝 RAG Use Cases:");
128 println!(" • Question answering over custom knowledge bases");
129 println!(" • Document search and retrieval");
130 println!(" • Building chatbots with domain-specific knowledge");
131 println!(" • Information extraction from large document sets");
132
133 println!("\n🔧 Setup Instructions:");
134 println!(" 1. Start Qdrant: docker run -p 6333:6333 qdrant/qdrant");
135 println!(" 2. Set API key: export OPENAI_API_KEY=your-key");
136 println!(" 3. Run example: cargo run --example agent_with_rag");
137
138 Ok(())
139}Trait Implementations§
Source§impl Clone for QdrantRAGTool
impl Clone for QdrantRAGTool
Source§fn clone(&self) -> QdrantRAGTool
fn clone(&self) -> QdrantRAGTool
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Tool for QdrantRAGTool
impl Tool for QdrantRAGTool
fn name(&self) -> &str
fn description(&self) -> &str
fn parameters(&self) -> HashMap<String, ToolParameter>
fn execute<'life0, 'async_trait>(
&'life0 self,
args: Value,
) -> Pin<Box<dyn Future<Output = Result<ToolResult>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn to_definition(&self) -> ToolDefinition
Auto Trait Implementations§
impl Freeze for QdrantRAGTool
impl !RefUnwindSafe for QdrantRAGTool
impl Send for QdrantRAGTool
impl Sync for QdrantRAGTool
impl Unpin for QdrantRAGTool
impl !UnwindSafe for QdrantRAGTool
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more