#![allow(clippy::non_canonical_partial_ord_impl)]
#![allow(clippy::manual_is_multiple_of)]
#![allow(clippy::manual_div_ceil)]
#![allow(clippy::derivable_impls)]
#![allow(clippy::needless_range_loop)]
#![allow(clippy::unused_enumerate_index)]
pub mod embedding;
pub mod index;
pub mod storage;
pub mod vector;
use thiserror::Error;
pub type Result<T> = std::result::Result<T, RagError>;
#[derive(Debug, Error)]
pub enum RagError {
#[error("Vector dimension mismatch: expected {expected}, got {actual}")]
DimensionMismatch { expected: usize, actual: usize },
#[error("Index error: {0}")]
IndexError(String),
#[error("Embedding error: {0}")]
EmbeddingError(String),
#[error("Storage error: {0}")]
StorageError(String),
#[error("IO error: {0}")]
IoError(#[from] std::io::Error),
#[error("Serialization error: {0}")]
SerializationError(#[from] bincode::Error),
#[error("Compression error: {0}")]
CompressionError(#[from] storage::compression::CompressionError),
#[error("Invalid input: {0}")]
InvalidInput(String),
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct Document {
pub id: String,
pub content: String,
pub embedding: Vec<f32>,
pub metadata: Option<serde_json::Value>,
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct SearchResult {
pub id: String,
pub content: String,
pub score: f32,
pub metadata: Option<serde_json::Value>,
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct RagConfig {
pub embedding_dim: usize,
pub max_documents: usize,
pub index_type: IndexType,
}
#[derive(Debug, Clone, Copy, serde::Serialize, serde::Deserialize)]
pub enum IndexType {
Flat,
HNSW,
}
impl Default for RagConfig {
fn default() -> Self {
Self {
embedding_dim: 384, max_documents: 10_000,
index_type: IndexType::HNSW,
}
}
}
pub use vector::{cosine_similarity, dot_product, l2_distance, normalize};