Skip to main content

post_cortex_embeddings/
lib.rs

1// Copyright (c) 2025, 2026 Julius ML
2// Licensed under the MIT License. See LICENSE at the workspace root.
3
4//! Embedding engines + HNSW vector database for post-cortex.
5//!
6//! This crate is self-contained: anyone needing a Candle-backed BERT
7//! embedder or an HNSW index for nearest-neighbour search can depend
8//! on it without pulling the post-cortex daemon, storage, or
9//! orchestrator. Implements [`EmbeddingBackend`] (BERT via Candle,
10//! static-hash fallback) and ships [`VectorDB`] (HNSW with optional
11//! product quantization).
12//!
13//! Shared types — \[`post_cortex_embeddings::VectorMetadata`\]
14//! and friends — live in `post-cortex-core` so the storage trait API
15//! can reference them without depending on the ML stack.
16
17// SAFETY: candle's `from_mmaped_safetensors` needs an unsafe block at the
18// single call site (file mmap). The exemption is justified inline.
19#![deny(unsafe_code)]
20// VectorDB config + HNSW types have many tuning knobs — the
21// field-by-field default-then-mutate pattern in tests is intentional.
22#![allow(clippy::field_reassign_with_default)]
23// `vec!` in tests is fine for clarity vs an array literal — silenced.
24#![allow(clippy::useless_vec)]
25// HNSW core uses .iter().enumerate() to index parallel arrays; the
26// loop variable looks "unused" to the lint but is structurally needed.
27#![allow(clippy::needless_range_loop)]
28// We pin MSRV 1.85; some clippy suggestions point at stabilisations in
29// later releases (e.g. div_ceil since 1.73 / inline_const since 1.79).
30#![allow(clippy::incompatible_msrv)]
31
32pub mod embeddings;
33pub mod error;
34pub mod vector_db;
35
36pub use error::{Error, Result};
37
38pub use embeddings::{EmbeddingBackend, EmbeddingConfig, EmbeddingModelType, LocalEmbeddingEngine};
39pub use vector_db::{
40    ProductQuantizationCodebook, SearchMatch, SearchMode, SearchQualityPreset, StoredVector,
41    VectorDB, VectorDbConfig, VectorDbStats, VectorDbStatsSnapshot, VectorMetadata,
42};