QdrantRAGTool

Struct QdrantRAGTool 

Source
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

Source

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

Creates a new QdrantRAGTool.

Examples found in repository?
examples/agent_with_rag.rs (lines 40-45)
23async fn main() -> helios_engine::Result<()> {
24    println!("🚀 Helios Engine - Agent with RAG Example");
25    println!("==========================================\n");
26
27    // Check for the required OpenAI API key.
28    let embedding_api_key = std::env::var("OPENAI_API_KEY").unwrap_or_else(|_| {
29        println!("⚠ Warning: OPENAI_API_KEY not set. Using placeholder.");
30        "your-api-key-here".to_string()
31    });
32
33    // Load configuration from `config.toml` or use default.
34    let config = Config::from_file("config.toml").unwrap_or_else(|_| {
35        println!("⚠ No config.toml found, using default configuration");
36        Config::new_default()
37    });
38
39    // Create a new `QdrantRAGTool`.
40    let rag_tool = QdrantRAGTool::new(
41        "http://localhost:6333",                // Qdrant URL
42        "helios_knowledge",                     // Collection name
43        "https://api.openai.com/v1/embeddings", // Embedding API
44        embedding_api_key,                      // API key
45    );
46
47    // Create an agent named "KnowledgeAgent" and equip it with the RAG tool.
48    let mut agent = Agent::builder("KnowledgeAgent")
49        .config(config)
50        .system_prompt(
51            "You are a helpful assistant with access to a RAG (Retrieval-Augmented Generation) system. \
52             You can store documents and retrieve relevant information to answer questions. \
53             When answering questions, first search for relevant documents, then provide informed answers based on the retrieved context."
54        )
55        .tool(Box::new(rag_tool))
56        .max_iterations(10)
57        .build()
58        .await?;
59
60    println!("✓ Agent created with RAG capabilities\n");
61
62    // --- Example 1: Add knowledge to the database ---
63    println!("Example 1: Adding Documents to Knowledge Base");
64    println!("==============================================\n");
65
66    let response = agent
67        .chat(
68            "Store this information: Rust is a systems programming language that runs blazingly fast, \
69             prevents segfaults, and guarantees thread safety. It was created by Mozilla Research."
70        )
71        .await?;
72    println!("Agent: {}\n", response);
73
74    let response = agent
75        .chat(
76            "Store this: Python is a high-level, interpreted programming language known for its \
77             clear syntax and readability. It was created by Guido van Rossum in 1991.",
78        )
79        .await?;
80    println!("Agent: {}\n", response);
81
82    let response = agent
83        .chat(
84            "Store this: JavaScript is a programming language commonly used for web development. \
85             It allows developers to create interactive web pages and runs in web browsers.",
86        )
87        .await?;
88    println!("Agent: {}\n", response);
89
90    // --- Example 2: Semantic search - ask questions ---
91    println!("\nExample 2: Semantic Search and Q&A");
92    println!("===================================\n");
93
94    let response = agent
95        .chat("What programming language is known for preventing segfaults?")
96        .await?;
97    println!("Agent: {}\n", response);
98
99    let response = agent
100        .chat("Tell me about the programming language created in 1991")
101        .await?;
102    println!("Agent: {}\n", response);
103
104    // --- Example 3: Multi-document retrieval ---
105    println!("\nExample 3: Multi-Document Retrieval");
106    println!("====================================\n");
107
108    let response = agent
109        .chat("Search for information about programming languages and summarize what you find")
110        .await?;
111    println!("Agent: {}\n", response);
112
113    // --- Example 4: Adding documents with metadata ---
114    println!("\nExample 4: Documents with Metadata");
115    println!("===================================\n");
116
117    let response = agent
118        .chat(
119            "Store this with metadata: \
120             The Helios Engine is a Rust framework for building LLM agents. \
121             Metadata: category=framework, language=rust, year=2025",
122        )
123        .await?;
124    println!("Agent: {}\n", response);
125
126    println!("\n✅ Example completed successfully!");
127    println!("\n💡 Key Features Demonstrated:");
128    println!("  • Document embedding with OpenAI embeddings");
129    println!("  • Vector storage in Qdrant database");
130    println!("  • Semantic search with cosine similarity");
131    println!("  • RAG workflow for context-aware answers");
132    println!("  • Metadata support for document organization");
133
134    println!("\n📝 RAG Use Cases:");
135    println!("  • Question answering over custom knowledge bases");
136    println!("  • Document search and retrieval");
137    println!("  • Building chatbots with domain-specific knowledge");
138    println!("  • Information extraction from large document sets");
139
140    println!("\n🔧 Setup Instructions:");
141    println!("  1. Start Qdrant: docker run -p 6333:6333 qdrant/qdrant");
142    println!("  2. Set API key: export OPENAI_API_KEY=your-key");
143    println!("  3. Run example: cargo run --example agent_with_rag");
144
145    Ok(())
146}

Trait Implementations§

Source§

impl Clone for QdrantRAGTool

Source§

fn clone(&self) -> QdrantRAGTool

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Tool for QdrantRAGTool

Source§

fn name(&self) -> &str

The name of the tool.
Source§

fn description(&self) -> &str

A description of the tool.
Source§

fn parameters(&self) -> HashMap<String, ToolParameter>

The parameters for the tool.
Source§

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,

Executes the tool with the given arguments.
Source§

fn to_definition(&self) -> ToolDefinition

Converts the tool to a ToolDefinition.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more