vectra-client 0.3.3 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,332 @@
1
+ # Vectra Examples
2
+
3
+ This directory contains comprehensive examples demonstrating Vectra's capabilities.
4
+
5
+ ## Prerequisites
6
+
7
+ ### For Qdrant examples:
8
+ ```bash
9
+ # Start Qdrant locally with Docker
10
+ docker run -p 6333:6333 qdrant/qdrant
11
+
12
+ # Or install Qdrant directly
13
+ brew install qdrant
14
+ qdrant
15
+ ```
16
+
17
+ ### For pgvector examples:
18
+ ```bash
19
+ # Install PostgreSQL with pgvector
20
+ brew install postgresql pgvector
21
+
22
+ # Start PostgreSQL
23
+ brew services start postgresql
24
+
25
+ # Create database and enable extension
26
+ createdb vectra_demo
27
+ psql vectra_demo -c "CREATE EXTENSION vector;"
28
+ ```
29
+
30
+ ## Examples
31
+
32
+ ### 1. **Comprehensive Demo** (`comprehensive_demo.rb`)
33
+
34
+ **⭐ START HERE** - Complete production-ready demonstration of all Vectra features.
35
+
36
+ ```bash
37
+ bundle exec ruby examples/comprehensive_demo.rb
38
+ ```
39
+
40
+ **What it demonstrates:**
41
+ - ✅ Basic CRUD operations (Create, Read, Update, Delete)
42
+ - ✅ Batch processing (50+ documents)
43
+ - ✅ **Async batch operations** (concurrent processing)
44
+ - ✅ **Streaming queries** (memory-efficient large result sets)
45
+ - ✅ Advanced queries with metadata filtering
46
+ - ✅ Update operations (metadata and vectors)
47
+ - ✅ Multiple delete strategies
48
+ - ✅ Cache performance (3-5x speedup)
49
+ - ✅ Error handling & resilience
50
+ - ✅ **Rate limiting** (proactive throttling)
51
+ - ✅ **Circuit breaker** (failover pattern)
52
+ - ✅ Multi-tenancy with namespaces
53
+ - ✅ Health monitoring & statistics
54
+ - ✅ **Structured JSON logging**
55
+ - ✅ **Audit logging** (compliance)
56
+ - ✅ **Error tracking** (Sentry, Honeybadger)
57
+
58
+ **Output preview:**
59
+ ```
60
+ ================================================================================
61
+ VECTRA COMPREHENSIVE DEMO
62
+ ================================================================================
63
+
64
+ Provider: Qdrant
65
+ Host: http://localhost:6333
66
+ Index: documents
67
+ Dimension: 128
68
+
69
+ ────────────────────────────────────────────────────────────────────────────────
70
+ │ 1. Basic CRUD Operations
71
+ ────────────────────────────────────────────────────────────────────────────────
72
+
73
+ 🏥 Checking system health...
74
+ ✅ System healthy (3.21ms latency)
75
+
76
+ 📦 Creating index 'documents'...
77
+ ✅ Index created
78
+
79
+ 📝 Inserting single document...
80
+ ✅ Inserted 1 document
81
+
82
+ [... continues with 13 sections ...]
83
+
84
+ 📊 Operations Summary:
85
+ Total operations: 60+
86
+ Cache hits: 2
87
+ Errors handled: 3
88
+ Retries: 0
89
+
90
+ 🎯 Features Demonstrated:
91
+ ✅ Basic CRUD operations
92
+ ✅ Batch processing
93
+ ✅ Async batch operations
94
+ ✅ Streaming queries
95
+ ✅ Advanced queries with filtering
96
+ ✅ Update operations
97
+ ✅ Delete operations
98
+ ✅ Caching & performance
99
+ ✅ Error handling
100
+ ✅ Multi-tenancy (namespaces)
101
+ ✅ Health monitoring
102
+ ✅ Rate limiting
103
+ ✅ Circuit breaker
104
+ ✅ Monitoring & logging
105
+
106
+ ✅ Demo completed successfully!
107
+ ```
108
+
109
+ **Run with cleanup:**
110
+ ```bash
111
+ bundle exec ruby examples/comprehensive_demo.rb --cleanup
112
+ ```
113
+
114
+ ---
115
+
116
+ ### 2. **Blog Search Engine** (`blog_search_engine.rb`)
117
+
118
+ Simple semantic search engine for blog posts with caching.
119
+
120
+ ```bash
121
+ bundle exec ruby examples/blog_search_engine.rb
122
+ ```
123
+
124
+ **Features:**
125
+ - Blog post indexing with metadata
126
+ - Semantic search with category filtering
127
+ - Cache performance testing
128
+ - Simple embedding generation
129
+
130
+ **Best for:**
131
+ - Learning the basics
132
+ - Understanding semantic search
133
+ - Quick prototyping
134
+
135
+ ---
136
+
137
+ ## Running Examples
138
+
139
+ ### Basic Usage
140
+
141
+ ```bash
142
+ # Run with default settings (localhost:6333)
143
+ bundle exec ruby examples/comprehensive_demo.rb
144
+
145
+ # Specify custom host
146
+ bundle exec ruby examples/comprehensive_demo.rb http://your-qdrant-host:6333
147
+
148
+ # Run with cleanup
149
+ bundle exec ruby examples/comprehensive_demo.rb --cleanup
150
+ ```
151
+
152
+ ### Troubleshooting
153
+
154
+ **"Cannot connect to Qdrant"**
155
+ ```bash
156
+ # Check if Qdrant is running
157
+ curl http://localhost:6333/health
158
+
159
+ # Start Qdrant if needed
160
+ docker run -p 6333:6333 qdrant/qdrant
161
+ ```
162
+
163
+ **"Index already exists"**
164
+ ```bash
165
+ # Run with cleanup flag
166
+ bundle exec ruby examples/comprehensive_demo.rb --cleanup
167
+ ```
168
+
169
+ **Performance issues**
170
+ ```bash
171
+ # Check Qdrant dashboard
172
+ open http://localhost:6333/dashboard
173
+ ```
174
+
175
+ ## Example Output Comparison
176
+
177
+ ### Comprehensive Demo
178
+ - **Operations:** 60+ operations across 13 sections
179
+ - **Duration:** ~10-15 seconds
180
+ - **Documents:** 80+ indexed
181
+ - **Features shown:** ALL major features including:
182
+ - Performance optimizations (async, streaming, caching)
183
+ - Resilience patterns (rate limiting, circuit breaker)
184
+ - Production monitoring (logging, audit, error tracking)
185
+
186
+ ### Blog Search Engine
187
+ - **Operations:** ~10 operations
188
+ - **Duration:** ~2-3 seconds
189
+ - **Documents:** 5-8 indexed
190
+ - **Features shown:** Basic CRUD + caching
191
+
192
+ ## Grafana Dashboard 📊
193
+
194
+ Create beautiful monitoring dashboards with Grafana - perfect for screenshots!
195
+
196
+ ### Quick Start (5 minutes)
197
+
198
+ 1. **Start Prometheus Exporter:**
199
+ ```bash
200
+ ruby examples/prometheus-exporter.rb
201
+ ```
202
+
203
+ 2. **Setup Grafana:**
204
+ - Sign up at [grafana.com](https://grafana.com) (free)
205
+ - Add Prometheus data source
206
+ - Import `examples/grafana-dashboard.json`
207
+
208
+ 3. **Take Screenshots:**
209
+ - Wait 1-2 minutes for metrics
210
+ - Use browser screenshot or Grafana's export feature
211
+ - Perfect panels: Request Rate, Latency Distribution, Pie Charts
212
+
213
+ **See [GRAFANA_QUICKSTART.md](GRAFANA_QUICKSTART.md) for step-by-step guide.**
214
+
215
+ ### Dashboard Features
216
+
217
+ - **12 Professional Panels:**
218
+ - Request rate, error rate, latency metrics
219
+ - Cache performance, connection pool status
220
+ - Time series, pie charts, bar gauges
221
+ - Color-coded thresholds
222
+
223
+ - **Perfect for Screenshots:**
224
+ - Clean, modern design
225
+ - Dark theme support
226
+ - Multiple visualization types
227
+ - Real-time data updates
228
+
229
+ See [grafana-setup.md](grafana-setup.md) for complete production setup.
230
+
231
+ ## Next Steps
232
+
233
+ 1. **Read the main README:** `../README.md`
234
+ 2. **Check the documentation:** [vectra-docs.netlify.app](https://vectra-docs.netlify.app/)
235
+ 3. **Explore the source code:** `../lib/vectra/`
236
+ 4. **Try with different providers:** Pinecone, Weaviate, pgvector
237
+ 5. **Build your own application!**
238
+
239
+ ## New Features in Comprehensive Demo
240
+
241
+ The comprehensive demo now includes **4 additional sections** demonstrating production-ready features:
242
+
243
+ ### Section 10: Async Batch Operations
244
+ - Concurrent batch upsert with configurable worker count
245
+ - Automatic chunking and error handling
246
+ - Performance metrics and throughput analysis
247
+
248
+ ### Section 11: Streaming Large Queries
249
+ - Memory-efficient query processing
250
+ - Batch-by-batch result streaming
251
+ - Perfect for large result sets without memory overflow
252
+
253
+ ### Section 12: Resilience Features
254
+ - **Rate Limiting**: Token bucket algorithm for smooth throttling
255
+ - **Circuit Breaker**: Automatic failover with state management
256
+ - Real-world resilience patterns
257
+
258
+ ### Section 13: Monitoring & Logging
259
+ - **Structured JSON Logging**: Machine-readable log format
260
+ - **Audit Logging**: Compliance-ready audit trails
261
+ - **Error Tracking**: Sentry and Honeybadger integration
262
+ - Production monitoring setup
263
+
264
+ In addition to the classic API, the demo now also showcases the **chainable Query Builder** style:
265
+
266
+ ```ruby
267
+ results = client
268
+ .query("documents")
269
+ .vector(embedding)
270
+ .top_k(10)
271
+ .filter(category: "ruby")
272
+ .with_metadata
273
+ .execute
274
+ ```
275
+
276
+ ## Tips for Production
277
+
278
+ ### Performance
279
+ ```ruby
280
+ # Use caching for frequently queried vectors
281
+ cache = Vectra::Cache.new(ttl: 600, max_size: 10000)
282
+ client = Vectra::CachedClient.new(base_client, cache: cache)
283
+
284
+ # Batch operations for efficiency
285
+ client.upsert(index: 'docs', vectors: large_batch)
286
+ ```
287
+
288
+ ### Error Handling
289
+ ```ruby
290
+ begin
291
+ client.query(index: 'docs', vector: embedding, top_k: 10)
292
+ rescue Vectra::NotFoundError => e
293
+ # Handle missing index
294
+ rescue Vectra::ValidationError => e
295
+ # Handle invalid input
296
+ rescue Vectra::ServerError => e
297
+ # Handle server errors
298
+ end
299
+ ```
300
+
301
+ ### Monitoring
302
+ ```ruby
303
+ # Regular health checks
304
+ health = client.health_check(include_stats: true)
305
+ puts "Latency: #{health.latency_ms}ms"
306
+ puts "Vector count: #{health.stats[:vector_count]}"
307
+ ```
308
+
309
+ ### Multi-tenancy
310
+ ```ruby
311
+ # Isolate tenant data with namespaces
312
+ client.upsert(
313
+ index: 'shared_index',
314
+ vectors: tenant_vectors,
315
+ namespace: "tenant-#{tenant_id}"
316
+ )
317
+
318
+ # Query only tenant's data
319
+ results = client.query(
320
+ index: 'shared_index',
321
+ vector: query_vec,
322
+ namespace: "tenant-#{tenant_id}"
323
+ )
324
+ ```
325
+
326
+ ## Contributing
327
+
328
+ Found an issue or want to add a new example? [Open an issue](https://github.com/stokry/vectra/issues) or submit a PR!
329
+
330
+ ## License
331
+
332
+ MIT - See [LICENSE](../LICENSE)