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.
@@ -138,6 +138,56 @@ run YourApp
138
138
 
139
139
  ## Grafana Dashboard
140
140
 
141
+ ### Live Dashboard Preview
142
+
143
+ Vectra includes a comprehensive Grafana dashboard with 11 professional panels for monitoring all aspects of your vector database operations:
144
+
145
+ <div class="tma-dashboard-showcase">
146
+ <div class="tma-dashboard-showcase__image">
147
+ <img src="{{ site.baseurl }}/grafana_final.png" alt="Vectra Grafana Dashboard - Real-time monitoring of vector database operations" class="tma-dashboard-screenshot">
148
+ </div>
149
+ <div class="tma-dashboard-showcase__features">
150
+ <h4>Dashboard Features</h4>
151
+ <ul>
152
+ <li><strong>Real-time Metrics:</strong> Request rate, latency, error tracking</li>
153
+ <li><strong>Performance Monitoring:</strong> P50, P95, P99 latency percentiles</li>
154
+ <li><strong>Cache Analytics:</strong> Hit ratio and performance metrics</li>
155
+ <li><strong>Provider Insights:</strong> Multi-provider comparison and distribution</li>
156
+ <li><strong>Connection Pooling:</strong> pgvector pool status and utilization</li>
157
+ <li><strong>Visual Analytics:</strong> Time series, pie charts, bar gauges</li>
158
+ </ul>
159
+ <div class="tma-dashboard-showcase__actions">
160
+ <a href="https://github.com/stokry/vectra/tree/main/examples#grafana-dashboard" class="tma-button tma-button--primary" target="_blank" rel="noopener">
161
+ Get Dashboard JSON →
162
+ </a>
163
+ <a href="https://github.com/stokry/vectra/blob/main/examples/GRAFANA_QUICKSTART.md" class="tma-button tma-button--secondary" target="_blank" rel="noopener">
164
+ Quick Start Guide →
165
+ </a>
166
+ </div>
167
+ </div>
168
+ </div>
169
+
170
+ ### Quick Setup
171
+
172
+ Get started in 5 minutes:
173
+
174
+ 1. **Start Prometheus Exporter:**
175
+ ```bash
176
+ gem install prometheus-client
177
+ ruby examples/prometheus-exporter.rb
178
+ ```
179
+
180
+ 2. **Import Dashboard:**
181
+ - Sign up at [grafana.com](https://grafana.com) (free tier available)
182
+ - Add Prometheus data source
183
+ - Import `examples/grafana-dashboard.json`
184
+
185
+ 3. **View Metrics:**
186
+ - Dashboard populates with real-time data
187
+ - Perfect for monitoring and screenshots
188
+
189
+ See the [Quick Start Guide](https://github.com/stokry/vectra/blob/main/examples/GRAFANA_QUICKSTART.md) for detailed setup instructions.
190
+
141
191
  ### Dashboard JSON Template
142
192
 
143
193
  Save as `vectra-dashboard.json` and import into Grafana:
@@ -16,6 +16,7 @@ Vectra supports multiple vector database providers. Choose the one that best fit
16
16
  | [**Qdrant**]({{ site.baseurl }}/providers/qdrant) | Open Source | Self-hosted, Performance |
17
17
  | [**Weaviate**]({{ site.baseurl }}/providers/weaviate) | Open Source | Semantic search, GraphQL |
18
18
  | [**pgvector**]({{ site.baseurl }}/providers/pgvector) | PostgreSQL | SQL integration, ACID |
19
+ | [**Memory**]({{ site.baseurl }}/providers/memory) | In-Memory | Testing, CI, local dev |
19
20
 
20
21
  ## Quick Comparison
21
22
 
@@ -75,6 +76,17 @@ client.upsert(vectors: [...])
75
76
  results = client.query(vector: [...], top_k: 5)
76
77
  ```
77
78
 
79
+ For **tests and CI** you can use the in-memory provider:
80
+
81
+ ```ruby
82
+ # config/initializers/vectra.rb (test environment)
83
+ Vectra.configure do |config|
84
+ config.provider = :memory if Rails.env.test?
85
+ end
86
+
87
+ client = Vectra::Client.new
88
+ ```
89
+
78
90
  ## Next Steps
79
91
 
80
92
  - [Getting Started Guide]({{ site.baseurl }}/guides/getting-started)
@@ -0,0 +1,145 @@
1
+ ---
2
+ layout: page
3
+ title: Memory Provider
4
+ permalink: /providers/memory/
5
+ ---
6
+
7
+ # Memory Provider
8
+
9
+ The **Memory provider** is an in-memory vector store built into Vectra.
10
+ It is designed **exclusively for testing, local development, and CI** – no external database required.
11
+
12
+ > Not for production use. All data lives in process memory and is lost when the process exits.
13
+
14
+ ## When to Use
15
+
16
+ - ✅ RSpec / Minitest suites (fast, isolated tests)
17
+ - ✅ Local development without provisioning Pinecone/Qdrant/Weaviate/pgvector
18
+ - ✅ CI pipelines where external services are not available
19
+ - ❌ Not suitable for production workloads
20
+
21
+ ## Setup
22
+
23
+ ### Global Configuration (Rails Example)
24
+
25
+ ```ruby
26
+ # config/initializers/vectra.rb
27
+ Vectra.configure do |config|
28
+ config.provider = :memory if Rails.env.test?
29
+ end
30
+ ```
31
+
32
+ Then in your application code:
33
+
34
+ ```ruby
35
+ client = Vectra::Client.new
36
+ ```
37
+
38
+ ### Direct Construction
39
+
40
+ ```ruby
41
+ require "vectra"
42
+
43
+ client = Vectra.memory
44
+ ```
45
+
46
+ No `host`, `api_key`, or environment configuration is required.
47
+
48
+ ## Features
49
+
50
+ - ✅ `upsert` – store vectors in memory
51
+ - ✅ `query` – cosine similarity search (with optional metadata filtering)
52
+ - ✅ `fetch` – retrieve vectors by ID
53
+ - ✅ `update` – merge metadata for existing vectors
54
+ - ✅ `delete` – delete by IDs, namespace, filter, or `delete_all`
55
+ - ✅ `list_indexes` / `describe_index` – basic index metadata (dimension, metric)
56
+ - ✅ `stats` – vector counts per namespace
57
+ - ✅ `clear!` – wipe all data between tests
58
+
59
+ ## Basic Usage
60
+
61
+ ```ruby
62
+ client = Vectra.memory
63
+
64
+ # Upsert
65
+ client.upsert(
66
+ index: "documents",
67
+ vectors: [
68
+ {
69
+ id: "doc-1",
70
+ values: [0.1, 0.2, 0.3],
71
+ metadata: { title: "Hello", category: "docs" }
72
+ }
73
+ ],
74
+ namespace: "test-suite"
75
+ )
76
+
77
+ # Query
78
+ results = client.query(
79
+ index: "documents",
80
+ vector: [0.1, 0.2, 0.3],
81
+ top_k: 5,
82
+ namespace: "test-suite",
83
+ filter: { category: "docs" },
84
+ include_metadata: true
85
+ )
86
+
87
+ results.each do |match|
88
+ puts "#{match.id}: #{match.metadata["title"]} (score=#{match.score.round(3)})"
89
+ end
90
+ ```
91
+
92
+ ## Metadata Filtering
93
+
94
+ The Memory provider supports a subset of the same filter operators as other providers:
95
+
96
+ ```ruby
97
+ results = client.query(
98
+ index: "products",
99
+ vector: query_embedding,
100
+ top_k: 10,
101
+ filter: {
102
+ status: ["active", "preview"], # IN
103
+ price: { "$gte" => 10, "$lte" => 100 },# range
104
+ brand: { "$ne" => "Acme" } # not equal
105
+ },
106
+ include_metadata: true
107
+ )
108
+ ```
109
+
110
+ Supported operators:
111
+
112
+ - Equality: `{ field: "value" }` or `{ field: { "$eq" => "value" } }`
113
+ - Inequality: `{ field: { "$ne" => "value" } }`
114
+ - Ranges: `{ field: { "$gt" => 10 } }`, `{ "$gte" => 10 }`, `{ "$lt" => 20 }`, `{ "$lte" => 20 }`
115
+ - Arrays / IN: `{ field: ["a", "b"] }` or `{ field: { "$in" => ["a", "b"] } }`
116
+
117
+ ## Resetting State Between Tests
118
+
119
+ The Memory provider exposes a `clear!` method to reset all in-memory state:
120
+
121
+ ```ruby
122
+ RSpec.describe "MyService" do
123
+ let(:client) { Vectra.memory }
124
+
125
+ before do
126
+ client.provider.clear! if client.provider.respond_to?(:clear!)
127
+ end
128
+
129
+ # your tests...
130
+ end
131
+ ```
132
+
133
+ You can also call `clear!` on the provider obtained from a regular `Vectra::Client`:
134
+
135
+ ```ruby
136
+ client = Vectra::Client.new(provider: :memory)
137
+ client.provider.clear!
138
+ ```
139
+
140
+ ## Limitations
141
+
142
+ - Not distributed – data lives only in the current Ruby process.
143
+ - No persistence – all vectors are lost when the process exits or `clear!` is called.
144
+ - Intended for **testing and development only**, not for production traffic.
145
+
@@ -18,53 +18,112 @@ docker run -p 8080:8080 semitechnologies/weaviate:latest
18
18
 
19
19
  ### Connect with Vectra
20
20
 
21
+ You can either use the convenience constructor:
22
+
23
+ ```ruby
24
+ client = Vectra.weaviate(
25
+ api_key: ENV["WEAVIATE_API_KEY"], # optional for local / required for cloud
26
+ host: "http://localhost:8080" # or your cloud endpoint
27
+ )
28
+ ```
29
+
30
+ or configure via `Vectra::Client`:
31
+
21
32
  ```ruby
22
33
  client = Vectra::Client.new(
23
34
  provider: :weaviate,
24
- host: 'localhost',
25
- port: 8080,
26
- class_name: 'Document'
35
+ api_key: ENV["WEAVIATE_API_KEY"],
36
+ host: "https://your-weaviate-instance"
27
37
  )
28
38
  ```
29
39
 
30
40
  ## Features
31
41
 
32
- - ✅ Upsert vectors
33
- - ✅ Query/search
34
- - ✅ Delete vectors
35
- - ✅ Class management
36
- - ✅ Metadata filtering
37
- - ✅ Semantic search
42
+ - ✅ Upsert vectors into Weaviate classes (per-index `class`)
43
+ - ✅ Vector similarity search via GraphQL `nearVector`
44
+ - ✅ Fetch by IDs
45
+ - ✅ Metadata filtering (exact match, ranges, arrays)
46
+ - ✅ Namespace support via `_namespace` property
47
+ - ✅ Delete by IDs or filter
48
+ - ✅ List and describe classes
49
+ - ✅ Basic stats via GraphQL `Aggregate`
38
50
 
39
- ## Example
51
+ ## Basic Example
40
52
 
41
53
  ```ruby
42
- # Initialize client
43
- client = Vectra::Client.new(
44
- provider: :weaviate,
45
- host: 'localhost',
46
- port: 8080
54
+ require "vectra"
55
+
56
+ client = Vectra.weaviate(
57
+ api_key: ENV["WEAVIATE_API_KEY"],
58
+ host: "https://your-weaviate-instance"
47
59
  )
48
60
 
61
+ index = "Document" # Weaviate class name
62
+
49
63
  # Upsert vectors
50
64
  client.upsert(
65
+ index: index,
51
66
  vectors: [
52
- { id: 'doc-1', values: [0.1, 0.2, 0.3], metadata: { category: 'news' } }
53
- ]
67
+ {
68
+ id: "doc-1",
69
+ values: [0.1, 0.2, 0.3],
70
+ metadata: {
71
+ title: "Getting started with Vectra",
72
+ category: "docs"
73
+ }
74
+ }
75
+ ],
76
+ namespace: "prod" # stored as _namespace property
54
77
  )
55
78
 
56
- # Search
57
- results = client.query(vector: [0.1, 0.2, 0.3], top_k: 5)
79
+ # Query with metadata filter
80
+ results = client.query(
81
+ index: index,
82
+ vector: [0.1, 0.2, 0.3],
83
+ top_k: 5,
84
+ namespace: "prod",
85
+ filter: { category: "docs" },
86
+ include_metadata: true
87
+ )
88
+
89
+ results.each do |match|
90
+ puts "#{match.id} (score=#{match.score.round(3)}): #{match.metadata["title"]}"
91
+ end
92
+ ```
93
+
94
+ ## Advanced Filtering
95
+
96
+ Vectra maps simple Ruby hashes to Weaviate `where` filters:
97
+
98
+ ```ruby
99
+ results = client.query(
100
+ index: "Document",
101
+ vector: query_embedding,
102
+ top_k: 10,
103
+ filter: {
104
+ category: "blog",
105
+ views: { "$gt" => 1000 },
106
+ tags: ["ruby", "vectra"] # ContainsAny
107
+ },
108
+ include_metadata: true
109
+ )
58
110
  ```
59
111
 
112
+ Supported operators:
113
+
114
+ - Equality: `{ field: "value" }` or `{ field: { "$eq" => "value" } }`
115
+ - Inequality: `{ field: { "$ne" => "value" } }`
116
+ - Ranges: `{ field: { "$gt" => 10 } }`, `{ "$gte" => 10 }`, `{ "$lt" => 20 }`, `{ "$lte" => 20 }`
117
+ - Arrays: `{ field: ["a", "b"] }` (contains any), `{ field: { "$in" => ["a", "b"] } }`
118
+
60
119
  ## Configuration Options
61
120
 
62
- | Option | Type | Required | Description |
63
- |--------|------|----------|-------------|
64
- | `host` | String | Yes | Weaviate host address |
65
- | `port` | Integer | Yes | Weaviate port (default: 8080) |
66
- | `class_name` | String | No | Class name for vectors |
67
- | `api_key` | String | No | API key if auth is enabled |
121
+ | Option | Type | Required | Description |
122
+ |----------|--------|----------|-----------------------------------------------|
123
+ | `host` | String | Yes | Weaviate base URL (`http://` or `https://`) |
124
+ | `api_key`| String | No* | API key if auth is enabled / cloud instances |
125
+
126
+ > `api_key` is optional for local, unsecured Weaviate; required for managed/cloud deployments.
68
127
 
69
128
  ## Documentation
70
129
 
@@ -0,0 +1,158 @@
1
+ # Grafana Dashboard - Quick Start for Screenshots
2
+
3
+ **Get beautiful dashboard screenshots in 5 minutes!**
4
+
5
+ ## Step-by-Step Guide
6
+
7
+ ### 1. Install Dependencies
8
+
9
+ ```bash
10
+ # Install prometheus-client gem
11
+ gem install prometheus-client
12
+
13
+ # Or add to Gemfile:
14
+ # gem 'prometheus-client'
15
+ ```
16
+
17
+ ### 2. Start Prometheus Exporter (Terminal 1)
18
+
19
+ ```bash
20
+ cd /path/to/vectra
21
+ ruby examples/prometheus-exporter.rb
22
+ ```
23
+
24
+ You should see:
25
+ ```
26
+ 🚀 Vectra Prometheus Exporter
27
+ 📊 Metrics endpoint: http://localhost:9394/metrics
28
+ 🌐 Web interface: http://localhost:9394
29
+ ```
30
+
31
+ **Keep this running!**
32
+
33
+ ### 3. Setup Grafana Cloud
34
+
35
+ 1. Go to [grafana.com](https://grafana.com) and sign up (free)
36
+ 2. Create a new organization
37
+ 3. Go to **Connections** → **Data Sources**
38
+ 4. Click **Add new data source**
39
+ 5. Select **Prometheus**
40
+ 6. Configure:
41
+ - **Name:** `Prometheus` (or any name)
42
+ - **URL:** `http://localhost:9394` (if using local)
43
+ - OR use Grafana Cloud's Prometheus (recommended)
44
+ 7. Click **Save & Test** (should show "Data source is working")
45
+
46
+ ### 4. Import Dashboard
47
+
48
+ 1. Go to **Dashboards** → **New** → **Import**
49
+ 2. Click **Upload JSON file**
50
+ 3. Select `examples/grafana-dashboard.json`
51
+ 4. Select your Prometheus data source
52
+ 5. Click **Import**
53
+
54
+ ### 5. View Dashboard
55
+
56
+ - Dashboard will appear with all panels
57
+ - Wait 1-2 minutes for metrics to accumulate
58
+ - Refresh dashboard (F5) to see new data
59
+
60
+ ### 6. Take Screenshots
61
+
62
+ **Option A: Browser Screenshot**
63
+ - Use browser dev tools (F12)
64
+ - Or use screenshot tool (Cmd+Shift+4 on Mac)
65
+
66
+ **Option B: Grafana Share**
67
+ - Click panel → **Share** → **Direct link rendered image**
68
+ - Or use **Export** → **Save as image**
69
+
70
+ ## Best Panels for Screenshots
71
+
72
+ ### 🎯 Top Recommendations:
73
+
74
+ 1. **Request Rate by Operation** (Time Series)
75
+ - Shows query, upsert, delete operations
76
+ - Clean lines, professional look
77
+ - Perfect for: Twitter, LinkedIn, blog posts
78
+
79
+ 2. **Latency Distribution** (P50, P95, P99)
80
+ - Three lines showing percentiles
81
+ - Shows performance depth
82
+ - Perfect for: Technical blog posts, documentation
83
+
84
+ 3. **Operations Distribution** (Pie Chart)
85
+ - Colorful, easy to understand
86
+ - Shows operation breakdown
87
+ - Perfect for: Overview posts, presentations
88
+
89
+ 4. **Top Row Stats** (4 Stat Panels)
90
+ - Total Requests, Error Rate, P95 Latency, Cache Hit Ratio
91
+ - Shows key metrics at a glance
92
+ - Perfect for: Hero images, feature highlights
93
+
94
+ ## Tips for Best Screenshots
95
+
96
+ ### Time Range
97
+ - Set to **"Last 15 minutes"** for demo screenshots
98
+ - Shows active, recent data
99
+
100
+ ### Theme
101
+ - Use **Dark theme** (Settings → Preferences)
102
+ - Looks more professional
103
+
104
+ ### Panel Settings
105
+ - Hide legend if too cluttered (Panel → Options → Legend)
106
+ - Add panel descriptions (Panel → Title → Description)
107
+
108
+ ### Data Density
109
+ - Let exporter run for 2-3 minutes before screenshot
110
+ - More data = better visualization
111
+
112
+ ## Troubleshooting
113
+
114
+ ### No Data Showing?
115
+
116
+ 1. **Check exporter is running:**
117
+ ```bash
118
+ curl http://localhost:9394/metrics | head -20
119
+ ```
120
+ Should show Prometheus metrics
121
+
122
+ 2. **Check Grafana data source:**
123
+ - Go to Data Sources
124
+ - Click "Test" button
125
+ - Should show "Data source is working"
126
+
127
+ 3. **Check dashboard queries:**
128
+ - Click panel → Edit
129
+ - Check if query returns data
130
+ - Try: `sum(vectra_requests_total)`
131
+
132
+ ### Metrics Not Appearing?
133
+
134
+ - Exporter generates metrics every 0.5-2 seconds
135
+ - Wait 1-2 minutes for data to accumulate
136
+ - Refresh dashboard (F5)
137
+
138
+ ## Next Steps
139
+
140
+ - Run comprehensive demo to generate real metrics:
141
+ ```bash
142
+ bundle exec ruby examples/comprehensive_demo.rb
143
+ ```
144
+
145
+ - See [grafana-setup.md](grafana-setup.md) for production setup
146
+
147
+ - Check [monitoring guide](../docs/guides/monitoring.md) for full monitoring setup
148
+
149
+ ## Example Screenshot Workflow
150
+
151
+ 1. ✅ Start exporter: `ruby examples/prometheus-exporter.rb`
152
+ 2. ✅ Import dashboard to Grafana
153
+ 3. ✅ Wait 2 minutes for data
154
+ 4. ✅ Set time range to "Last 15 minutes"
155
+ 5. ✅ Take screenshot of "Request Rate by Operation" panel
156
+ 6. ✅ Take screenshot of "Latency Distribution" panel
157
+ 7. ✅ Take screenshot of full dashboard
158
+ 8. ✅ Done! 🎉