rag_qdrant_comparison/
rag_qdrant_comparison.rs1use helios_engine::{Agent, Config, RAGTool};
18
19async fn demonstrate_in_memory() -> helios_engine::Result<()> {
20 println!("=== IN-MEMORY RAG DEMONSTRATION ===\n");
21
22 let api_key = std::env::var("OPENAI_API_KEY").unwrap_or_else(|_| {
23 println!("⚠ Warning: OPENAI_API_KEY not set. Using placeholder.");
24 "your-api-key-here".to_string()
25 });
26
27 let config = Config::from_file("config.toml").unwrap_or_else(|_| Config::new_default());
28
29 let rag_tool = RAGTool::new_in_memory("https://api.openai.com/v1/embeddings", &api_key);
31
32 let mut agent = Agent::builder("InMemoryAgent")
33 .config(config)
34 .system_prompt("You are a helpful assistant with in-memory RAG capabilities.")
35 .tool(Box::new(rag_tool))
36 .max_iterations(8)
37 .build()
38 .await?;
39
40 println!("✓ In-memory agent created\n");
41
42 println!("Adding documents...");
44 agent.chat("Store: The capital of France is Paris.").await?;
45 agent
46 .chat("Store: The capital of Germany is Berlin.")
47 .await?;
48 agent.chat("Store: The capital of Italy is Rome.").await?;
49 println!("✓ Documents added\n");
50
51 println!("Searching...");
53 let response = agent.chat("What is the capital of Germany?").await?;
54 println!("Agent: {}\n", response);
55
56 println!("Advantages of in-memory:");
57 println!(" ✓ No external dependencies");
58 println!(" ✓ Fast and simple");
59 println!(" ✓ Perfect for development");
60 println!(" ✗ No persistence (data lost on restart)");
61 println!(" ✗ Limited scalability\n");
62
63 Ok(())
64}
65
66async fn demonstrate_qdrant() -> helios_engine::Result<()> {
67 println!("=== QDRANT RAG DEMONSTRATION ===\n");
68
69 let api_key = std::env::var("OPENAI_API_KEY").unwrap_or_else(|_| {
70 println!("⚠ Warning: OPENAI_API_KEY not set. Using placeholder.");
71 "your-api-key-here".to_string()
72 });
73
74 let config = Config::from_file("config.toml").unwrap_or_else(|_| Config::new_default());
75
76 let rag_tool = RAGTool::new_qdrant(
78 "http://localhost:6333",
79 "comparison_demo",
80 "https://api.openai.com/v1/embeddings",
81 &api_key,
82 );
83
84 let mut agent = Agent::builder("QdrantAgent")
85 .config(config)
86 .system_prompt("You are a helpful assistant with Qdrant RAG capabilities.")
87 .tool(Box::new(rag_tool))
88 .max_iterations(8)
89 .build()
90 .await?;
91
92 println!("✓ Qdrant agent created\n");
93
94 println!("Clearing existing data...");
96 agent.chat("Clear all documents").await?;
97 println!("✓ Cleared\n");
98
99 println!("Adding documents...");
101 agent
102 .chat("Store: The Eiffel Tower is located in Paris, France.")
103 .await?;
104 agent
105 .chat("Store: The Colosseum is located in Rome, Italy.")
106 .await?;
107 agent
108 .chat("Store: The Brandenburg Gate is located in Berlin, Germany.")
109 .await?;
110 println!("✓ Documents added\n");
111
112 println!("Searching...");
114 let response = agent.chat("What famous landmark is in Berlin?").await?;
115 println!("Agent: {}\n", response);
116
117 println!("Advantages of Qdrant:");
118 println!(" ✓ Persistent storage");
119 println!(" ✓ Highly scalable");
120 println!(" ✓ Production-ready");
121 println!(" ✓ Advanced features (filtering, etc.)");
122 println!(" ✗ Requires external service");
123 println!(" ✗ More complex setup\n");
124
125 Ok(())
126}
127
128#[tokio::main]
129async fn main() -> helios_engine::Result<()> {
130 println!("🚀 Helios Engine - RAG Backend Comparison");
131 println!("=========================================\n");
132
133 match demonstrate_in_memory().await {
135 Ok(_) => println!("✅ In-memory demonstration completed\n"),
136 Err(e) => println!("❌ In-memory demonstration failed: {}\n", e),
137 }
138
139 println!("---\n");
140
141 match demonstrate_qdrant().await {
143 Ok(_) => println!("✅ Qdrant demonstration completed\n"),
144 Err(e) => {
145 println!("❌ Qdrant demonstration failed: {}", e);
146 println!(" (Make sure Qdrant is running: docker run -p 6333:6333 qdrant/qdrant)\n");
147 }
148 }
149
150 println!("\n📊 Comparison Summary:");
151 println!("┌──────────────────┬────────────────┬──────────────┐");
152 println!("│ Feature │ In-Memory │ Qdrant │");
153 println!("├──────────────────┼────────────────┼──────────────┤");
154 println!("│ Setup │ Easy │ Moderate │");
155 println!("│ Dependencies │ None │ Qdrant │");
156 println!("│ Persistence │ No │ Yes │");
157 println!("│ Scalability │ Limited │ High │");
158 println!("│ Performance │ Fast (in-mem) │ Fast │");
159 println!("│ Best for │ Dev/Testing │ Production │");
160 println!("└──────────────────┴────────────────┴──────────────┘");
161
162 println!("\n💡 Recommendations:");
163 println!(" • Use in-memory for: development, testing, demos");
164 println!(" • Use Qdrant for: production, large datasets, persistence");
165
166 Ok(())
167}