Crate lumosai_vector_postgres

Source
Expand description

§Lumos Vector PostgreSQL

PostgreSQL with pgvector implementation for the lumos-vector-core architecture.

This crate provides a PostgreSQL backend with pgvector extension for vector storage, implementing the unified VectorStorage trait from lumos-vector-core.

§Features

  • SQL Integration: Leverages PostgreSQL’s ACID properties
  • pgvector Extension: High-performance vector operations
  • Rich Queries: Complex SQL queries with vector similarity
  • Transactions: Full transaction support
  • Indexing: Multiple vector index types (IVFFlat, HNSW)

§Example

use lumos_vector_postgres::PostgresVectorStorage;
use lumos_vector_core::prelude::*;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Create PostgreSQL storage
    let storage = PostgresVectorStorage::new("postgresql://user:pass@localhost/db").await?;
     
    // Create an index
    let config = IndexConfig::new("documents", 384)
        .with_metric(SimilarityMetric::Cosine);
    storage.create_index(config).await?;
     
    // Insert documents
    let docs = vec![
        Document::new("doc1", "Hello world")
            .with_embedding(vec![0.1; 384])
            .with_metadata("type", "greeting"),
    ];
    storage.upsert_documents("documents", docs).await?;
     
    Ok(())
}

Re-exports§

pub use storage::PostgresVectorStorage;
pub use config::PostgresConfig;
pub use error::PostgresError;
pub use error::PostgresResult;

Modules§

config
PostgreSQL configuration for vector storage
error
Error types for PostgreSQL vector storage
filter
Default filter evaluator implementation
similarity
Default similarity calculator implementations
storage
PostgreSQL vector storage implementation

Structs§

BackendInfo
Backend information
CacheConfig
缓存配置
CacheEntry
缓存条目
CacheStats
缓存统计信息
ConnectionPool
连接池
ConnectionPoolConfig
连接池配置
ConnectionPoolStats
连接池统计信息
Document
Document representation with embedding support
IndexConfig
Index configuration
IndexCreateConfig
Index creation configuration
IndexInfo
Index statistics and information
IndexOptions
Index-specific options
LRUCache
LRU缓存
PerformanceMetrics
性能指标
PerformanceMonitor
性能监控器
PooledConnection
池化连接
SearchConfig
Search configuration
SearchRequest
Search request for querying vectors
SearchResponse
Search response
SearchResult
Search result item
StorageConfigBuilder
Builder for creating storage configurations
VectorSystemConfig
Complete vector storage system configuration

Enums§

EmbeddingConfig
Embedding model configuration
FilterCondition
Filter conditions for querying vectors
MetadataValue
Metadata value that can hold various types
SearchQuery
Search query can be either a vector or text
SimilarityMetric
Similarity metrics for vector comparison
SqliteSynchronous
SQLite synchronous mode
StorageConfig
Storage backend configuration
VectorError
Comprehensive error type for vector storage operations

Traits§

Embeddable
Trait for documents that can be embedded
EmbeddingModel
Trait for embedding models
FilterEvaluator
Trait for filter evaluation
SimilarityCalculator
Trait for vector similarity calculation
VectorStorage
Core trait for vector storage backends

Functions§

create_postgres_storage
Create a new PostgreSQL vector storage instance
create_postgres_storage_with_config
Create a new PostgreSQL vector storage instance with configuration

Type Aliases§

DocumentId
Document ID type
Metadata
Metadata type for storing arbitrary key-value pairs
Result
Result type alias for vector operations
Vector
Vector type alias for f32 vectors