PostgreSQL with pgvector Provider
pgvector is a PostgreSQL extension for vector data.
Setup
Prerequisites
# Install PostgreSQL with pgvector extension
# macOS with Homebrew
brew install postgresql
# Enable pgvector extension
psql -d your_database -c "CREATE EXTENSION IF NOT EXISTS vector;"
Connect with Vectra
client = Vectra::Client.new(
provider: :pgvector,
database: 'my_database',
host: 'localhost',
port: 5432,
user: 'postgres',
password: ENV['DB_PASSWORD']
)
Features
- ✅ Upsert vectors
- ✅ Query/search
- ✅ Delete vectors
- ✅ SQL integration
- ✅ ACID transactions
- ✅ Complex queries
- ✅ Rails ActiveRecord integration
Example
# Initialize client
client = Vectra::Client.new(
provider: :pgvector,
database: 'vectors_db',
host: 'localhost'
)
# Upsert vectors
client.upsert(
vectors: [
{ id: 'doc-1', values: [0.1, 0.2, 0.3], metadata: { title: 'Doc 1' } }
]
)
# Search using cosine distance
results = client.query(vector: [0.1, 0.2, 0.3], top_k: 5)
ActiveRecord Integration
class Document < ApplicationRecord
include Vectra::ActiveRecord
vector_search :embedding_vector
end
# Search
docs = Document.vector_search([0.1, 0.2, 0.3], limit: 10)
Configuration Options
| Option | Type | Required | Description |
|---|---|---|---|
database |
String | Yes | Database name |
host |
String | Yes | PostgreSQL host |
port |
Integer | No | PostgreSQL port (default: 5432) |
user |
String | No | Database user |
password |
String | No | Database password |
schema |
String | No | Database schema |