entelix_memory_pgvector/lib.rs
1//! # entelix-memory-pgvector
2//!
3//! Concrete [`entelix_memory::VectorStore`] implementation backed by
4//! Postgres + the pgvector extension.
5//!
6//! Companion to the trait-only [`entelix_memory`] crate:
7//! sqlx + pgvector specifics live here so users who plug their own
8//! `VectorStore` pay nothing in compile time.
9//!
10//! ## One-call setup
11//!
12//! ```ignore
13//! use entelix_memory_pgvector::{DistanceMetric, IndexKind, PgVectorStore};
14//!
15//! let store = PgVectorStore::builder(1536)
16//! .with_connection_string("postgres://localhost/entelix")
17//! .with_distance(DistanceMetric::Cosine)
18//! .with_index_kind(IndexKind::Hnsw)
19//! .build()
20//! .await?;
21//! ```
22//!
23//! ## Multi-tenancy
24//!
25//! Single-table design with a composite `(namespace_key, doc_id)`
26//! primary key. Every read / write / count / list rides a
27//! `WHERE namespace_key = $1` anchor — invariant 11 / F2 demand
28//! structural tenant isolation, and the composite PK doubles as
29//! the B-tree index that anchor relies on.
30//!
31//! ## Schema-as-code escape hatch
32//!
33//! Operators that own the schema externally (DBA-managed, IaC,
34//! migration pipeline) call [`PgVectorStoreBuilder::with_auto_migrate`]
35//! with `false` — the builder
36//! skips extension creation, table creation, and index
37//! provisioning, trusting the operator to have stamped them.
38
39#![cfg_attr(docsrs, feature(doc_cfg))]
40#![doc(html_root_url = "https://docs.rs/entelix-memory-pgvector/0.5.3")]
41#![deny(missing_docs)]
42// `Postgres`, `pgvector` ride through doc strings as vendor names.
43// `pub(crate)` items inside private modules are the canonical
44// crate-internal helper pattern.
45#![allow(
46 clippy::doc_markdown,
47 clippy::redundant_pub_crate,
48 clippy::cast_precision_loss,
49 clippy::cast_possible_truncation,
50 clippy::cast_possible_wrap,
51 clippy::cast_sign_loss,
52 clippy::redundant_closure_for_method_calls,
53 clippy::missing_const_for_fn,
54 clippy::expect_used
55)]
56
57mod error;
58mod filter;
59mod migration;
60mod store;
61mod tenant;
62
63pub use error::{PgVectorStoreError, PgVectorStoreResult};
64pub use store::{DistanceMetric, IndexKind, PgVectorStore, PgVectorStoreBuilder};