avocado_core/
lib.rs

1//! AvocadoDB Core Engine
2//!
3//! The deterministic context compiler that fixes RAG.
4//!
5//! AvocadoDB replaces traditional vector databases' chaotic "top-k" retrieval
6//! with deterministic, citation-backed context generation using span-based
7//! compilation.
8//!
9//! # Key Features
10//!
11//! - **100% Deterministic**: Same query → same context, every time
12//! - **Citation-Backed**: Every piece of context has exact line number citations
13//! - **Token Efficient**: 95%+ token budget utilization (vs 60-70% in RAG)
14//! - **Fast**: < 500ms for 8K token context
15//!
16//! # Architecture
17//!
18//! ```text
19//! Query → Embed → [Semantic Search + Lexical Search] → Hybrid Fusion
20//!       → MMR Diversification → Token Packing → Deterministic Sort → WorkingSet
21//! ```
22
23#![warn(missing_docs)]
24
25pub mod types;
26pub mod span;
27pub mod embedding;
28pub mod compiler;
29pub mod db;
30pub mod index;
31pub mod session;
32pub mod approx;
33pub mod eval;
34pub mod diff;
35
36// Re-export commonly used types
37pub use types::{
38    Artifact, Citation, CompilerConfig, Error, Result, ScoredSpan, Span, WorkingSet,
39    Session, Message, MessageRole, SessionWorkingSet,
40    // New types for enhanced determinism and explainability
41    Manifest, ChunkingParams, IndexParams,
42    ExplainPlan, ExplainCandidate, ExplainTiming, ExplainThresholds,
43    IngestAction,
44    GoldenQuery, EvalResult, EvalSummary,
45    WorkingSetDiff, DiffEntry, RerankEntry,
46};
47
48pub use session::{SessionManager, SessionReplay, SessionTurn};
49
50/// The version of AvocadoDB
51pub const VERSION: &str = env!("CARGO_PKG_VERSION");
52
53#[cfg(test)]
54mod tests {
55    use super::*;
56
57    #[test]
58    fn test_version() {
59        assert!(!VERSION.is_empty());
60    }
61
62    #[test]
63    fn test_working_set_hash_determinism() {
64        let ws1 = WorkingSet {
65            text: "Hello, world!".to_string(),
66            spans: vec![],
67            citations: vec![],
68            tokens_used: 3,
69            query: "test".to_string(),
70            compilation_time_ms: 100,
71            manifest: None,
72            explain: None,
73        };
74
75        let ws2 = WorkingSet {
76            text: "Hello, world!".to_string(),
77            spans: vec![],
78            citations: vec![],
79            tokens_used: 3,
80            query: "test".to_string(),
81            compilation_time_ms: 200, // Different timing
82            manifest: None,
83            explain: None,
84        };
85
86        // Hash should be the same because it only depends on text
87        assert_eq!(ws1.deterministic_hash(), ws2.deterministic_hash());
88    }
89}