prax-pgvector
pgvector integration for the Prax ORM — vector similarity search, embeddings, and index management for PostgreSQL.
This crate provides type-safe wrappers around pgvector
functionality, integrating with the prax-postgres driver for seamless vector operations.
Features
- Vector types: [
Embedding], [SparseEmbedding], [BinaryVector] (and [HalfEmbedding] with thehalfvecfeature) - Distance metrics: L2, inner product, cosine, L1, Hamming, Jaccard
- Index management: IVFFlat and HNSW index creation with tuning parameters
- Query builder: Fluent API for vector similarity search
- Hybrid search: Combined vector + full-text search using Reciprocal Rank Fusion
- Filter integration: Vector filters for prax-query WHERE/ORDER BY clauses
Quick Start
use *;
// Create an embedding
let query = new;
// Build a similarity search
let search = new
.query
.metric
.limit
.ef_search // Tune HNSW recall
.build;
let sql = search.to_sql;
// SELECT *, embedding <=> $1 AS distance FROM documents ORDER BY distance LIMIT 10
Index Management
use ;
use DistanceMetric;
// Create an HNSW index
let index = hnsw
.metric
.config
.concurrent
.build
.unwrap;
println!;
// CREATE INDEX CONCURRENTLY idx_doc_embedding ON documents
// USING hnsw (embedding vector_cosine_ops)
// WITH (m = 32, ef_construction = 128)
Feature Flags
| Feature | Description |
|---|---|
halfvec |
Enable half-precision (float16) vector support |