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;
35pub mod storage;
36
37// Re-export commonly used types
38pub use types::{
39    Artifact, Citation, CompilerConfig, Error, Result, ScoredSpan, Span, WorkingSet,
40    Session, Message, MessageRole, SessionWorkingSet,
41    // New types for enhanced determinism and explainability
42    Manifest, ChunkingParams, IndexParams,
43    ExplainPlan, ExplainCandidate, ExplainTiming, ExplainThresholds,
44    IngestAction,
45    GoldenQuery, EvalResult, EvalSummary,
46    WorkingSetDiff, DiffEntry, RerankEntry,
47    // Multi-agent orchestration types
48    Agent, Stance, AgentRelation, AgentMessageMeta, AgentRelationSummary, AgentRelationEntry,
49};
50
51pub use session::{SessionManager, SessionManagerGeneric, SessionReplay, SessionTurn};
52
53// Re-export compiler functions
54pub use compiler::{compile, compile_with_backend, compile_with_backend_options};
55
56// Re-export storage module types
57pub use storage::{
58    StorageBackend, StorageConfig, SqliteBackend,
59    VectorSearchProvider, VectorSearchResult,
60    create_backend, create_backend_from_env,
61};
62
63/// The version of AvocadoDB
64pub const VERSION: &str = env!("CARGO_PKG_VERSION");
65
66#[cfg(test)]
67mod tests {
68    use super::*;
69
70    #[test]
71    fn test_version() {
72        assert!(!VERSION.is_empty());
73    }
74
75    #[test]
76    fn test_working_set_hash_determinism() {
77        let ws1 = WorkingSet {
78            text: "Hello, world!".to_string(),
79            spans: vec![],
80            citations: vec![],
81            tokens_used: 3,
82            query: "test".to_string(),
83            compilation_time_ms: 100,
84            manifest: None,
85            explain: None,
86        };
87
88        let ws2 = WorkingSet {
89            text: "Hello, world!".to_string(),
90            spans: vec![],
91            citations: vec![],
92            tokens_used: 3,
93            query: "test".to_string(),
94            compilation_time_ms: 200, // Different timing
95            manifest: None,
96            explain: None,
97        };
98
99        // Hash should be the same because it only depends on text
100        assert_eq!(ws1.deterministic_hash(), ws2.deterministic_hash());
101    }
102}