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 rerank;
35pub mod text;
36pub mod vector_db;
37
38pub use error::{Error, Result};
39
40pub use rerank::Reranker;
41
42pub use embeddings::{EmbeddingBackend, EmbeddingConfig, EmbeddingModelType, LocalEmbeddingEngine};
43pub use vector_db::{
44    Corpus, MESSAGE_CONTENT_TYPE, ProductQuantizationCodebook, SearchMatch, SearchMode,
45    SearchQualityPreset, StoredVector, VectorDB, VectorDbConfig, VectorDbStats,
46    VectorDbStatsSnapshot, VectorMetadata, cosine_similarity, cosine_with_norms, dot, l2_norm,
47};