vectra-client 0.2.0 → 0.2.2
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +27 -14
- data/README.md +140 -328
- data/Rakefile +1 -1
- data/docs/Gemfile +10 -0
- data/docs/_config.yml +20 -0
- data/docs/_layouts/default.html +14 -0
- data/docs/_layouts/home.html +33 -0
- data/docs/_layouts/page.html +20 -0
- data/docs/_site/api/overview/index.html +145 -0
- data/docs/_site/assets/main.css +649 -0
- data/docs/_site/assets/main.css.map +1 -0
- data/docs/_site/assets/minima-social-icons.svg +33 -0
- data/docs/_site/assets/style.css +295 -0
- data/docs/_site/community/contributing/index.html +110 -0
- data/docs/_site/examples/basic-usage/index.html +117 -0
- data/docs/_site/examples/index.html +58 -0
- data/docs/_site/feed.xml +1 -0
- data/docs/_site/guides/getting-started/index.html +106 -0
- data/docs/_site/guides/installation/index.html +82 -0
- data/docs/_site/index.html +92 -0
- data/docs/_site/providers/index.html +119 -0
- data/docs/_site/providers/pgvector/index.html +155 -0
- data/docs/_site/providers/pinecone/index.html +121 -0
- data/docs/_site/providers/qdrant/index.html +124 -0
- data/docs/_site/providers/weaviate/index.html +123 -0
- data/docs/_site/robots.txt +1 -0
- data/docs/_site/sitemap.xml +39 -0
- data/docs/api/overview.md +126 -0
- data/docs/assets/style.css +295 -0
- data/docs/community/contributing.md +89 -0
- data/docs/examples/basic-usage.md +102 -0
- data/docs/examples/index.md +32 -0
- data/docs/guides/getting-started.md +90 -0
- data/docs/guides/installation.md +67 -0
- data/docs/index.md +53 -0
- data/docs/providers/index.md +62 -0
- data/docs/providers/pgvector.md +95 -0
- data/docs/providers/pinecone.md +72 -0
- data/docs/providers/qdrant.md +73 -0
- data/docs/providers/weaviate.md +72 -0
- data/lib/vectra/configuration.rb +10 -1
- data/lib/vectra/providers/base.rb +10 -0
- data/lib/vectra/providers/qdrant.rb +399 -12
- data/lib/vectra/version.rb +1 -1
- data/lib/vectra.rb +9 -2
- data/netlify.toml +12 -0
- metadata +43 -9
- data/IMPLEMENTATION_GUIDE.md +0 -686
- data/NEW_FEATURES_v0.2.0.md +0 -459
- data/RELEASE_CHECKLIST_v0.2.0.md +0 -383
- data/USAGE_EXAMPLES.md +0 -787
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 4fb1baf885e79af651a89ca695ead6a909a39c495241586ec3a46bdbecfb48ec
|
|
4
|
+
data.tar.gz: 9e7d3c14ea8108531821790c2d6d9f3d76901f122ab2d78472bf9ac6dbfc32dc
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b27299838743d313b9416e7c1d54f0bf694853df45526e9e6cdc51f3c2744b2254730100704ca980435ed982baf4d9341ce94a57e9eee8d9da3cc18ceb452fd1
|
|
7
|
+
data.tar.gz: a4a1ba817e2d094dde020471c63ec954f40de90e5389726b9c486da1aecd7140b80e3f4a0f4a773d654ccb75e3e65dd793bfd655ae749ae2c80a001e9a0259a8
|
data/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,33 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.2.1] - 2025-01-08
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- **Qdrant Provider** - Full Qdrant vector database support:
|
|
15
|
+
- Vector upsert, query, fetch, update, delete operations
|
|
16
|
+
- Collection management (create, list, describe, delete)
|
|
17
|
+
- Multiple similarity metrics: cosine, euclidean, dot product
|
|
18
|
+
- Namespace support via payload filtering
|
|
19
|
+
- Advanced metadata filtering with Qdrant operators ($eq, $ne, $gt, $gte, $lt, $lte, $in, $nin)
|
|
20
|
+
- Automatic point ID hashing for string IDs
|
|
21
|
+
- Support for both local and cloud Qdrant instances
|
|
22
|
+
- Optional API key authentication for local deployments
|
|
23
|
+
|
|
24
|
+
### Improved
|
|
25
|
+
|
|
26
|
+
- Enhanced error handling with `Faraday::RetriableResponse` support
|
|
27
|
+
- Configuration now allows optional API key for Qdrant and pgvector (local instances)
|
|
28
|
+
- Better retry middleware integration across all providers
|
|
29
|
+
|
|
30
|
+
### Provider Support
|
|
31
|
+
|
|
32
|
+
- ✅ Pinecone - Fully implemented
|
|
33
|
+
- ✅ pgvector (PostgreSQL) - Fully implemented
|
|
34
|
+
- ✅ Qdrant - Fully implemented
|
|
35
|
+
- 🚧 Weaviate - Stub implementation (planned for v0.3.0)
|
|
36
|
+
|
|
10
37
|
## [0.2.0] - 2025-01-08
|
|
11
38
|
|
|
12
39
|
### Added
|
|
@@ -49,13 +76,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
49
76
|
- Updated gemspec description to include pgvector
|
|
50
77
|
- Added `pg` gem as development dependency
|
|
51
78
|
|
|
52
|
-
### Provider Support
|
|
53
|
-
|
|
54
|
-
- ✅ Pinecone - Fully implemented
|
|
55
|
-
- ✅ pgvector (PostgreSQL) - Fully implemented
|
|
56
|
-
- 🚧 Qdrant - Stub implementation (planned for v0.2.0)
|
|
57
|
-
- 🚧 Weaviate - Stub implementation (planned for v0.3.0)
|
|
58
|
-
|
|
59
79
|
## [0.1.0] - 2024-XX-XX
|
|
60
80
|
|
|
61
81
|
### Added
|
|
@@ -89,13 +109,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
89
109
|
|
|
90
110
|
## Planned
|
|
91
111
|
|
|
92
|
-
### [0.2.0]
|
|
93
|
-
|
|
94
|
-
- Qdrant provider implementation
|
|
95
|
-
- Enhanced error messages
|
|
96
|
-
- Connection pooling
|
|
97
|
-
- Improved retry strategies
|
|
98
|
-
|
|
99
112
|
### [0.3.0]
|
|
100
113
|
|
|
101
114
|
- Weaviate provider implementation
|
data/README.md
CHANGED
|
@@ -1,434 +1,246 @@
|
|
|
1
|
-
# Vectra
|
|
1
|
+
# Vectra 🚀
|
|
2
2
|
|
|
3
|
-
[](https://
|
|
3
|
+
[](https://rubygems.org/gems/vectra-client)
|
|
4
4
|
[](https://github.com/stokry/vectra/actions)
|
|
5
5
|
[](https://codecov.io/gh/stokry/vectra)
|
|
6
6
|
[](https://github.com/rubocop/rubocop)
|
|
7
7
|
[](https://opensource.org/licenses/MIT)
|
|
8
8
|
[](CODE_OF_CONDUCT.md)
|
|
9
9
|
|
|
10
|
-
**
|
|
10
|
+
> **A unified Ruby client for vector databases.** Write once, switch vector database providers seamlessly. Perfect for AI/ML applications, semantic search, and RAG (Retrieval Augmented Generation) systems.
|
|
11
11
|
|
|
12
|
-
##
|
|
12
|
+
## 📖 Complete Documentation
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
- 🚀 **Modern Ruby** - Built for Ruby 3.2+ with modern patterns
|
|
16
|
-
- 🔄 **Automatic Retries** - Built-in retry logic with exponential backoff
|
|
17
|
-
- 📊 **Rich Results** - Enumerable query results with filtering capabilities
|
|
18
|
-
- 🛡️ **Type Safety** - Comprehensive validation and meaningful errors
|
|
19
|
-
- 📝 **Well Documented** - Extensive YARD documentation
|
|
14
|
+
**Full documentation, guides, and API reference available at:** [**https://vectra-docs.netlify.app/**](https://vectra-docs.netlify.app/)
|
|
20
15
|
|
|
21
|
-
|
|
16
|
+
This README provides a quick overview. For detailed guides, examples, and API documentation, visit the official documentation site above.
|
|
22
17
|
|
|
23
|
-
|
|
24
|
-
|----------|--------|---------|
|
|
25
|
-
| [Pinecone](https://pinecone.io) | ✅ Fully Supported | v0.1.0 |
|
|
26
|
-
| [PostgreSQL + pgvector](https://github.com/pgvector/pgvector) | ✅ Fully Supported | v0.1.1 |
|
|
27
|
-
| [Qdrant](https://qdrant.tech) | 🚧 Planned | v0.2.0 |
|
|
28
|
-
| [Weaviate](https://weaviate.io) | 🚧 Planned | v0.3.0 |
|
|
18
|
+
---
|
|
29
19
|
|
|
30
|
-
##
|
|
20
|
+
## ✨ Key Features
|
|
21
|
+
|
|
22
|
+
- 🔌 **Provider Agnostic** - Switch between vector database providers with minimal code changes
|
|
23
|
+
- 🚀 **Production Ready** - Built for Ruby 3.2+ with comprehensive test coverage (95%+)
|
|
24
|
+
- 🔄 **Resilient** - Built-in retry logic with exponential backoff and circuit breaker patterns
|
|
25
|
+
- 📊 **Rich Results** - Enumerable query results with advanced filtering and mapping capabilities
|
|
26
|
+
- 🛡️ **Type Safe** - Comprehensive input validation and meaningful error messages
|
|
27
|
+
- 📈 **Observable** - Native instrumentation support for Datadog and New Relic
|
|
28
|
+
- 🏗️ **Rails Ready** - Seamless ActiveRecord integration with migrations support
|
|
29
|
+
- 📚 **Well Documented** - Extensive YARD documentation and comprehensive examples
|
|
30
|
+
|
|
31
|
+
## 🗄️ Supported Vector Databases
|
|
32
|
+
|
|
33
|
+
| Provider | Type | Status | Docs |
|
|
34
|
+
|----------|------|--------|------|
|
|
35
|
+
| **Pinecone** | Managed Cloud | ✅ Fully Supported | [Guide](https://vectra-docs.netlify.app/providers/pinecone) |
|
|
36
|
+
| **PostgreSQL + pgvector** | SQL Database | ✅ Fully Supported | [Guide](https://vectra-docs.netlify.app/providers/pgvector) |
|
|
37
|
+
| **Qdrant** | Open Source | ✅ Fully Supported | [Guide](https://vectra-docs.netlify.app/providers/qdrant) |
|
|
38
|
+
| **Weaviate** | Open Source | ✅ Fully Supported | [Guide](https://vectra-docs.netlify.app/providers/weaviate) |
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
## 📦 Installation
|
|
31
43
|
|
|
32
44
|
Add this line to your application's Gemfile:
|
|
33
45
|
|
|
34
46
|
```ruby
|
|
35
|
-
gem 'vectra'
|
|
47
|
+
gem 'vectra-client'
|
|
36
48
|
```
|
|
37
49
|
|
|
38
|
-
|
|
50
|
+
Then execute:
|
|
39
51
|
|
|
40
52
|
```bash
|
|
41
53
|
bundle install
|
|
42
54
|
```
|
|
43
55
|
|
|
44
|
-
Or install
|
|
56
|
+
Or install directly:
|
|
45
57
|
|
|
46
58
|
```bash
|
|
47
|
-
gem install vectra
|
|
59
|
+
gem install vectra-client
|
|
48
60
|
```
|
|
49
61
|
|
|
50
|
-
###
|
|
62
|
+
### RubyGems Information
|
|
63
|
+
|
|
64
|
+
- **Gem Name:** `vectra-client`
|
|
65
|
+
- **Latest Version:** 0.2.1
|
|
66
|
+
- **Repository:** [stokry/vectra](https://github.com/stokry/vectra)
|
|
67
|
+
- **RubyGems Page:** [vectra-client](https://rubygems.org/gems/vectra-client)
|
|
68
|
+
- **License:** MIT
|
|
69
|
+
- **Ruby Requirement:** >= 3.2.0
|
|
51
70
|
|
|
52
|
-
|
|
71
|
+
### Provider-Specific Setup
|
|
53
72
|
|
|
73
|
+
Each vector database may require additional dependencies:
|
|
74
|
+
|
|
75
|
+
**PostgreSQL + pgvector:**
|
|
54
76
|
```ruby
|
|
55
77
|
gem 'pg', '~> 1.5'
|
|
56
78
|
```
|
|
57
79
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
### Configuration
|
|
61
|
-
|
|
80
|
+
**For Instrumentation:**
|
|
62
81
|
```ruby
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
# Global configuration
|
|
66
|
-
Vectra.configure do |config|
|
|
67
|
-
config.provider = :pinecone
|
|
68
|
-
config.api_key = ENV['PINECONE_API_KEY']
|
|
69
|
-
config.environment = 'us-east-1' # or config.host = 'your-index-host.pinecone.io'
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
# Create a client
|
|
73
|
-
client = Vectra::Client.new
|
|
82
|
+
gem 'dogstatsd-ruby' # Datadog
|
|
83
|
+
gem 'newrelic_rpm' # New Relic
|
|
74
84
|
```
|
|
75
85
|
|
|
76
|
-
|
|
86
|
+
## 🚀 Quick Start
|
|
87
|
+
|
|
88
|
+
### 1. Initialize a Client
|
|
77
89
|
|
|
78
90
|
```ruby
|
|
79
|
-
|
|
80
|
-
|
|
91
|
+
require 'vectra'
|
|
92
|
+
|
|
93
|
+
# Pinecone
|
|
94
|
+
client = Vectra::Client.new(
|
|
95
|
+
provider: :pinecone,
|
|
81
96
|
api_key: ENV['PINECONE_API_KEY'],
|
|
82
|
-
environment: 'us-
|
|
97
|
+
environment: 'us-west-4'
|
|
83
98
|
)
|
|
84
99
|
|
|
85
|
-
#
|
|
86
|
-
client = Vectra.
|
|
87
|
-
|
|
100
|
+
# PostgreSQL + pgvector
|
|
101
|
+
client = Vectra::Client.new(
|
|
102
|
+
provider: :pgvector,
|
|
103
|
+
database: 'my_app_production',
|
|
104
|
+
host: 'localhost'
|
|
88
105
|
)
|
|
89
106
|
|
|
90
|
-
#
|
|
107
|
+
# Qdrant
|
|
91
108
|
client = Vectra::Client.new(
|
|
92
|
-
provider: :
|
|
93
|
-
|
|
94
|
-
environment: 'us-east-1',
|
|
95
|
-
timeout: 60,
|
|
96
|
-
max_retries: 5
|
|
109
|
+
provider: :qdrant,
|
|
110
|
+
host: 'http://localhost:6333'
|
|
97
111
|
)
|
|
98
112
|
```
|
|
99
113
|
|
|
100
|
-
###
|
|
101
|
-
|
|
102
|
-
#### Upsert Vectors
|
|
114
|
+
### 2. Upsert Vectors
|
|
103
115
|
|
|
104
116
|
```ruby
|
|
105
117
|
client.upsert(
|
|
106
|
-
index: 'my-index',
|
|
107
118
|
vectors: [
|
|
108
|
-
{
|
|
109
|
-
|
|
119
|
+
{
|
|
120
|
+
id: 'doc-1',
|
|
121
|
+
values: [0.1, 0.2, 0.3],
|
|
122
|
+
metadata: { title: 'Introduction to AI' }
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
id: 'doc-2',
|
|
126
|
+
values: [0.2, 0.3, 0.4],
|
|
127
|
+
metadata: { title: 'Advanced ML Techniques' }
|
|
128
|
+
}
|
|
110
129
|
]
|
|
111
130
|
)
|
|
112
|
-
# => { upserted_count: 2 }
|
|
113
131
|
```
|
|
114
132
|
|
|
115
|
-
|
|
133
|
+
### 3. Search for Similar Vectors
|
|
116
134
|
|
|
117
135
|
```ruby
|
|
118
136
|
results = client.query(
|
|
119
|
-
index: 'my-index',
|
|
120
137
|
vector: [0.1, 0.2, 0.3],
|
|
121
|
-
top_k: 5
|
|
122
|
-
include_metadata: true
|
|
138
|
+
top_k: 5
|
|
123
139
|
)
|
|
124
140
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
puts "
|
|
128
|
-
puts "Metadata: #{match.metadata}"
|
|
141
|
+
results.matches.each do |match|
|
|
142
|
+
puts "#{match['id']}: #{match['score']}"
|
|
143
|
+
puts " Metadata: #{match['metadata']}"
|
|
129
144
|
end
|
|
130
|
-
|
|
131
|
-
# Access specific results
|
|
132
|
-
results.first # First match
|
|
133
|
-
results.ids # All matching IDs
|
|
134
|
-
results.scores # All scores
|
|
135
|
-
results.max_score # Highest score
|
|
136
|
-
|
|
137
|
-
# Filter by score
|
|
138
|
-
high_quality = results.above_score(0.8)
|
|
139
145
|
```
|
|
140
146
|
|
|
141
|
-
|
|
147
|
+
### 4. Delete Vectors
|
|
142
148
|
|
|
143
149
|
```ruby
|
|
144
|
-
|
|
145
|
-
index: 'my-index',
|
|
146
|
-
vector: [0.1, 0.2, 0.3],
|
|
147
|
-
top_k: 10,
|
|
148
|
-
filter: { category: 'programming', language: 'ruby' }
|
|
149
|
-
)
|
|
150
|
-
```
|
|
151
|
-
|
|
152
|
-
#### Fetch Vectors by ID
|
|
153
|
-
|
|
154
|
-
```ruby
|
|
155
|
-
vectors = client.fetch(index: 'my-index', ids: ['vec1', 'vec2'])
|
|
156
|
-
|
|
157
|
-
vectors['vec1'].values # [0.1, 0.2, 0.3]
|
|
158
|
-
vectors['vec1'].metadata # { 'text' => 'Hello world' }
|
|
150
|
+
client.delete(ids: ['doc-1', 'doc-2'])
|
|
159
151
|
```
|
|
160
152
|
|
|
161
|
-
|
|
153
|
+
## 📖 Full Documentation
|
|
162
154
|
|
|
163
|
-
|
|
164
|
-
client.update(
|
|
165
|
-
index: 'my-index',
|
|
166
|
-
id: 'vec1',
|
|
167
|
-
metadata: { category: 'updated', processed: true }
|
|
168
|
-
)
|
|
169
|
-
```
|
|
170
|
-
|
|
171
|
-
#### Delete Vectors
|
|
172
|
-
|
|
173
|
-
```ruby
|
|
174
|
-
# Delete by IDs
|
|
175
|
-
client.delete(index: 'my-index', ids: ['vec1', 'vec2'])
|
|
155
|
+
For complete documentation, examples, and guides, visit:
|
|
176
156
|
|
|
177
|
-
|
|
178
|
-
client.delete(index: 'my-index', filter: { category: 'old' })
|
|
157
|
+
**👉 [https://vectra-docs.netlify.app/](https://vectra-docs.netlify.app/)**
|
|
179
158
|
|
|
180
|
-
|
|
181
|
-
client.delete(index: 'my-index', delete_all: true)
|
|
182
|
-
```
|
|
159
|
+
### Documentation Includes:
|
|
183
160
|
|
|
184
|
-
|
|
161
|
+
- [Installation Guide](https://vectra-docs.netlify.app/guides/installation)
|
|
162
|
+
- [Getting Started](https://vectra-docs.netlify.app/guides/getting-started)
|
|
163
|
+
- [Provider Guides](https://vectra-docs.netlify.app/providers)
|
|
164
|
+
- [Pinecone](https://vectra-docs.netlify.app/providers/pinecone)
|
|
165
|
+
- [PostgreSQL + pgvector](https://vectra-docs.netlify.app/providers/pgvector)
|
|
166
|
+
- [Qdrant](https://vectra-docs.netlify.app/providers/qdrant)
|
|
167
|
+
- [Weaviate](https://vectra-docs.netlify.app/providers/weaviate)
|
|
168
|
+
- [API Reference](https://vectra-docs.netlify.app/api/overview)
|
|
169
|
+
- [Code Examples](https://vectra-docs.netlify.app/examples)
|
|
170
|
+
- [Rails Integration Guide](https://vectra-docs.netlify.app/providers/pgvector/)
|
|
185
171
|
|
|
186
|
-
|
|
187
|
-
# Create a Vector object
|
|
188
|
-
vector = Vectra::Vector.new(
|
|
189
|
-
id: 'my-vector',
|
|
190
|
-
values: [0.1, 0.2, 0.3],
|
|
191
|
-
metadata: { text: 'Example' }
|
|
192
|
-
)
|
|
172
|
+
---
|
|
193
173
|
|
|
194
|
-
|
|
195
|
-
vector.metadata? # => true
|
|
196
|
-
vector.to_h # Convert to hash
|
|
174
|
+
## 💡 Use Cases
|
|
197
175
|
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
vector.cosine_similarity(other) # => 1.0 (identical)
|
|
201
|
-
vector.euclidean_distance(other) # => 0.0
|
|
202
|
-
```
|
|
176
|
+
### Semantic Search
|
|
177
|
+
Build intelligent search that understands meaning, not just keywords. Perfect for product discovery, knowledge base search, and content recommendation.
|
|
203
178
|
|
|
204
|
-
###
|
|
179
|
+
### Retrieval Augmented Generation (RAG)
|
|
180
|
+
Combine vector databases with LLMs to enable precise information retrieval for AI applications, chatbots, and knowledge systems.
|
|
205
181
|
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
indexes = client.list_indexes
|
|
209
|
-
indexes.each { |idx| puts idx[:name] }
|
|
210
|
-
|
|
211
|
-
# Describe an index
|
|
212
|
-
info = client.describe_index(index: 'my-index')
|
|
213
|
-
puts info[:dimension] # => 384
|
|
214
|
-
puts info[:metric] # => "cosine"
|
|
215
|
-
|
|
216
|
-
# Get index statistics
|
|
217
|
-
stats = client.stats(index: 'my-index')
|
|
218
|
-
puts stats[:total_vector_count]
|
|
219
|
-
```
|
|
182
|
+
### Duplicate Detection
|
|
183
|
+
Identify and deduplicate similar items across your dataset using vector similarity.
|
|
220
184
|
|
|
221
|
-
###
|
|
185
|
+
### Recommendation Systems
|
|
186
|
+
Power personalized recommendations based on user behavior and content similarity.
|
|
222
187
|
|
|
223
|
-
|
|
188
|
+
---
|
|
224
189
|
|
|
225
|
-
```ruby
|
|
226
|
-
# Upsert to a namespace
|
|
227
|
-
client.upsert(
|
|
228
|
-
index: 'my-index',
|
|
229
|
-
namespace: 'production',
|
|
230
|
-
vectors: [...]
|
|
231
|
-
)
|
|
232
190
|
|
|
233
|
-
|
|
234
|
-
client.query(
|
|
235
|
-
index: 'my-index',
|
|
236
|
-
namespace: 'production',
|
|
237
|
-
vector: [0.1, 0.2, 0.3],
|
|
238
|
-
top_k: 5
|
|
239
|
-
)
|
|
240
|
-
```
|
|
191
|
+
## 🛠️ Development
|
|
241
192
|
|
|
242
|
-
###
|
|
243
|
-
|
|
244
|
-
pgvector uses PostgreSQL tables as indexes. Each "index" is a table with a vector column.
|
|
245
|
-
|
|
246
|
-
#### Setup PostgreSQL with pgvector
|
|
193
|
+
### Set Up Development Environment
|
|
247
194
|
|
|
248
195
|
```bash
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
-p 5432:5432 \
|
|
253
|
-
pgvector/pgvector:pg16
|
|
254
|
-
```
|
|
255
|
-
|
|
256
|
-
#### Create an Index (Table)
|
|
257
|
-
|
|
258
|
-
```ruby
|
|
259
|
-
client = Vectra.pgvector(connection_url: 'postgres://postgres:password@localhost/postgres')
|
|
260
|
-
|
|
261
|
-
# Create a new index with cosine similarity
|
|
262
|
-
client.provider.create_index(
|
|
263
|
-
name: 'documents',
|
|
264
|
-
dimension: 384,
|
|
265
|
-
metric: 'cosine' # or 'euclidean', 'inner_product'
|
|
266
|
-
)
|
|
267
|
-
```
|
|
268
|
-
|
|
269
|
-
#### Supported Metrics
|
|
270
|
-
|
|
271
|
-
| Metric | Description | pgvector Operator |
|
|
272
|
-
|--------|-------------|-------------------|
|
|
273
|
-
| `cosine` | Cosine similarity (default) | `<=>` |
|
|
274
|
-
| `euclidean` | Euclidean distance | `<->` |
|
|
275
|
-
| `inner_product` | Inner product / dot product | `<#>` |
|
|
276
|
-
|
|
277
|
-
#### Table Structure
|
|
278
|
-
|
|
279
|
-
Vectra creates tables with the following structure:
|
|
280
|
-
|
|
281
|
-
```sql
|
|
282
|
-
CREATE TABLE documents (
|
|
283
|
-
id TEXT PRIMARY KEY,
|
|
284
|
-
embedding vector(384),
|
|
285
|
-
metadata JSONB DEFAULT '{}',
|
|
286
|
-
namespace TEXT DEFAULT '',
|
|
287
|
-
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
|
288
|
-
);
|
|
289
|
-
|
|
290
|
-
-- IVFFlat index for fast similarity search
|
|
291
|
-
CREATE INDEX ON documents USING ivfflat (embedding vector_cosine_ops);
|
|
292
|
-
```
|
|
293
|
-
|
|
294
|
-
## Configuration Options
|
|
295
|
-
|
|
296
|
-
| Option | Description | Default |
|
|
297
|
-
|--------|-------------|---------|
|
|
298
|
-
| `provider` | Vector database provider (`:pinecone`, `:pgvector`, `:qdrant`, `:weaviate`) | Required |
|
|
299
|
-
| `api_key` | API key for authentication (password for pgvector) | Required* |
|
|
300
|
-
| `environment` | Environment/region (Pinecone) | - |
|
|
301
|
-
| `host` | Direct host URL or PostgreSQL connection URL | - |
|
|
302
|
-
| `timeout` | Request timeout in seconds | 30 |
|
|
303
|
-
| `open_timeout` | Connection timeout in seconds | 10 |
|
|
304
|
-
| `max_retries` | Maximum retry attempts | 3 |
|
|
305
|
-
| `retry_delay` | Initial retry delay in seconds | 1 |
|
|
306
|
-
| `logger` | Logger instance for debugging | nil |
|
|
307
|
-
|
|
308
|
-
*For pgvector, `api_key` is used as the PostgreSQL password.
|
|
309
|
-
|
|
310
|
-
## Error Handling
|
|
311
|
-
|
|
312
|
-
Vectra provides specific error classes for different failure scenarios:
|
|
313
|
-
|
|
314
|
-
```ruby
|
|
315
|
-
begin
|
|
316
|
-
client.query(index: 'my-index', vector: [0.1, 0.2], top_k: 5)
|
|
317
|
-
rescue Vectra::AuthenticationError => e
|
|
318
|
-
puts "Authentication failed: #{e.message}"
|
|
319
|
-
rescue Vectra::RateLimitError => e
|
|
320
|
-
puts "Rate limited. Retry after #{e.retry_after} seconds"
|
|
321
|
-
rescue Vectra::NotFoundError => e
|
|
322
|
-
puts "Resource not found: #{e.message}"
|
|
323
|
-
rescue Vectra::ValidationError => e
|
|
324
|
-
puts "Invalid request: #{e.message}"
|
|
325
|
-
rescue Vectra::ServerError => e
|
|
326
|
-
puts "Server error (#{e.status_code}): #{e.message}"
|
|
327
|
-
rescue Vectra::Error => e
|
|
328
|
-
puts "General error: #{e.message}"
|
|
329
|
-
end
|
|
330
|
-
```
|
|
331
|
-
|
|
332
|
-
## Logging
|
|
333
|
-
|
|
334
|
-
Enable debug logging to see request details:
|
|
335
|
-
|
|
336
|
-
```ruby
|
|
337
|
-
require 'logger'
|
|
338
|
-
|
|
339
|
-
Vectra.configure do |config|
|
|
340
|
-
config.provider = :pinecone
|
|
341
|
-
config.api_key = ENV['PINECONE_API_KEY']
|
|
342
|
-
config.environment = 'us-east-1'
|
|
343
|
-
config.logger = Logger.new($stdout)
|
|
344
|
-
end
|
|
196
|
+
git clone https://github.com/stokry/vectra.git
|
|
197
|
+
cd vectra
|
|
198
|
+
bundle install
|
|
345
199
|
```
|
|
346
200
|
|
|
347
|
-
|
|
201
|
+
### Run Tests
|
|
348
202
|
|
|
349
|
-
|
|
203
|
+
```bash
|
|
204
|
+
# All tests
|
|
205
|
+
bundle exec rspec
|
|
350
206
|
|
|
351
|
-
|
|
207
|
+
# Unit tests only
|
|
208
|
+
bundle exec rspec spec/vectra
|
|
352
209
|
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
client.upsert(index: 'my-index', vectors: batch)
|
|
356
|
-
end
|
|
210
|
+
# Integration tests only
|
|
211
|
+
bundle exec rspec spec/integration
|
|
357
212
|
```
|
|
358
213
|
|
|
359
|
-
###
|
|
214
|
+
### Code Quality
|
|
360
215
|
|
|
361
|
-
|
|
216
|
+
```bash
|
|
217
|
+
# Run RuboCop linter
|
|
218
|
+
bundle exec rubocop
|
|
362
219
|
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
client = Vectra::Client.new(...)
|
|
366
|
-
client.query(...)
|
|
367
|
-
client.upsert(...)
|
|
368
|
-
|
|
369
|
-
# Avoid: Creating new clients for each operation
|
|
370
|
-
Vectra::Client.new(...).query(...)
|
|
371
|
-
Vectra::Client.new(...).upsert(...)
|
|
220
|
+
# Generate documentation
|
|
221
|
+
bundle exec rake docs
|
|
372
222
|
```
|
|
373
223
|
|
|
374
|
-
|
|
224
|
+
## 🤝 Contributing
|
|
375
225
|
|
|
376
|
-
|
|
226
|
+
We welcome contributions! Please see [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.
|
|
377
227
|
|
|
378
|
-
|
|
379
|
-
def query_with_retry(client, **params, retries: 3)
|
|
380
|
-
client.query(**params)
|
|
381
|
-
rescue Vectra::RateLimitError => e
|
|
382
|
-
if retries > 0
|
|
383
|
-
sleep(e.retry_after || 1)
|
|
384
|
-
retry(retries: retries - 1)
|
|
385
|
-
else
|
|
386
|
-
raise
|
|
387
|
-
end
|
|
388
|
-
end
|
|
389
|
-
```
|
|
228
|
+
See [CHANGELOG.md](CHANGELOG.md) for the complete history of changes.
|
|
390
229
|
|
|
391
|
-
##
|
|
230
|
+
## 🔗 Links
|
|
392
231
|
|
|
393
|
-
|
|
232
|
+
- **Documentation:** [https://vectra-docs.netlify.app/](https://vectra-docs.netlify.app/)
|
|
233
|
+
- **RubyGems:** [vectra-client](https://rubygems.org/gems/vectra-client)
|
|
234
|
+
- **GitHub:** [stokry/vectra](https://github.com/stokry/vectra)
|
|
235
|
+
- **Issues:** [Report a bug](https://github.com/stokry/vectra/issues)
|
|
394
236
|
|
|
395
|
-
|
|
396
|
-
# Install dependencies
|
|
397
|
-
bundle install
|
|
237
|
+
## 📄 License
|
|
398
238
|
|
|
399
|
-
|
|
400
|
-
bundle exec rspec
|
|
401
|
-
|
|
402
|
-
# Run linter
|
|
403
|
-
bundle exec rubocop
|
|
239
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
404
240
|
|
|
405
|
-
|
|
406
|
-
bundle exec rake docs
|
|
407
|
-
```
|
|
241
|
+
---
|
|
408
242
|
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
### v0.1.0
|
|
412
|
-
- ✅ Pinecone provider
|
|
413
|
-
- ✅ Basic CRUD operations
|
|
414
|
-
- ✅ Configuration system
|
|
415
|
-
- ✅ Error handling with retries
|
|
416
|
-
- ✅ Comprehensive tests
|
|
417
|
-
|
|
418
|
-
### v0.1.1 (Current)
|
|
419
|
-
- ✅ pgvector (PostgreSQL) provider
|
|
420
|
-
- ✅ Multiple similarity metrics (cosine, euclidean, inner product)
|
|
421
|
-
- ✅ Namespace support for pgvector
|
|
422
|
-
- ✅ IVFFlat index creation
|
|
423
|
-
|
|
424
|
-
### v0.2.0
|
|
425
|
-
- 🚧 Qdrant provider
|
|
426
|
-
- 🚧 Enhanced error handling
|
|
427
|
-
- 🚧 Connection pooling
|
|
428
|
-
|
|
429
|
-
### v0.3.0
|
|
430
|
-
- 🚧 Weaviate provider
|
|
431
|
-
- 🚧 Batch operations
|
|
243
|
+
**Built with ❤️ by the Vectra community**
|
|
432
244
|
- 🚧 Performance optimizations
|
|
433
245
|
|
|
434
246
|
### v1.0.0
|
data/Rakefile
CHANGED
data/docs/Gemfile
ADDED
data/docs/_config.yml
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
title: Vectra Documentation
|
|
2
|
+
description: Unified Ruby client for vector databases
|
|
3
|
+
theme: minima
|
|
4
|
+
plugins:
|
|
5
|
+
- jekyll-feed
|
|
6
|
+
- jekyll-sitemap
|
|
7
|
+
|
|
8
|
+
markdown: kramdown
|
|
9
|
+
highlighter: rouge
|
|
10
|
+
|
|
11
|
+
exclude:
|
|
12
|
+
- Gemfile
|
|
13
|
+
- Gemfile.lock
|
|
14
|
+
- node_modules
|
|
15
|
+
- vendor/bundle/
|
|
16
|
+
- vendor/cache/
|
|
17
|
+
- vendor/gems/
|
|
18
|
+
- vendor/ruby/
|
|
19
|
+
|
|
20
|
+
permalink: /:categories/:title/
|