Expand description
§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 prax_pgvector::prelude::*;
// Create an embedding
let query = Embedding::new(vec![0.1, 0.2, 0.3, /* ... */]);
// Build a similarity search
let search = VectorSearchBuilder::new("documents", "embedding")
.query(query)
.metric(DistanceMetric::Cosine)
.limit(10)
.ef_search(200) // Tune HNSW recall
.build();
let sql = search.to_sql();
// SELECT *, embedding <=> $1 AS distance FROM documents ORDER BY distance LIMIT 10§Index Management
ⓘ
use prax_pgvector::index::{VectorIndex, HnswConfig};
use prax_pgvector::DistanceMetric;
// Create an HNSW index
let index = VectorIndex::hnsw("idx_doc_embedding", "documents", "embedding")
.metric(DistanceMetric::Cosine)
.config(HnswConfig::high_recall())
.concurrent()
.build()
.unwrap();
println!("{}", index.to_create_sql());
// 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 |
Re-exports§
pub use error::VectorError;pub use error::VectorResult;pub use ops::BinaryDistanceMetric;pub use ops::DistanceMetric;pub use types::BinaryVector;pub use types::Embedding;pub use types::SparseEmbedding;
Modules§
- error
- Error types for pgvector operations.
- filter
- Vector filter operations for integration with the prax query builder.
- index
- Vector index management for pgvector.
- ops
- Distance operators and similarity metrics for pgvector.
- prelude
- Prelude for convenient imports.
- query
- High-level query builder for vector similarity search.
- types
- Core vector types wrapping pgvector with Prax ORM integration.